1313from docx .parts .image import Image , ImagePart
1414
1515from .unitutil import (
16- docx_path , class_mock , instance_mock , method_mock , property_mock
16+ docx_path , class_mock , instance_mock , method_mock
1717)
1818
1919
@@ -39,6 +39,13 @@ def it_can_add_a_new_image_part(self, add_image_part_fixture):
3939 image_parts ._add_image_part .assert_called_once_with (image_ )
4040 assert image_part is image_part_
4141
42+ def it_knows_the_next_available_image_partname (
43+ self , next_partname_fixture ):
44+ image_parts , ext , expected_partname = next_partname_fixture
45+ assert image_parts ._next_image_partname (ext ) == expected_partname
46+ print ('\n %s' % image_parts ._next_image_partname (ext ))
47+ print (expected_partname )
48+
4249 def it_can_really_add_a_new_image_part (
4350 self , really_add_image_part_fixture ):
4451 image_parts , image_ , ImagePart_ , partname_ , image_part_ = (
@@ -99,13 +106,33 @@ def image_part_(self, request, sha1):
99106 image_part_ .sha1 = sha1
100107 return image_part_
101108
109+ def _image_part_with_partname_ (self , request , n ):
110+ partname = self ._image_partname (n )
111+ return instance_mock (request , ImagePart , partname = partname )
112+
113+ def _image_partname (self , n ):
114+ return PackURI ('/word/media/image%d.png' % n )
115+
102116 @pytest .fixture
103117 def new_image_part_ (self , request ):
104118 return instance_mock (request , ImagePart )
105119
106120 @pytest .fixture
107121 def _next_image_partname_ (self , request ):
108- return property_mock (request , ImageParts , '_next_image_partname' )
122+ return method_mock (request , ImageParts , '_next_image_partname' )
123+
124+ @pytest .fixture (params = [((2 , 3 ), 1 ), ((1 , 3 ), 2 ), ((1 , 2 ), 3 )])
125+ def next_partname_fixture (self , request ):
126+ existing_partname_numbers , expected_partname_number = request .param
127+ image_parts = ImageParts ()
128+ for n in existing_partname_numbers :
129+ image_part_ = self ._image_part_with_partname_ (request , n )
130+ image_parts .append (image_part_ )
131+ ext = '.png'
132+ expected_image_partname = self ._image_partname (
133+ expected_partname_number
134+ )
135+ return image_parts , ext , expected_image_partname
109136
110137 @pytest .fixture
111138 def partname_ (self , request ):
0 commit comments