Skip to content

Commit d278197

Browse files
author
Steve Canny
committed
acpt: add scenarios for Table.table_direction
1 parent 221e28c commit d278197

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

docx/table.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ def table(self):
145145
"""
146146
return self
147147

148+
@property
149+
def table_direction(self):
150+
"""
151+
A member of :ref:`WdTableDirection` indicating the direction in which
152+
the table cells are ordered, e.g. `WD_TABLE_DIRECTION.LTR`. |None|
153+
indicates the value is inherited from the style hierarchy.
154+
"""
155+
raise NotImplementedError
156+
148157
@property
149158
def _cells(self):
150159
"""

features/steps/table.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from behave import given, then, when
1212

1313
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
1515
from docx.shared import Inches
1616
from docx.table import _Column, _Columns, _Row, _Rows
1717

@@ -112,6 +112,17 @@ def given_a_table_having_style(context, style):
112112
context.table_ = document.tables[table_idx]
113113

114114

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+
115126
@given('a table having two columns')
116127
def given_a_table_having_two_columns(context):
117128
docx_path = test_docx('blk-containing-table')
@@ -165,6 +176,14 @@ def when_apply_value_to_table_style(context, value):
165176
table.style = new_value
166177

167178

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+
168187
@when('I merge from cell {origin} to cell {other}')
169188
def when_I_merge_from_cell_origin_to_cell_other(context, origin, other):
170189
def cell(table, idx):
@@ -274,6 +293,15 @@ def then_table_style_is_styles_style_name(context, style_name):
274293
assert table.style == expected_style, "got '%s'" % table.style
275294

276295

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+
277305
@then('the column cells text is {expected_text}')
278306
def then_the_column_cells_text_is_expected_text(context, expected_text):
279307
table = context.table_
15.6 KB
Binary file not shown.

features/tbl-props.feature

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Feature: Get and set table properties
44
I need a way to get and set a table's properties
55

66

7-
Scenario Outline: Determine table alignment
7+
Scenario Outline: Get table alignment
88
Given a table having <alignment> alignment
99
Then table.alignment is <value>
1010

@@ -53,3 +53,28 @@ Feature: Get and set table properties
5353
| autofit | autofit | autofit |
5454
| fixed | fixed | fixed |
5555
| autofit | fixed | fixed |
56+
57+
58+
@wip
59+
Scenario Outline: Get table direction
60+
Given a table having table direction set <setting>
61+
Then table.table_direction is <value>
62+
63+
Examples: Table on/off property values
64+
| setting | value |
65+
| to inherit | None |
66+
| right-to-left | RTL |
67+
| left-to-right | LTR |
68+
69+
70+
@wip
71+
Scenario Outline: Set table direction
72+
Given a table having table direction set <setting>
73+
When I assign <new-value> to table.table_direction
74+
Then table.table_direction is <value>
75+
76+
Examples: Results of assignment to Table.table_direction
77+
| setting | new-value | value |
78+
| to inherit | RTL | RTL |
79+
| right-to-left | LTR | LTR |
80+
| left-to-right | None | None |

0 commit comments

Comments
 (0)