X Tutup
Skip to content

Commit 81d49bd

Browse files
author
Steve Canny
committed
sect: add Section.page_height setter
1 parent d5073ee commit 81d49bd

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

docx/oxml/section.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ def page_height(self):
4646
return None
4747
return pgSz.h
4848

49+
@page_height.setter
50+
def page_height(self, value):
51+
pgSz = self.get_or_add_pgSz()
52+
pgSz.h = value
53+
4954
@property
5055
def page_width(self):
5156
"""

docx/section.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def page_height(self):
2525
"""
2626
return self._sectPr.page_height
2727

28+
@page_height.setter
29+
def page_height(self, value):
30+
self._sectPr.page_height = value
31+
2832
@property
2933
def page_width(self):
3034
"""

features/sct-section-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ Feature: Access and change section properties
3535
And the reported page height is 11 inches
3636

3737

38-
@wip
3938
Scenario: Set section page size
4039
Given a section having known page dimension
4140
When I set the section page width to 11 inches

tests/test_section.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ def it_knows_its_page_width(self, page_width_get_fixture):
3333
def it_can_change_its_page_width(self, page_width_set_fixture):
3434
section, new_page_width, expected_xml = page_width_set_fixture
3535
section.page_width = new_page_width
36-
assert section._sectPr.xml == expected_xml
3736

3837
def it_knows_its_page_height(self, page_height_get_fixture):
3938
section, expected_page_height = page_height_get_fixture
4039
assert section.page_height == expected_page_height
4140

41+
def it_can_change_its_page_height(self, page_height_set_fixture):
42+
section, new_page_height, expected_xml = page_height_set_fixture
43+
section.page_height = new_page_height
44+
assert section._sectPr.xml == expected_xml
45+
4246
# fixtures -------------------------------------------------------
4347

4448
@pytest.fixture(params=[
@@ -53,6 +57,20 @@ def page_height_get_fixture(self, request):
5357
section = Section(sectPr)
5458
return section, expected_page_height
5559

60+
@pytest.fixture(params=[
61+
(None, None),
62+
(Inches(2), 2880),
63+
])
64+
def page_height_set_fixture(self, request):
65+
new_page_height, expected_h_val = request.param
66+
# section ----------------------
67+
sectPr = self.sectPr_bldr().element
68+
section = Section(sectPr)
69+
# expected_xml -----------------
70+
pgSz_bldr = self.pgSz_bldr(h=expected_h_val)
71+
expected_xml = self.sectPr_bldr(pgSz_bldr).xml()
72+
return section, new_page_height, expected_xml
73+
5674
@pytest.fixture(params=[
5775
(True, 1440, Inches(1)),
5876
(True, None, None),

0 commit comments

Comments
 (0)
X Tutup