1818from docx .parts .numbering import NumberingPart
1919from docx .parts .styles import StylesPart
2020from docx .section import Section
21+ from docx .shape import InlineShape
2122from docx .table import Table
2223from docx .text import Paragraph , Run
2324
2425from .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
2627)
2728
2829
@@ -90,12 +91,11 @@ def it_can_add_a_page_break(self, add_page_break_fixture):
9091 assert paragraph is paragraph_
9192
9293 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 )
9999 assert picture is picture_
100100
101101 def it_can_add_a_section (self , add_section_fixture ):
@@ -195,23 +195,14 @@ def add_page_break_fixture(
195195 self , document , document_part_ , paragraph_ , run_ ):
196196 return document , document_part_ , paragraph_ , run_
197197
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_ ):
207200 document = Document ()
208201 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_ )
215206
216207 @pytest .fixture
217208 def add_section_fixture (self , document , start_type_ , section_ ):
@@ -330,12 +321,6 @@ def open_(self, request, document_part_, package_):
330321 return_value = (document_part_ , package_ )
331322 )
332323
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-
339324 @pytest .fixture
340325 def Package_ (self , request , package_ ):
341326 Package_ = class_mock (request , 'docx.api.Package' )
@@ -348,10 +333,20 @@ def package_(self, request, document_part_):
348333 package_ .main_document = document_part_
349334 return package_
350335
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+
351342 @pytest .fixture
352343 def paragraphs_ (self , request ):
353344 return instance_mock (request , list )
354345
346+ @pytest .fixture
347+ def picture_ (self , request ):
348+ return instance_mock (request , InlineShape )
349+
355350 @pytest .fixture
356351 def run_ (self , request ):
357352 return instance_mock (request , Run )
0 commit comments