1515from docx .enum .text import WD_BREAK
1616from docx .opc .coreprops import CoreProperties
1717from docx .parts .document import DocumentPart
18- from docx .section import Sections
18+ from docx .section import Section , Sections
1919from docx .shape import InlineShape , InlineShapes
20+ from docx .shared import Length
2021from docx .styles .styles import Styles
2122from docx .table import Table
2223from docx .text .paragraph import Paragraph
@@ -75,9 +76,9 @@ def it_can_add_a_section(self, add_section_fixture):
7576 assert section is section_
7677
7778 def it_can_add_a_table (self , add_table_fixture ):
78- document , rows , cols , style , table_ = add_table_fixture
79+ document , rows , cols , style , width , table_ = add_table_fixture
7980 table = document .add_table (rows , cols , style )
80- document ._body .add_table .assert_called_once_with (rows , cols )
81+ document ._body .add_table .assert_called_once_with (rows , cols , width )
8182 assert table == table_
8283 assert table .style == style
8384
@@ -125,6 +126,12 @@ def it_provides_access_to_the_document_body(self, body_fixture):
125126 _Body_ .assert_called_once_with (body_elm , document )
126127 assert body is body_
127128
129+ def it_determines_block_width_to_help (self , block_width_fixture ):
130+ document , expected_value = block_width_fixture
131+ width = document ._block_width
132+ assert isinstance (width , Length )
133+ assert width == expected_value
134+
128135 # fixtures -------------------------------------------------------
129136
130137 @pytest .fixture (params = [
@@ -186,11 +193,22 @@ def add_section_fixture(self, request, Section_):
186193 return document , start_type , Section_ , section_ , expected_xml
187194
188195 @pytest .fixture
189- def add_table_fixture (self , body_prop_ , table_ ):
196+ def add_table_fixture (self , _block_width_prop_ , body_prop_ , table_ ):
190197 document = Document (None , None )
191198 rows , cols , style = 4 , 2 , 'Light Shading Accent 1'
192199 body_prop_ .return_value .add_table .return_value = table_
193- return document , rows , cols , style , table_
200+ _block_width_prop_ .return_value = width = 42
201+ return document , rows , cols , style , width , table_
202+
203+ @pytest .fixture
204+ def block_width_fixture (self , sections_prop_ , section_ ):
205+ document = Document (None , None )
206+ sections_prop_ .return_value = [None , section_ ]
207+ section_ .page_width = 6000
208+ section_ .left_margin = 1500
209+ section_ .right_margin = 1000
210+ expected_value = 3500
211+ return document , expected_value
194212
195213 @pytest .fixture
196214 def body_fixture (self , _Body_ , body_ ):
@@ -261,6 +279,10 @@ def _Body_(self, request, body_):
261279 def body_ (self , request ):
262280 return instance_mock (request , _Body )
263281
282+ @pytest .fixture
283+ def _block_width_prop_ (self , request ):
284+ return property_mock (request , Document , '_block_width' )
285+
264286 @pytest .fixture
265287 def body_prop_ (self , request , body_ ):
266288 return property_mock (request , Document , '_body' , return_value = body_ )
@@ -297,6 +319,10 @@ def run_(self, request):
297319 def Section_ (self , request ):
298320 return class_mock (request , 'docx.document.Section' )
299321
322+ @pytest .fixture
323+ def section_ (self , request ):
324+ return instance_mock (request , Section )
325+
300326 @pytest .fixture
301327 def Sections_ (self , request ):
302328 return class_mock (request , 'docx.document.Sections' )
@@ -305,6 +331,10 @@ def Sections_(self, request):
305331 def sections_ (self , request ):
306332 return instance_mock (request , Sections )
307333
334+ @pytest .fixture
335+ def sections_prop_ (self , request ):
336+ return property_mock (request , Document , 'sections' )
337+
308338 @pytest .fixture
309339 def styles_ (self , request ):
310340 return instance_mock (request , Styles )
0 commit comments