4
4
Step implementations for table-related features
5
5
"""
6
6
7
- from __future__ import absolute_import , print_function , unicode_literals
7
+ from __future__ import (
8
+ absolute_import , division , print_function , unicode_literals
9
+ )
8
10
9
11
from behave import given , then , when
10
12
@@ -127,6 +129,17 @@ def when_apply_style_to_table(context):
127
129
table .style = 'LightShading-Accent1'
128
130
129
131
132
+ @when ('I merge from cell {origin} to cell {other}' )
133
+ def when_I_merge_from_cell_origin_to_cell_other (context , origin , other ):
134
+ def cell (table , idx ):
135
+ row , col = idx // 3 , idx % 3
136
+ return table .cell (row , col )
137
+ a_idx , b_idx = int (origin ) - 1 , int (other ) - 1
138
+ table = context .table_
139
+ a , b = cell (table , a_idx ), cell (table , b_idx )
140
+ a .merge (b )
141
+
142
+
130
143
@when ('I set the cell width to {width}' )
131
144
def when_I_set_the_cell_width_to_width (context , width ):
132
145
new_value = {'1 inch' : Inches (1 )}[width ]
@@ -266,8 +279,9 @@ def then_the_reported_width_of_the_cell_is_width(context, width):
266
279
)
267
280
268
281
269
- @then ('the row cells text is {expected_text}' )
270
- def then_the_row_cells_text_is_expected_text (context , expected_text ):
282
+ @then ('the row cells text is {encoded_text}' )
283
+ def then_the_row_cells_text_is_expected_text (context , encoded_text ):
284
+ expected_text = encoded_text .replace ('\\ ' , '\n ' )
271
285
table = context .table_
272
286
cells_text = ' ' .join (c .text for row in table .rows for c in row .cells )
273
287
assert cells_text == expected_text , 'got %s' % cells_text
@@ -292,3 +306,13 @@ def then_table_has_count_rows(context, count):
292
306
row_count = int (count )
293
307
rows = context .table_ .rows
294
308
assert len (rows ) == row_count
309
+
310
+
311
+ @then ('the width of cell {n_str} is {inches_str} inches' )
312
+ def then_the_width_of_cell_n_is_x_inches (context , n_str , inches_str ):
313
+ def _cell (table , idx ):
314
+ row , col = idx // 3 , idx % 3
315
+ return table .cell (row , col )
316
+ idx , inches = int (n_str ) - 1 , float (inches_str )
317
+ cell = _cell (context .table_ , idx )
318
+ assert cell .width == Inches (inches ), 'got %s' % cell .width .inches
0 commit comments