@@ -89,13 +89,6 @@ def given_a_table_having_alignment_alignment(context, alignment):
8989 context .table_ = document .tables [table_idx ]
9090
9191
92- @given ('a table having an applied style' )
93- def given_a_table_having_an_applied_style (context ):
94- docx_path = test_docx ('tbl-having-applied-style' )
95- document = Document (docx_path )
96- context .table_ = document .tables [0 ]
97-
98-
9992@given ('a table having an autofit layout of {autofit}' )
10093def given_a_table_having_an_autofit_layout_of_autofit (context , autofit ):
10194 tbl_idx = {
@@ -107,6 +100,18 @@ def given_a_table_having_an_autofit_layout_of_autofit(context, autofit):
107100 context .table_ = document .tables [tbl_idx ]
108101
109102
103+ @given ('a table having {style} style' )
104+ def given_a_table_having_style (context , style ):
105+ table_idx = {
106+ 'no explicit' : 0 ,
107+ 'Table Grid' : 1 ,
108+ 'Light Shading - Accent 1' : 2 ,
109+ }[style ]
110+ document = Document (test_docx ('tbl-having-applied-style' ))
111+ context .document = document
112+ context .table_ = document .tables [table_idx ]
113+
114+
110115@given ('a table having two columns' )
111116def given_a_table_having_two_columns (context ):
112117 docx_path = test_docx ('blk-containing-table' )
@@ -137,12 +142,6 @@ def when_add_row_to_table(context):
137142 context .row = table .add_row ()
138143
139144
140- @when ('I apply a style to the table' )
141- def when_apply_style_to_table (context ):
142- table = context .table_
143- table .style = 'LightShading-Accent1'
144-
145-
146145@when ('I assign {value_str} to table.alignment' )
147146def when_I_assign_value_to_table_alignment (context , value_str ):
148147 value = {
@@ -155,6 +154,18 @@ def when_I_assign_value_to_table_alignment(context, value_str):
155154 table .alignment = value
156155
157156
157+ @when ('I assign {value} to table.style' )
158+ def when_apply_value_to_table_style (context , value ):
159+ table , styles = context .table_ , context .document .styles
160+ if value == 'None' :
161+ new_value = None
162+ elif value .startswith ('styles[' ):
163+ new_value = styles [value .split ('\' ' )[1 ]]
164+ else :
165+ new_value = styles [value ]
166+ table .style = new_value
167+
168+
158169@when ('I merge from cell {origin} to cell {other}' )
159170def when_I_merge_from_cell_origin_to_cell_other (context , origin , other ):
160171 def cell (table , idx ):
@@ -217,13 +228,6 @@ def then_can_access_row_collection_of_table(context):
217228 assert isinstance (rows , _Rows )
218229
219230
220- @then ('I can get the table style name' )
221- def then_can_get_table_style_name (context ):
222- table = context .table_
223- msg = "got '%s'" % table .style
224- assert table .style == 'LightShading-Accent1' , msg
225-
226-
227231@then ('I can iterate over the column collection' )
228232def then_can_iterate_over_column_collection (context ):
229233 columns = context .columns
@@ -264,6 +268,13 @@ def then_table_cell_row_col_text_is_text(context, row, col, expected_text):
264268 assert cell_text == expected_text , 'got %s' % cell_text
265269
266270
271+ @then ('table.style is styles[\' {style_name}\' ]' )
272+ def then_table_style_is_styles_style_name (context , style_name ):
273+ table , styles = context .table_ , context .document .styles
274+ expected_style = styles [style_name ]
275+ assert table .style == expected_style , "got '%s'" % table .style
276+
277+
267278@then ('the column cells text is {expected_text}' )
268279def then_the_column_cells_text_is_expected_text (context , expected_text ):
269280 table = context .table_
@@ -325,13 +336,6 @@ def then_the_row_cells_text_is_expected_text(context, encoded_text):
325336 assert cells_text == expected_text , 'got %s' % cells_text
326337
327338
328- @then ('the table style matches the name I applied' )
329- def then_table_style_matches_name_applied (context ):
330- table = context .table_
331- tmpl = "table.style doesn't match, got '%s'"
332- assert table .style == 'LightShading-Accent1' , tmpl % table .style
333-
334-
335339@then ('the table has {count} columns' )
336340def then_table_has_count_columns (context , count ):
337341 column_count = int (count )
0 commit comments