@@ -73,6 +73,21 @@ def it_can_extend_its_horz_span_to_help_merge(self, span_width_fixture):
73
73
assert tc ._swallow_next_tc .call_args_list == expected_calls
74
74
assert tc .vMerge == vMerge
75
75
76
+ def it_can_swallow_the_next_tc_help_merge (self , swallow_fixture ):
77
+ tc , grid_width , top_tc , tr , expected_xml = swallow_fixture
78
+ tc ._swallow_next_tc (grid_width , top_tc )
79
+ assert tr .xml == expected_xml
80
+
81
+ def it_adds_cell_widths_on_swallow (self , add_width_fixture ):
82
+ tc , grid_width , top_tc , tr , expected_xml = add_width_fixture
83
+ tc ._swallow_next_tc (grid_width , top_tc )
84
+ assert tr .xml == expected_xml
85
+
86
+ def it_raises_on_invalid_swallow (self , swallow_raise_fixture ):
87
+ tc , grid_width , top_tc , tr = swallow_raise_fixture
88
+ with pytest .raises (InvalidSpanError ):
89
+ tc ._swallow_next_tc (grid_width , top_tc )
90
+
76
91
def it_can_move_its_content_to_help_merge (self , move_fixture ):
77
92
tc , tc_2 , expected_tc_xml , expected_tc_2_xml = move_fixture
78
93
tc ._move_content_to (tc_2 )
@@ -86,6 +101,32 @@ def it_raises_on_tr_above(self, tr_above_raise_fixture):
86
101
87
102
# fixtures -------------------------------------------------------
88
103
104
+ @pytest .fixture (params = [
105
+ # both cells have a width
106
+ ('w:tr/(w:tc/(w:tcPr/w:tcW{w:w=1440,w:type=dxa},w:p),'
107
+ 'w:tc/(w:tcPr/w:tcW{w:w=1440,w:type=dxa},w:p))' , 0 , 2 ,
108
+ 'w:tr/(w:tc/(w:tcPr/(w:tcW{w:w=2880,w:type=dxa},'
109
+ 'w:gridSpan{w:val=2}),w:p))' ),
110
+ # neither have a width
111
+ ('w:tr/(w:tc/w:p,w:tc/w:p)' , 0 , 2 ,
112
+ 'w:tr/(w:tc/(w:tcPr/w:gridSpan{w:val=2},w:p))' ),
113
+ # only second one has a width
114
+ ('w:tr/(w:tc/w:p,'
115
+ 'w:tc/(w:tcPr/w:tcW{w:w=1440,w:type=dxa},w:p))' , 0 , 2 ,
116
+ 'w:tr/(w:tc/(w:tcPr/w:gridSpan{w:val=2},w:p))' ),
117
+ # only first one has a width
118
+ ('w:tr/(w:tc/(w:tcPr/w:tcW{w:w=1440,w:type=dxa},w:p),'
119
+ 'w:tc/w:p)' , 0 , 2 ,
120
+ 'w:tr/(w:tc/(w:tcPr/(w:tcW{w:w=1440,w:type=dxa},'
121
+ 'w:gridSpan{w:val=2}),w:p))' ),
122
+ ])
123
+ def add_width_fixture (self , request ):
124
+ tr_cxml , tc_idx , grid_width , expected_tr_cxml = request .param
125
+ tr = element (tr_cxml )
126
+ tc = top_tc = tr [tc_idx ]
127
+ expected_tr_xml = xml (expected_tr_cxml )
128
+ return tc , grid_width , top_tc , tr , expected_tr_xml
129
+
89
130
@pytest .fixture (params = [
90
131
(0 , 0 , 0 , 'top' , 0 ), (2 , 0 , 1 , 'top' , 0 ),
91
132
(2 , 1 , 1 , 'top' , 0 ), (4 , 2 , 1 , 'top' , 1 ),
@@ -202,6 +243,36 @@ def span_width_fixture(
202
243
]
203
244
return tc , grid_width , top_tc_ , vMerge , expected_calls
204
245
246
+ @pytest .fixture (params = [
247
+ ('w:tr/(w:tc/w:p,w:tc/w:p)' , 0 , 2 ,
248
+ 'w:tr/(w:tc/(w:tcPr/w:gridSpan{w:val=2},w:p))' ),
249
+ ('w:tr/(w:tc/w:p,w:tc/w:p,w:tc/w:p)' , 1 , 2 ,
250
+ 'w:tr/(w:tc/w:p,w:tc/(w:tcPr/w:gridSpan{w:val=2},w:p))' ),
251
+ ('w:tr/(w:tc/w:p/w:r/w:t"a",w:tc/w:p/w:r/w:t"b")' , 0 , 2 ,
252
+ 'w:tr/(w:tc/(w:tcPr/w:gridSpan{w:val=2},w:p/w:r/w:t"a",'
253
+ 'w:p/w:r/w:t"b"))' ),
254
+ ('w:tr/(w:tc/(w:tcPr/w:gridSpan{w:val=2},w:p),w:tc/w:p)' , 0 , 3 ,
255
+ 'w:tr/(w:tc/(w:tcPr/w:gridSpan{w:val=3},w:p))' ),
256
+ ('w:tr/(w:tc/w:p,w:tc/(w:tcPr/w:gridSpan{w:val=2},w:p))' , 0 , 3 ,
257
+ 'w:tr/(w:tc/(w:tcPr/w:gridSpan{w:val=3},w:p))' ),
258
+ ])
259
+ def swallow_fixture (self , request ):
260
+ tr_cxml , tc_idx , grid_width , expected_tr_cxml = request .param
261
+ tr = element (tr_cxml )
262
+ tc = top_tc = tr [tc_idx ]
263
+ expected_tr_xml = xml (expected_tr_cxml )
264
+ return tc , grid_width , top_tc , tr , expected_tr_xml
265
+
266
+ @pytest .fixture (params = [
267
+ ('w:tr/w:tc/w:p' , 0 , 2 ),
268
+ ('w:tr/(w:tc/w:p,w:tc/(w:tcPr/w:gridSpan{w:val=2},w:p))' , 0 , 2 ),
269
+ ])
270
+ def swallow_raise_fixture (self , request ):
271
+ tr_cxml , tc_idx , grid_width = request .param
272
+ tr = element (tr_cxml )
273
+ tc = top_tc = tr [tc_idx ]
274
+ return tc , grid_width , top_tc , tr
275
+
205
276
@pytest .fixture (params = [(0 , 0 , 0 ), (4 , 0 , 0 )])
206
277
def tr_above_raise_fixture (self , request ):
207
278
snippet_idx , row_idx , col_idx = request .param
0 commit comments