99import pytest
1010
1111from docx .blkcntnr import BlockItemContainer
12+ from docx .shared import Inches
1213from docx .table import Table
1314from docx .text .paragraph import Paragraph
1415
1516from .unitutil .cxml import element , xml
17+ from .unitutil .file import snippet_seq
1618from .unitutil .mock import call , instance_mock , method_mock
1719
1820
@@ -30,10 +32,11 @@ def it_can_add_a_paragraph(self, add_paragraph_fixture):
3032 assert new_paragraph is paragraph_
3133
3234 def it_can_add_a_table (self , add_table_fixture ):
33- blkcntnr , rows , cols , expected_xml = add_table_fixture
34- table = blkcntnr .add_table (rows , cols , None )
35- assert blkcntnr ._element .xml == expected_xml
35+ blkcntnr , rows , cols , width , expected_xml = add_table_fixture
36+ table = blkcntnr .add_table (rows , cols , width )
3637 assert isinstance (table , Table )
38+ assert table ._element .xml == expected_xml
39+ assert table ._parent is blkcntnr
3740
3841 def it_provides_access_to_the_paragraphs_it_contains (
3942 self , paragraphs_fixture ):
@@ -91,21 +94,12 @@ def _add_paragraph_fixture(self, request):
9194 expected_xml = xml (after_cxml )
9295 return blkcntnr , expected_xml
9396
94- @pytest .fixture (params = [
95- ('w:body' , 0 , 0 , 'w:body/w:tbl/(w:tblPr/w:tblW{w:type=auto,w:w=0},w:'
96- 'tblGrid)' ),
97- ('w:body' , 1 , 0 , 'w:body/w:tbl/(w:tblPr/w:tblW{w:type=auto,w:w=0},w:'
98- 'tblGrid,w:tr)' ),
99- ('w:body' , 0 , 1 , 'w:body/w:tbl/(w:tblPr/w:tblW{w:type=auto,w:w=0},w:'
100- 'tblGrid/w:gridCol)' ),
101- ('w:body' , 1 , 1 , 'w:body/w:tbl/(w:tblPr/w:tblW{w:type=auto,w:w=0},w:'
102- 'tblGrid/w:gridCol,w:tr/w:tc/w:p)' ),
103- ])
104- def add_table_fixture (self , request ):
105- blkcntnr_cxml , rows , cols , after_cxml = request .param
106- blkcntnr = BlockItemContainer (element (blkcntnr_cxml ), None )
107- expected_xml = xml (after_cxml )
108- return blkcntnr , rows , cols , expected_xml
97+ @pytest .fixture
98+ def add_table_fixture (self ):
99+ blkcntnr = BlockItemContainer (element ('w:body' ), None )
100+ rows , cols , width = 2 , 2 , Inches (2 )
101+ expected_xml = snippet_seq ('new-tbl' )[0 ]
102+ return blkcntnr , rows , cols , width , expected_xml
109103
110104 @pytest .fixture (params = [
111105 ('w:body' , 0 ),
0 commit comments