|
6 | 6 |
|
7 | 7 | from __future__ import absolute_import, print_function, unicode_literals |
8 | 8 |
|
9 | | -from behave import given, then |
| 9 | +from behave import given, then, when |
10 | 10 |
|
11 | 11 | from docx import Document |
12 | 12 | from docx.table import ( |
@@ -47,6 +47,18 @@ def given_a_row_collection_having_two_rows(context): |
47 | 47 | context.rows = document.body.tables[0].rows |
48 | 48 |
|
49 | 49 |
|
| 50 | +@given('a table') |
| 51 | +def given_a_table(context): |
| 52 | + context.table_ = Document().body.add_table(rows=2, cols=2) |
| 53 | + |
| 54 | + |
| 55 | +@given('a table having an applied style') |
| 56 | +def given_a_table_having_an_applied_style(context): |
| 57 | + docx_path = test_docx('tbl-having-applied-style') |
| 58 | + document = Document(docx_path) |
| 59 | + context.table_ = document.body.tables[0] |
| 60 | + |
| 61 | + |
50 | 62 | @given('a table having two columns') |
51 | 63 | def given_a_table_having_two_columns(context): |
52 | 64 | docx_path = test_docx('blk-containing-table') |
@@ -77,6 +89,14 @@ def given_a_table_row_having_two_cells(context): |
77 | 89 | context.row = document.body.tables[0].rows[0] |
78 | 90 |
|
79 | 91 |
|
| 92 | +# when ===================================================== |
| 93 | + |
| 94 | +@when('I apply a style to the table') |
| 95 | +def when_apply_style_to_table(context): |
| 96 | + table = context.table_ |
| 97 | + table.style = 'LightShading-Accent1' |
| 98 | + |
| 99 | + |
80 | 100 | # then ===================================================== |
81 | 101 |
|
82 | 102 | @then('I can access a cell using its row and column indices') |
@@ -162,6 +182,12 @@ def then_can_get_length_of_row_cell_collection(context): |
162 | 182 | assert len(cells) == 2 |
163 | 183 |
|
164 | 184 |
|
| 185 | +@then('I can get the table style name') |
| 186 | +def then_can_get_table_style_name(context): |
| 187 | + table = context.table_ |
| 188 | + assert table.style == 'foobar', "got '%s'" % table.style |
| 189 | + |
| 190 | + |
165 | 191 | @then('I can iterate over the column cells') |
166 | 192 | def then_can_iterate_over_the_column_cells(context): |
167 | 193 | cells = context.cells |
@@ -212,3 +238,10 @@ def then_len_of_column_collection_is_2(context): |
212 | 238 | def then_len_of_row_collection_is_2(context): |
213 | 239 | rows = context.table_.rows |
214 | 240 | assert len(rows) == 2 |
| 241 | + |
| 242 | + |
| 243 | +@then('the table style matches the name I applied') |
| 244 | +def then_table_style_matches_name_applied(context): |
| 245 | + table = context.table_ |
| 246 | + tmpl = "table.style doesn't match, got '%s'" |
| 247 | + assert table.style == 'LightShading-Accent1', tmpl % table.style |
0 commit comments