2121from docx .text import Paragraph , Run
2222
2323from ..oxml .parts .unitdata .document import a_body , a_document
24- from ..oxml .unitdata .table import (
25- a_gridCol , a_tbl , a_tblGrid , a_tblPr , a_tblW , a_tc , a_tr
26- )
27- from ..oxml .unitdata .text import a_p , a_sectPr
24+ from ..oxml .unitdata .text import a_p
2825from ..unitutil .cxml import element , xml
2926from ..unitutil .mock import (
3027 instance_mock , class_mock , loose_mock , method_mock , property_mock
@@ -295,9 +292,9 @@ def it_can_add_a_paragraph(self, add_paragraph_fixture):
295292 assert isinstance (p , Paragraph )
296293
297294 def it_can_add_a_table (self , add_table_fixture ):
298- body , expected_xml = add_table_fixture
299- table = body .add_table (rows = 1 , cols = 1 )
300- assert body ._body .xml == expected_xml
295+ body , rows , cols , expected_xml = add_table_fixture
296+ table = body .add_table (rows , cols )
297+ assert body ._element .xml == expected_xml
301298 assert isinstance (table , Table )
302299
303300 def it_can_clear_itself_of_all_content_it_holds (self , clear_fixture ):
@@ -335,19 +332,21 @@ def add_paragraph_fixture(self, request):
335332 expected_xml = xml (after_cxml )
336333 return body , expected_xml
337334
338- @pytest .fixture (params = [(0 , False ), (0 , True ), (1 , False ), (1 , True )])
335+ @pytest .fixture (params = [
336+ ('w:body' , 0 , 0 , 'w:body/w:tbl/(w:tblPr/w:tblW{w:type=auto,w:w=0},w:'
337+ 'tblGrid)' ),
338+ ('w:body' , 1 , 0 , 'w:body/w:tbl/(w:tblPr/w:tblW{w:type=auto,w:w=0},w:'
339+ 'tblGrid,w:tr)' ),
340+ ('w:body' , 0 , 1 , 'w:body/w:tbl/(w:tblPr/w:tblW{w:type=auto,w:w=0},w:'
341+ 'tblGrid/w:gridCol)' ),
342+ ('w:body' , 1 , 1 , 'w:body/w:tbl/(w:tblPr/w:tblW{w:type=auto,w:w=0},w:'
343+ 'tblGrid/w:gridCol,w:tr/w:tc/w:p)' ),
344+ ])
339345 def add_table_fixture (self , request ):
340- p_count , has_sectPr = request .param
341- body_bldr = self ._body_bldr (p_count = p_count , sectPr = has_sectPr )
342- body = _Body (body_bldr .element , None )
343-
344- tbl_bldr = self ._tbl_bldr ()
345- body_bldr = self ._body_bldr (
346- p_count = p_count , tbl_bldr = tbl_bldr , sectPr = has_sectPr
347- )
348- expected_xml = body_bldr .xml ()
349-
350- return body , expected_xml
346+ body_cxml , rows , cols , after_cxml = request .param
347+ body = _Body (element (body_cxml ), None )
348+ expected_xml = xml (after_cxml )
349+ return body , rows , cols , expected_xml
351350
352351 @pytest .fixture (params = [
353352 ('w:body' , 'w:body' ),
@@ -369,47 +368,6 @@ def paragraphs_fixture(self):
369368 def tables_fixture (self ):
370369 return _Body (element ('w:body/(w:tbl, w:tbl)' ), None )
371370
372- # fixture components ---------------------------------------------
373-
374- def _body_bldr (self , p_count = 0 , tbl_bldr = None , sectPr = False ):
375- body_bldr = a_body ().with_nsdecls ()
376- for i in range (p_count ):
377- body_bldr .with_child (a_p ())
378- if tbl_bldr is not None :
379- body_bldr .with_child (tbl_bldr )
380- if sectPr :
381- body_bldr .with_child (a_sectPr ())
382- return body_bldr
383-
384- def _tbl_bldr (self , rows = 1 , cols = 1 ):
385- tblPr_bldr = (
386- a_tblPr ().with_child (
387- a_tblW ().with_type ("auto" ).with_w (0 ))
388- )
389-
390- tblGrid_bldr = a_tblGrid ()
391- for i in range (cols ):
392- tblGrid_bldr .with_child (a_gridCol ())
393-
394- tbl_bldr = a_tbl ()
395- tbl_bldr .with_child (tblPr_bldr )
396- tbl_bldr .with_child (tblGrid_bldr )
397- for i in range (rows ):
398- tr_bldr = self ._tr_bldr (cols )
399- tbl_bldr .with_child (tr_bldr )
400-
401- return tbl_bldr
402-
403- def _tc_bldr (self ):
404- return a_tc ().with_child (a_p ())
405-
406- def _tr_bldr (self , cols ):
407- tr_bldr = a_tr ()
408- for i in range (cols ):
409- tc_bldr = self ._tc_bldr ()
410- tr_bldr .with_child (tc_bldr )
411- return tr_bldr
412-
413371
414372class DescribeInlineShapes (object ):
415373
0 commit comments