|
18 | 18 |
|
19 | 19 | # given =================================================== |
20 | 20 |
|
| 21 | +@given('a 2 x 2 table') |
| 22 | +def given_a_2x2_table(context): |
| 23 | + context.table_ = Document().add_table(rows=2, cols=2) |
| 24 | + |
| 25 | + |
21 | 26 | @given('a column cell collection having two cells') |
22 | 27 | def given_a_column_cell_collection_having_two_cells(context): |
23 | 28 | docx_path = test_docx('blk-containing-table') |
@@ -48,7 +53,7 @@ def given_a_row_collection_having_two_rows(context): |
48 | 53 |
|
49 | 54 | @given('a table') |
50 | 55 | def given_a_table(context): |
51 | | - context.table_ = Document().body.add_table(rows=2, cols=2) |
| 56 | + context.table_ = Document().add_table(rows=2, cols=2) |
52 | 57 |
|
53 | 58 |
|
54 | 59 | @given('a table having an applied style') |
@@ -90,6 +95,18 @@ def given_a_table_row_having_two_cells(context): |
90 | 95 |
|
91 | 96 | # when ===================================================== |
92 | 97 |
|
| 98 | +@when('I add a column to the table') |
| 99 | +def when_add_column_to_table(context): |
| 100 | + table = context.table_ |
| 101 | + context.column = table.add_column() |
| 102 | + |
| 103 | + |
| 104 | +@when('I add a row to the table') |
| 105 | +def when_add_row_to_table(context): |
| 106 | + table = context.table_ |
| 107 | + context.row = table.add_row() |
| 108 | + |
| 109 | + |
93 | 110 | @when('I apply a style to the table') |
94 | 111 | def when_apply_style_to_table(context): |
95 | 112 | table = context.table_ |
@@ -240,8 +257,32 @@ def then_len_of_row_collection_is_2(context): |
240 | 257 | assert len(rows) == 2 |
241 | 258 |
|
242 | 259 |
|
| 260 | +@then('the new column has 2 cells') |
| 261 | +def then_new_column_has_2_cells(context): |
| 262 | + assert len(context.column.cells) == 2 |
| 263 | + |
| 264 | + |
| 265 | +@then('the new row has 2 cells') |
| 266 | +def then_new_row_has_2_cells(context): |
| 267 | + assert len(context.row.cells) == 2 |
| 268 | + |
| 269 | + |
243 | 270 | @then('the table style matches the name I applied') |
244 | 271 | def then_table_style_matches_name_applied(context): |
245 | 272 | table = context.table_ |
246 | 273 | tmpl = "table.style doesn't match, got '%s'" |
247 | 274 | assert table.style == 'LightShading-Accent1', tmpl % table.style |
| 275 | + |
| 276 | + |
| 277 | +@then('the table has {count} columns') |
| 278 | +def then_table_has_count_columns(context, count): |
| 279 | + column_count = int(count) |
| 280 | + columns = context.table_.columns |
| 281 | + assert len(columns) == column_count |
| 282 | + |
| 283 | + |
| 284 | +@then('the table has {count} rows') |
| 285 | +def then_table_has_count_rows(context, count): |
| 286 | + row_count = int(count) |
| 287 | + rows = context.table_.rows |
| 288 | + assert len(rows) == row_count |
0 commit comments