@@ -89,13 +89,6 @@ def given_a_table_having_alignment_alignment(context, alignment):
89
89
context .table_ = document .tables [table_idx ]
90
90
91
91
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
-
99
92
@given ('a table having an autofit layout of {autofit}' )
100
93
def given_a_table_having_an_autofit_layout_of_autofit (context , autofit ):
101
94
tbl_idx = {
@@ -107,6 +100,18 @@ def given_a_table_having_an_autofit_layout_of_autofit(context, autofit):
107
100
context .table_ = document .tables [tbl_idx ]
108
101
109
102
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
+
110
115
@given ('a table having two columns' )
111
116
def given_a_table_having_two_columns (context ):
112
117
docx_path = test_docx ('blk-containing-table' )
@@ -137,12 +142,6 @@ def when_add_row_to_table(context):
137
142
context .row = table .add_row ()
138
143
139
144
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
-
146
145
@when ('I assign {value_str} to table.alignment' )
147
146
def when_I_assign_value_to_table_alignment (context , value_str ):
148
147
value = {
@@ -155,6 +154,18 @@ def when_I_assign_value_to_table_alignment(context, value_str):
155
154
table .alignment = value
156
155
157
156
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
+
158
169
@when ('I merge from cell {origin} to cell {other}' )
159
170
def when_I_merge_from_cell_origin_to_cell_other (context , origin , other ):
160
171
def cell (table , idx ):
@@ -217,13 +228,6 @@ def then_can_access_row_collection_of_table(context):
217
228
assert isinstance (rows , _Rows )
218
229
219
230
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
-
227
231
@then ('I can iterate over the column collection' )
228
232
def then_can_iterate_over_column_collection (context ):
229
233
columns = context .columns
@@ -264,6 +268,13 @@ def then_table_cell_row_col_text_is_text(context, row, col, expected_text):
264
268
assert cell_text == expected_text , 'got %s' % cell_text
265
269
266
270
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
+
267
278
@then ('the column cells text is {expected_text}' )
268
279
def then_the_column_cells_text_is_expected_text (context , expected_text ):
269
280
table = context .table_
@@ -325,13 +336,6 @@ def then_the_row_cells_text_is_expected_text(context, encoded_text):
325
336
assert cells_text == expected_text , 'got %s' % cells_text
326
337
327
338
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
-
335
339
@then ('the table has {count} columns' )
336
340
def then_table_has_count_columns (context , count ):
337
341
column_count = int (count )
0 commit comments