|
11 | 11 | from behave import given, then, when |
12 | 12 |
|
13 | 13 | from docx import Document |
14 | | -from docx.enum.table import WD_TABLE_ALIGNMENT |
| 14 | +from docx.enum.table import WD_TABLE_ALIGNMENT, WD_TABLE_DIRECTION |
15 | 15 | from docx.shared import Inches |
16 | 16 | from docx.table import _Column, _Columns, _Row, _Rows |
17 | 17 |
|
@@ -112,6 +112,17 @@ def given_a_table_having_style(context, style): |
112 | 112 | context.table_ = document.tables[table_idx] |
113 | 113 |
|
114 | 114 |
|
| 115 | +@given('a table having table direction set {setting}') |
| 116 | +def given_a_table_having_table_direction_setting(context, setting): |
| 117 | + table_idx = [ |
| 118 | + 'to inherit', |
| 119 | + 'right-to-left', |
| 120 | + 'left-to-right' |
| 121 | + ].index(setting) |
| 122 | + document = Document(test_docx('tbl-on-off-props')) |
| 123 | + context.table_ = document.tables[table_idx] |
| 124 | + |
| 125 | + |
115 | 126 | @given('a table having two columns') |
116 | 127 | def given_a_table_having_two_columns(context): |
117 | 128 | docx_path = test_docx('blk-containing-table') |
@@ -165,6 +176,14 @@ def when_apply_value_to_table_style(context, value): |
165 | 176 | table.style = new_value |
166 | 177 |
|
167 | 178 |
|
| 179 | +@when('I assign {value} to table.table_direction') |
| 180 | +def when_assign_value_to_table_table_direction(context, value): |
| 181 | + new_value = ( |
| 182 | + None if value == 'None' else getattr(WD_TABLE_DIRECTION, value) |
| 183 | + ) |
| 184 | + context.table_.table_direction = new_value |
| 185 | + |
| 186 | + |
168 | 187 | @when('I merge from cell {origin} to cell {other}') |
169 | 188 | def when_I_merge_from_cell_origin_to_cell_other(context, origin, other): |
170 | 189 | def cell(table, idx): |
@@ -274,6 +293,15 @@ def then_table_style_is_styles_style_name(context, style_name): |
274 | 293 | assert table.style == expected_style, "got '%s'" % table.style |
275 | 294 |
|
276 | 295 |
|
| 296 | +@then('table.table_direction is {value}') |
| 297 | +def then_table_table_direction_is_value(context, value): |
| 298 | + expected_value = ( |
| 299 | + None if value == 'None' else getattr(WD_TABLE_DIRECTION, value) |
| 300 | + ) |
| 301 | + actual_value = context.table_.table_direction |
| 302 | + assert actual_value == expected_value, "got '%s'" % actual_value |
| 303 | + |
| 304 | + |
277 | 305 | @then('the column cells text is {expected_text}') |
278 | 306 | def then_the_column_cells_text_is_expected_text(context, expected_text): |
279 | 307 | table = context.table_ |
|
0 commit comments