15
15
from docx .enum .text import WD_BREAK
16
16
from docx .opc .coreprops import CoreProperties
17
17
from docx .parts .document import DocumentPart
18
- from docx .section import Sections
18
+ from docx .section import Section , Sections
19
19
from docx .shape import InlineShape , InlineShapes
20
+ from docx .shared import Length
20
21
from docx .styles .styles import Styles
21
22
from docx .table import Table
22
23
from docx .text .paragraph import Paragraph
@@ -75,9 +76,9 @@ def it_can_add_a_section(self, add_section_fixture):
75
76
assert section is section_
76
77
77
78
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
79
80
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 )
81
82
assert table == table_
82
83
assert table .style == style
83
84
@@ -125,6 +126,12 @@ def it_provides_access_to_the_document_body(self, body_fixture):
125
126
_Body_ .assert_called_once_with (body_elm , document )
126
127
assert body is body_
127
128
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
+
128
135
# fixtures -------------------------------------------------------
129
136
130
137
@pytest .fixture (params = [
@@ -186,11 +193,22 @@ def add_section_fixture(self, request, Section_):
186
193
return document , start_type , Section_ , section_ , expected_xml
187
194
188
195
@pytest .fixture
189
- def add_table_fixture (self , body_prop_ , table_ ):
196
+ def add_table_fixture (self , _block_width_prop_ , body_prop_ , table_ ):
190
197
document = Document (None , None )
191
198
rows , cols , style = 4 , 2 , 'Light Shading Accent 1'
192
199
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
194
212
195
213
@pytest .fixture
196
214
def body_fixture (self , _Body_ , body_ ):
@@ -261,6 +279,10 @@ def _Body_(self, request, body_):
261
279
def body_ (self , request ):
262
280
return instance_mock (request , _Body )
263
281
282
+ @pytest .fixture
283
+ def _block_width_prop_ (self , request ):
284
+ return property_mock (request , Document , '_block_width' )
285
+
264
286
@pytest .fixture
265
287
def body_prop_ (self , request , body_ ):
266
288
return property_mock (request , Document , '_body' , return_value = body_ )
@@ -297,6 +319,10 @@ def run_(self, request):
297
319
def Section_ (self , request ):
298
320
return class_mock (request , 'docx.document.Section' )
299
321
322
+ @pytest .fixture
323
+ def section_ (self , request ):
324
+ return instance_mock (request , Section )
325
+
300
326
@pytest .fixture
301
327
def Sections_ (self , request ):
302
328
return class_mock (request , 'docx.document.Sections' )
@@ -305,6 +331,10 @@ def Sections_(self, request):
305
331
def sections_ (self , request ):
306
332
return instance_mock (request , Sections )
307
333
334
+ @pytest .fixture
335
+ def sections_prop_ (self , request ):
336
+ return property_mock (request , Document , 'sections' )
337
+
308
338
@pytest .fixture
309
339
def styles_ (self , request ):
310
340
return instance_mock (request , Styles )
0 commit comments