X Tutup
Skip to content

Commit bb37339

Browse files
author
Steve Canny
committed
sect: add Section.orientation setter
1 parent f6036e0 commit bb37339

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

docx/oxml/section.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ def orientation(self):
5050
return WD_ORIENTATION.PORTRAIT
5151
return pgSz.orient
5252

53+
@orientation.setter
54+
def orientation(self, value):
55+
pgSz = self.get_or_add_pgSz()
56+
pgSz.orient = value
57+
5358
@property
5459
def page_height(self):
5560
"""

docx/section.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def orientation(self):
2323
"""
2424
return self._sectPr.orientation
2525

26+
@orientation.setter
27+
def orientation(self, value):
28+
self._sectPr.orientation = value
29+
2630
@property
2731
def page_height(self):
2832
"""

features/sct-section-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ Feature: Access and change section properties
5353
| portrait | WD_ORIENT.PORTRAIT |
5454

5555

56-
@wip
5756
Scenario Outline: Set section orientation
5857
Given a section known to have <initial-orientation> orientation
5958
When I set the section orientation to <new-orientation>

tests/test_section.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def it_knows_its_page_orientation(self, orientation_get_fixture):
4747
section, expected_orientation = orientation_get_fixture
4848
assert section.orientation is expected_orientation
4949

50+
def it_can_change_its_orientation(self, orientation_set_fixture):
51+
section, new_orientation, expected_xml = orientation_set_fixture
52+
section.orientation = new_orientation
53+
assert section._sectPr.xml == expected_xml
54+
5055
# fixtures -------------------------------------------------------
5156

5257
@pytest.fixture(params=[
@@ -62,6 +67,21 @@ def orientation_get_fixture(self, request):
6267
section = Section(sectPr)
6368
return section, expected_orientation
6469

70+
@pytest.fixture(params=[
71+
(WD_ORIENT.LANDSCAPE, 'landscape'),
72+
(WD_ORIENT.PORTRAIT, None),
73+
(None, None),
74+
])
75+
def orientation_set_fixture(self, request):
76+
new_orientation, expected_orient_val = request.param
77+
# section ----------------------
78+
sectPr = self.sectPr_bldr().element
79+
section = Section(sectPr)
80+
# expected_xml -----------------
81+
pgSz_bldr = self.pgSz_bldr(orient=expected_orient_val)
82+
expected_xml = self.sectPr_bldr(pgSz_bldr).xml()
83+
return section, new_orientation, expected_xml
84+
6585
@pytest.fixture(params=[
6686
(True, 2880, Inches(2)),
6787
(True, None, None),

0 commit comments

Comments
 (0)
X Tutup