|
15 | 15 | from docx.package import ImageParts, Package |
16 | 16 | from docx.parts.document import _Body, DocumentPart, InlineShapes, Sections |
17 | 17 | from docx.parts.image import ImagePart |
| 18 | +from docx.parts.numbering import NumberingPart |
18 | 19 | from docx.parts.styles import StylesPart |
19 | 20 | from docx.section import Section |
20 | 21 | from docx.shape import InlineShape |
@@ -74,6 +75,21 @@ def it_provides_access_to_the_inline_shapes_in_the_document( |
74 | 75 | InlineShapes_.assert_called_once_with(body_elm, document) |
75 | 76 | assert inline_shapes is InlineShapes_.return_value |
76 | 77 |
|
| 78 | + def it_provides_access_to_the_numbering_part(self, nmprt_get_fixture): |
| 79 | + document_part, numbering_part_ = nmprt_get_fixture |
| 80 | + numbering_part = document_part.numbering_part |
| 81 | + document_part.part_related_by.assert_called_once_with(RT.NUMBERING) |
| 82 | + assert numbering_part is numbering_part_ |
| 83 | + |
| 84 | + def it_creates_numbering_part_if_not_present(self, nmprt_create_fixture): |
| 85 | + document_part, NumberingPart_, numbering_part_ = nmprt_create_fixture |
| 86 | + numbering_part = document_part.numbering_part |
| 87 | + NumberingPart_.new.assert_called_once_with() |
| 88 | + document_part.relate_to.assert_called_once_with( |
| 89 | + numbering_part_, RT.NUMBERING |
| 90 | + ) |
| 91 | + assert numbering_part is numbering_part_ |
| 92 | + |
77 | 93 | def it_can_add_an_image_part_to_the_document( |
78 | 94 | self, get_or_add_image_fixture): |
79 | 95 | (document, image_descriptor_, image_parts_, relate_to_, image_part_, |
@@ -182,6 +198,20 @@ def next_id_fixture(self, request): |
182 | 198 | document = DocumentPart(None, None, document_elm, None) |
183 | 199 | return document, expected_id |
184 | 200 |
|
| 201 | + @pytest.fixture |
| 202 | + def nmprt_create_fixture(self, part_related_by_, relate_to_, |
| 203 | + NumberingPart_, numbering_part_): |
| 204 | + document_part = DocumentPart(None, None, None, None) |
| 205 | + part_related_by_.side_effect = KeyError |
| 206 | + NumberingPart_.new.return_value = numbering_part_ |
| 207 | + return document_part, NumberingPart_, numbering_part_ |
| 208 | + |
| 209 | + @pytest.fixture |
| 210 | + def nmprt_get_fixture(self, part_related_by_, numbering_part_): |
| 211 | + document_part = DocumentPart(None, None, None, None) |
| 212 | + part_related_by_.return_value = numbering_part_ |
| 213 | + return document_part, numbering_part_ |
| 214 | + |
185 | 215 | @pytest.fixture |
186 | 216 | def paragraphs_fixture(self, document_part_body_, body_, paragraphs_): |
187 | 217 | document_part = DocumentPart(None, None, None, None) |
@@ -271,6 +301,14 @@ def image_parts_(self, request, image_part_): |
271 | 301 | def InlineShapes_(self, request): |
272 | 302 | return class_mock(request, 'docx.parts.document.InlineShapes') |
273 | 303 |
|
| 304 | + @pytest.fixture |
| 305 | + def NumberingPart_(self, request): |
| 306 | + return class_mock(request, 'docx.parts.document.NumberingPart') |
| 307 | + |
| 308 | + @pytest.fixture |
| 309 | + def numbering_part_(self, request): |
| 310 | + return instance_mock(request, NumberingPart) |
| 311 | + |
274 | 312 | @pytest.fixture |
275 | 313 | def p_(self, request): |
276 | 314 | return instance_mock(request, Paragraph) |
|
0 commit comments