X Tutup
Skip to content

Commit 212a655

Browse files
author
Steve Canny
committed
acpt: add scenarios for Section.orientation getter
Also, add WD_ORIENTATION enumeration.
1 parent 81d49bd commit 212a655

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

docx/enum/section.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@
99
from .base import alias, XmlEnumeration, XmlMappedEnumMember
1010

1111

12+
@alias('WD_ORIENT')
13+
class WD_ORIENTATION(XmlEnumeration):
14+
"""
15+
Specifies the page layout orientation.
16+
"""
17+
18+
__ms_name__ = 'WdOrientation'
19+
20+
__url__ = 'http://msdn.microsoft.com/en-us/library/office/ff837902.aspx'
21+
22+
__members__ = (
23+
XmlMappedEnumMember(
24+
'PORTRAIT', 0, 'portrait', 'Portrait orientation.'
25+
),
26+
XmlMappedEnumMember(
27+
'LANDSCAPE', 1, 'landscape', 'Landscape orientation.'
28+
),
29+
)
30+
31+
1232
@alias('WD_SECTION')
1333
class WD_SECTION_START(XmlEnumeration):
1434
"""

features/sct-section-props.feature

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,14 @@ Feature: Access and change section properties
4141
And I set the section page height to 8.5 inches
4242
Then the reported page width is 11 inches
4343
And the reported page height is 8.5 inches
44+
45+
46+
@wip
47+
Scenario Outline: Get section orientation
48+
Given a section known to have <orientation> orientation
49+
Then the reported page orientation is <reported-orientation>
50+
51+
Examples: Section page orientations
52+
| orientation | reported-orientation |
53+
| landscape | WD_ORIENT.LANDSCAPE |
54+
| portrait | WD_ORIENT.PORTRAIT |

features/steps/section.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from behave import given, then, when
1010

1111
from docx import Document
12-
from docx.enum.section import WD_SECTION
12+
from docx.enum.section import WD_ORIENT, WD_SECTION
1313
from docx.shared import Inches
1414

1515
from helpers import test_docx
@@ -36,6 +36,16 @@ def given_a_section_having_start_type(context, start_type):
3636
context.section = document.sections[section_idx]
3737

3838

39+
@given('a section known to have {orientation} orientation')
40+
def given_a_section_having_known_orientation(context, orientation):
41+
section_idx = {
42+
'landscape': 0,
43+
'portrait': 1
44+
}[orientation]
45+
document = Document(test_docx('sct-section-props'))
46+
context.section = document.sections[section_idx]
47+
48+
3949
# when =====================================================
4050

4151
@when('I set the section page height to {y} inches')
@@ -63,6 +73,15 @@ def when_I_set_the_section_start_type_to_start_type(context, start_type):
6373

6474
# then =====================================================
6575

76+
@then('the reported page orientation is {orientation}')
77+
def then_the_reported_page_orientation_is_orientation(context, orientation):
78+
expected_value = {
79+
'WD_ORIENT.LANDSCAPE': WD_ORIENT.LANDSCAPE,
80+
'WD_ORIENT.PORTRAIT': WD_ORIENT.PORTRAIT,
81+
}[orientation]
82+
assert context.section.orientation == expected_value
83+
84+
6685
@then('the reported page width is {x} inches')
6786
def then_the_reported_page_width_is_width(context, x):
6887
assert context.section.page_width == Inches(float(x))
783 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
X Tutup