1111from behave import given , then , when
1212
1313from docx import Document
14- from docx .enum .table import WD_TABLE_ALIGNMENT , WD_TABLE_DIRECTION
14+ from docx .enum .table import (
15+ WD_ROW_HEIGHT_RULE , WD_TABLE_ALIGNMENT , WD_TABLE_DIRECTION
16+ )
1517from docx .shared import Inches
1618from docx .table import _Column , _Columns , _Row , _Rows
1719
@@ -139,6 +141,31 @@ def given_a_table_having_two_rows(context):
139141 context .table_ = document .tables [0 ]
140142
141143
144+ @given ('a table row having height of {state}' )
145+ def given_a_table_row_having_height_of_state (context , state ):
146+ table_idx = {
147+ 'no explicit setting' : 0 ,
148+ '2 inches' : 2 ,
149+ '3 inches' : 3
150+ }[state ]
151+ document = Document (test_docx ('tbl-props' ))
152+ table = document .tables [table_idx ]
153+ context .row = table .rows [0 ]
154+
155+
156+ @given ('a table row having height rule {state}' )
157+ def given_a_table_row_having_height_rule_state (context , state ):
158+ table_idx = {
159+ 'no explicit setting' : 0 ,
160+ 'automatic' : 1 ,
161+ 'at least' : 2 ,
162+ 'exactly' : 3
163+ }[state ]
164+ document = Document (test_docx ('tbl-props' ))
165+ table = document .tables [table_idx ]
166+ context .row = table .rows [0 ]
167+
168+
142169# when =====================================================
143170
144171@when ('I add a 1.0 inch column to the table' )
@@ -152,6 +179,20 @@ def when_add_row_to_table(context):
152179 context .row = table .add_row ()
153180
154181
182+ @when ('I assign {value} to row.height' )
183+ def when_I_assign_value_to_row_height (context , value ):
184+ new_value = None if value == 'None' else int (value )
185+ context .row .height = new_value
186+
187+
188+ @when ('I assign {value} to row.height_rule' )
189+ def when_I_assign_value_to_row_height_rule (context , value ):
190+ new_value = (
191+ None if value == 'None' else getattr (WD_ROW_HEIGHT_RULE , value )
192+ )
193+ context .row .height_rule = new_value
194+
195+
155196@when ('I assign {value_str} to table.alignment' )
156197def when_I_assign_value_to_table_alignment (context , value_str ):
157198 value = {
@@ -266,6 +307,26 @@ def then_can_iterate_over_row_collection(context):
266307 assert actual_count == 2
267308
268309
310+ @then ('row.height is {value}' )
311+ def then_row_height_is_value (context , value ):
312+ expected_height = None if value == 'None' else int (value )
313+ actual_height = context .row .height
314+ assert actual_height == expected_height , (
315+ 'expected %s, got %s' % (expected_height , actual_height )
316+ )
317+
318+
319+ @then ('row.height_rule is {value}' )
320+ def then_row_height_rule_is_value (context , value ):
321+ expected_rule = (
322+ None if value == 'None' else getattr (WD_ROW_HEIGHT_RULE , value )
323+ )
324+ actual_rule = context .row .height_rule
325+ assert actual_rule == expected_rule , (
326+ 'expected %s, got %s' % (expected_rule , actual_rule )
327+ )
328+
329+
269330@then ('table.alignment is {value_str}' )
270331def then_table_alignment_is_value (context , value_str ):
271332 value = {
0 commit comments