Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4f12bde

Browse files
revossen-asmlSteve Canny
authored andcommitted
tbl: add _Row.height_rule setter
1 parent 4f28d93 commit 4f12bde

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

docx/oxml/table.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ def trHeight_hRule(self):
7171
return None
7272
return trPr.trHeight_hRule
7373

74+
@trHeight_hRule.setter
75+
def trHeight_hRule(self, value):
76+
trPr = self.get_or_add_trPr()
77+
trPr.trHeight_hRule = value
78+
7479
def _insert_tblPrEx(self, tblPrEx):
7580
self.insert(0, tblPrEx)
7681

@@ -819,6 +824,13 @@ def trHeight_hRule(self):
819824
return None
820825
return trHeight.hRule
821826

827+
@trHeight_hRule.setter
828+
def trHeight_hRule(self, value):
829+
if value is None and self.trHeight is None:
830+
return
831+
trHeight = self.get_or_add_trHeight()
832+
trHeight.hRule = value
833+
822834

823835
class CT_VMerge(BaseOxmlElement):
824836
"""

docx/table.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ def height_rule(self):
392392
"""
393393
return self._tr.trHeight_hRule
394394

395+
@height_rule.setter
396+
def height_rule(self, value):
397+
self._tr.trHeight_hRule = value
398+
395399
@property
396400
def table(self):
397401
"""

features/tbl-row-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Feature: Get and set table row properties
1515
| at least | AT_LEAST |
1616

1717

18-
@wip
1918
Scenario Outline: Set Row.height_rule
2019
Given a table row having height rule <state>
2120
When I assign <value> to row.height_rule

tests/test_table.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,11 @@ def it_knows_its_height_rule(self, height_rule_get_fixture):
657657
row, expected_rule = height_rule_get_fixture
658658
assert row.height_rule == expected_rule
659659

660+
def it_can_change_its_height_rule(self, height_rule_set_fixture):
661+
row, rule, expected_xml = height_rule_set_fixture
662+
row.height_rule = rule
663+
assert row._tr.xml == expected_xml
664+
660665
def it_provides_access_to_its_cells(self, cells_fixture):
661666
row, row_idx, expected_cells = cells_fixture
662667
cells = row.cells
@@ -696,6 +701,32 @@ def height_rule_get_fixture(self, request):
696701
row = _Row(element(tr_cxml), None)
697702
return row, expected_rule
698703

704+
@pytest.fixture(params=[
705+
('w:tr',
706+
WD_ROW_HEIGHT.AUTO,
707+
'w:tr/w:trPr/w:trHeight{w:hRule=auto}'),
708+
('w:tr/w:trPr',
709+
WD_ROW_HEIGHT.AT_LEAST,
710+
'w:tr/w:trPr/w:trHeight{w:hRule=atLeast}'),
711+
('w:tr/w:trPr/w:trHeight',
712+
WD_ROW_HEIGHT.EXACTLY,
713+
'w:tr/w:trPr/w:trHeight{w:hRule=exact}'),
714+
('w:tr/w:trPr/w:trHeight{w:val=1440, w:hRule=exact}',
715+
WD_ROW_HEIGHT.AUTO,
716+
'w:tr/w:trPr/w:trHeight{w:val=1440, w:hRule=auto}'),
717+
('w:tr/w:trPr/w:trHeight{w:val=1440, w:hRule=auto}',
718+
None,
719+
'w:tr/w:trPr/w:trHeight{w:val=1440}'),
720+
('w:tr', None, 'w:tr/w:trPr'),
721+
('w:tr/w:trPr', None, 'w:tr/w:trPr'),
722+
('w:tr/w:trPr/w:trHeight', None, 'w:tr/w:trPr/w:trHeight'),
723+
])
724+
def height_rule_set_fixture(self, request):
725+
tr_cxml, new_rule, expected_cxml = request.param
726+
row = _Row(element(tr_cxml), None)
727+
expected_xml = xml(expected_cxml)
728+
return row, new_rule, expected_xml
729+
699730
@pytest.fixture
700731
def idx_fixture(self):
701732
tbl = element('w:tbl/(w:tr,w:tr,w:tr)')

0 commit comments

Comments
 (0)