18
18
from docx .parts .numbering import NumberingPart
19
19
from docx .parts .styles import StylesPart
20
20
from docx .section import Section
21
+ from docx .shape import InlineShape
21
22
from docx .table import Table
22
23
from docx .text import Paragraph , Run
23
24
24
25
from .unitutil .mock import (
25
- ANY , instance_mock , class_mock , method_mock , property_mock , var_mock
26
+ instance_mock , class_mock , method_mock , property_mock , var_mock
26
27
)
27
28
28
29
@@ -90,12 +91,11 @@ def it_can_add_a_page_break(self, add_page_break_fixture):
90
91
assert paragraph is paragraph_
91
92
92
93
def it_can_add_a_picture (self , add_picture_fixture ):
93
- (document , image_path , width , height , inline_shapes_ , expected_width ,
94
- expected_height , picture_ ) = add_picture_fixture
95
- picture = document .add_picture (image_path , width , height )
96
- inline_shapes_ .add_picture .assert_called_once_with (image_path , ANY )
97
- assert picture .width == expected_width
98
- assert picture .height == expected_height
94
+ document , image_path_ , width , height , run_ , picture_ = (
95
+ add_picture_fixture
96
+ )
97
+ picture = document .add_picture (image_path_ , width , height )
98
+ run_ .add_picture .assert_called_once_with (image_path_ , width , height )
99
99
assert picture is picture_
100
100
101
101
def it_can_add_a_section (self , add_section_fixture ):
@@ -195,23 +195,14 @@ def add_page_break_fixture(
195
195
self , document , document_part_ , paragraph_ , run_ ):
196
196
return document , document_part_ , paragraph_ , run_
197
197
198
- @pytest .fixture (params = [
199
- (None , None , 200 , 100 ),
200
- (1000 , 500 , 1000 , 500 ),
201
- (2000 , None , 2000 , 1000 ),
202
- (None , 2000 , 4000 , 2000 ),
203
- ])
204
- def add_picture_fixture (
205
- self , request , Document_inline_shapes_ , inline_shapes_ ):
206
- width , height , expected_width , expected_height = request .param
198
+ @pytest .fixture
199
+ def add_picture_fixture (self , request , run_ , picture_ ):
207
200
document = Document ()
208
201
image_path_ = instance_mock (request , str , name = 'image_path_' )
209
- picture_ = inline_shapes_ .add_picture .return_value
210
- picture_ .width , picture_ .height = 200 , 100
211
- return (
212
- document , image_path_ , width , height , inline_shapes_ ,
213
- expected_width , expected_height , picture_
214
- )
202
+ width , height = 100 , 200
203
+ class_mock (request , 'docx.text.Run' , return_value = run_ )
204
+ run_ .add_picture .return_value = picture_
205
+ return (document , image_path_ , width , height , run_ , picture_ )
215
206
216
207
@pytest .fixture
217
208
def add_section_fixture (self , document , start_type_ , section_ ):
@@ -330,12 +321,6 @@ def open_(self, request, document_part_, package_):
330
321
return_value = (document_part_ , package_ )
331
322
)
332
323
333
- @pytest .fixture
334
- def paragraph_ (self , request , run_ ):
335
- paragraph_ = instance_mock (request , Paragraph )
336
- paragraph_ .add_run .return_value = run_
337
- return paragraph_
338
-
339
324
@pytest .fixture
340
325
def Package_ (self , request , package_ ):
341
326
Package_ = class_mock (request , 'docx.api.Package' )
@@ -348,10 +333,20 @@ def package_(self, request, document_part_):
348
333
package_ .main_document = document_part_
349
334
return package_
350
335
336
+ @pytest .fixture
337
+ def paragraph_ (self , request , run_ ):
338
+ paragraph_ = instance_mock (request , Paragraph )
339
+ paragraph_ .add_run .return_value = run_
340
+ return paragraph_
341
+
351
342
@pytest .fixture
352
343
def paragraphs_ (self , request ):
353
344
return instance_mock (request , list )
354
345
346
+ @pytest .fixture
347
+ def picture_ (self , request ):
348
+ return instance_mock (request , InlineShape )
349
+
355
350
@pytest .fixture
356
351
def run_ (self , request ):
357
352
return instance_mock (request , Run )
0 commit comments