@@ -89,6 +89,10 @@ def it_provides_access_to_the_inline_shapes_in_the_document(
8989 def it_knows_it_is_the_part_its_child_objects_belong_to (self , document ):
9090 assert document .part is document
9191
92+ def it_knows_the_next_available_xml_id (self , next_id_fixture ):
93+ document , expected_id = next_id_fixture
94+ assert document .next_id == expected_id
95+
9296 # fixtures -------------------------------------------------------
9397
9498 @pytest .fixture
@@ -157,6 +161,20 @@ def inline_shapes_fixture(self, request, InlineShapes_):
157161 document = _Document (None , None , document_elm , None )
158162 return document , InlineShapes_ , body_elm
159163
164+ @pytest .fixture (params = [
165+ ((), 1 ), ((1 ,), 2 ), ((2 ,), 1 ), ((1 , 2 , 3 ), 4 ), ((1 , 2 , 4 ), 3 ),
166+ ((0 , 0 ), 1 ), ((0 , 0 , 1 , 3 ), 2 ),
167+ ])
168+ def next_id_fixture (self , request ):
169+ existing_ids , expected_id = request .param
170+ document_elm = a_document ().with_nsdecls ().element
171+ for n in existing_ids :
172+ p = a_p ().with_nsdecls ().element
173+ p .set ('id' , str (n ))
174+ document_elm .append (p )
175+ document = _Document (None , None , document_elm , None )
176+ return document , expected_id
177+
160178 @pytest .fixture
161179 def oxml_fromstring_ (self , request ):
162180 return function_mock (request , 'docx.parts.document.oxml_fromstring' )
0 commit comments