|
9 | 9 | import pytest
|
10 | 10 |
|
11 | 11 | from docx.oxml import parse_xml
|
| 12 | +from docx.oxml.table import CT_Tc |
12 | 13 | from docx.shared import Inches
|
13 | 14 | from docx.table import _Cell, _Column, _Columns, _Row, _Rows, Table
|
14 | 15 | from docx.text import Paragraph
|
@@ -289,6 +290,14 @@ def it_can_add_a_table(self, add_table_fixture):
|
289 | 290 | assert cell._tc.xml == expected_xml
|
290 | 291 | assert isinstance(table, Table)
|
291 | 292 |
|
| 293 | + def it_can_merge_itself_with_other_cells(self, merge_fixture): |
| 294 | + cell, other_cell, merged_tc_ = merge_fixture |
| 295 | + merged_cell = cell.merge(other_cell) |
| 296 | + cell._tc.merge.assert_called_once_with(other_cell._tc) |
| 297 | + assert isinstance(merged_cell, _Cell) |
| 298 | + assert merged_cell._tc is merged_tc_ |
| 299 | + assert merged_cell._parent is cell._parent |
| 300 | + |
292 | 301 | # fixtures -------------------------------------------------------
|
293 | 302 |
|
294 | 303 | @pytest.fixture(params=[
|
@@ -317,6 +326,12 @@ def add_table_fixture(self, request):
|
317 | 326 | expected_xml = xml(after_tc_cxml)
|
318 | 327 | return cell, expected_xml
|
319 | 328 |
|
| 329 | + @pytest.fixture |
| 330 | + def merge_fixture(self, tc_, tc_2_, parent_, merged_tc_): |
| 331 | + cell, other_cell = _Cell(tc_, parent_), _Cell(tc_2_, parent_) |
| 332 | + tc_.merge.return_value = merged_tc_ |
| 333 | + return cell, other_cell, merged_tc_ |
| 334 | + |
320 | 335 | @pytest.fixture
|
321 | 336 | def paragraphs_fixture(self):
|
322 | 337 | return _Cell(element('w:tc/(w:p, w:p)'), None)
|
@@ -383,6 +398,24 @@ def width_set_fixture(self, request):
|
383 | 398 | expected_xml = xml(expected_cxml)
|
384 | 399 | return cell, new_value, expected_xml
|
385 | 400 |
|
| 401 | + # fixture components --------------------------------------------- |
| 402 | + |
| 403 | + @pytest.fixture |
| 404 | + def merged_tc_(self, request): |
| 405 | + return instance_mock(request, CT_Tc) |
| 406 | + |
| 407 | + @pytest.fixture |
| 408 | + def parent_(self, request): |
| 409 | + return instance_mock(request, Table) |
| 410 | + |
| 411 | + @pytest.fixture |
| 412 | + def tc_(self, request): |
| 413 | + return instance_mock(request, CT_Tc) |
| 414 | + |
| 415 | + @pytest.fixture |
| 416 | + def tc_2_(self, request): |
| 417 | + return instance_mock(request, CT_Tc) |
| 418 | + |
386 | 419 |
|
387 | 420 | class Describe_Column(object):
|
388 | 421 |
|
|
0 commit comments