1515from docx .enum .text import WD_BREAK
1616from docx .parts .document import DocumentPart
1717from docx .shape import InlineShape
18+ from docx .table import Table
1819from docx .text .paragraph import Paragraph
1920from docx .text .run import Run
2021
@@ -70,6 +71,13 @@ def it_can_add_a_section(self, add_section_fixture):
7071 Section_ .assert_called_once_with (sectPr )
7172 assert section is section_
7273
74+ def it_can_add_a_table (self , add_table_fixture ):
75+ document , rows , cols , style , table_ = add_table_fixture
76+ table = document .add_table (rows , cols , style )
77+ document ._body .add_table .assert_called_once_with (rows , cols )
78+ assert table == table_
79+ assert table .style == style
80+
7381 def it_provides_access_to_the_document_part (self , part_fixture ):
7482 document , part_ = part_fixture
7583 assert document .part is part_
@@ -140,6 +148,13 @@ def add_section_fixture(self, request, Section_):
140148 section_ = Section_ .return_value
141149 return document , start_type , Section_ , section_ , expected_xml
142150
151+ @pytest .fixture
152+ def add_table_fixture (self , body_prop_ , table_ ):
153+ document = Document (None , None )
154+ rows , cols , style = 4 , 2 , 'Light Shading Accent 1'
155+ body_prop_ .return_value .add_table .return_value = table_
156+ return document , rows , cols , style , table_
157+
143158 @pytest .fixture
144159 def body_fixture (self , _Body_ , body_ ):
145160 document_elm = element ('w:document/w:body' )
@@ -167,8 +182,8 @@ def body_(self, request):
167182 return instance_mock (request , _Body )
168183
169184 @pytest .fixture
170- def body_prop_ (self , request ):
171- return property_mock (request , Document , '_body' )
185+ def body_prop_ (self , request , body_ ):
186+ return property_mock (request , Document , '_body' , return_value = body_ )
172187
173188 @pytest .fixture
174189 def document_part_ (self , request ):
@@ -189,3 +204,7 @@ def run_(self, request):
189204 @pytest .fixture
190205 def Section_ (self , request ):
191206 return class_mock (request , 'docx.document.Section' )
207+
208+ @pytest .fixture
209+ def table_ (self , request ):
210+ return instance_mock (request , Table , style = 'UNASSIGNED' )
0 commit comments