|
11 | 11 | from behave import given, then, when |
12 | 12 |
|
13 | 13 | from docx import Document |
| 14 | +from docx.enum.table import WD_ALIGN_VERTICAL # noqa |
14 | 15 | from docx.enum.table import ( |
15 | 16 | WD_ROW_HEIGHT_RULE, WD_TABLE_ALIGNMENT, WD_TABLE_DIRECTION |
16 | 17 | ) |
@@ -39,6 +40,19 @@ def given_a_3x3_table_having_span_state(context, span_state): |
39 | 40 | context.table_ = document.tables[table_idx] |
40 | 41 |
|
41 | 42 |
|
| 43 | +@given('a _Cell object with {state} vertical alignment as cell') |
| 44 | +def given_a_Cell_object_with_vertical_alignment_as_cell(context, state): |
| 45 | + table_idx = { |
| 46 | + 'inherited': 0, |
| 47 | + 'bottom': 1, |
| 48 | + 'center': 2, |
| 49 | + 'top': 3, |
| 50 | + }[state] |
| 51 | + document = Document(test_docx('tbl-props')) |
| 52 | + table = document.tables[table_idx] |
| 53 | + context.cell = table.cell(0, 0) |
| 54 | + |
| 55 | + |
42 | 56 | @given('a column collection having two columns') |
43 | 57 | def given_a_column_collection_having_two_columns(context): |
44 | 58 | docx_path = test_docx('blk-containing-table') |
@@ -179,6 +193,11 @@ def when_add_row_to_table(context): |
179 | 193 | context.row = table.add_row() |
180 | 194 |
|
181 | 195 |
|
| 196 | +@when('I assign {value} to cell.vertical_alignment') |
| 197 | +def when_I_assign_value_to_cell_vertical_alignment(context, value): |
| 198 | + context.cell.vertical_alignment = eval(value) |
| 199 | + |
| 200 | + |
182 | 201 | @when('I assign {value} to row.height') |
183 | 202 | def when_I_assign_value_to_row_height(context, value): |
184 | 203 | new_value = None if value == 'None' else int(value) |
@@ -257,6 +276,15 @@ def when_I_set_the_table_autofit_to_setting(context, setting): |
257 | 276 |
|
258 | 277 | # then ===================================================== |
259 | 278 |
|
| 279 | +@then('cell.vertical_alignment is {value}') |
| 280 | +def then_cell_vertical_alignment_is_value(context, value): |
| 281 | + expected_value = eval(value) |
| 282 | + actual_value = context.cell.vertical_alignment |
| 283 | + assert actual_value is expected_value, ( |
| 284 | + 'cell.vertical_alignment is %s' % actual_value |
| 285 | + ) |
| 286 | + |
| 287 | + |
260 | 288 | @then('I can access a collection column by index') |
261 | 289 | def then_can_access_collection_column_by_index(context): |
262 | 290 | columns = context.columns |
|
0 commit comments