1010
1111from mock import Mock
1212
13+ from docx .oxml .parts import CT_Document
1314from docx .parts import _Body , _Document
1415from docx .table import Table
1516from docx .text import Paragraph
2021)
2122from .oxml .unitdata .text import a_p , a_sectPr
2223from .unitutil import (
23- function_mock , class_mock , initializer_mock
24+ function_mock , class_mock , initializer_mock , instance_mock
2425)
2526
2627
@@ -50,17 +51,27 @@ def it_has_a_body(self, document_body_fixture):
5051 _Body_ .assert_called_once_with (body_elm )
5152 assert _body is _Body_ .return_value
5253
53- def it_can_serialize_to_xml (self , serialize_part_xml_ ):
54- # mockery ----------------------
55- doc = _Document (None , None , None , None )
56- doc ._element = Mock (name = '_element' )
57- # exercise ---------------------
58- doc .blob
59- # verify -----------------------
60- serialize_part_xml_ .assert_called_once_with (doc ._element )
54+ def it_can_serialize_to_xml (self , document_blob_fixture ):
55+ document , document_elm , serialize_part_xml_ = document_blob_fixture
56+ blob = document .blob
57+ serialize_part_xml_ .assert_called_once_with (document_elm )
58+ assert blob is serialize_part_xml_ .return_value
59+
60+ def it_provides_access_to_the_inline_shapes_in_the_document (
61+ self , inline_shapes_fixture ):
62+ document , InlineShapes_ , body_elm = inline_shapes_fixture
63+ inline_shapes = document .inline_shapes
64+ InlineShapes_ .assert_called_once_with (body_elm )
65+ assert inline_shapes is InlineShapes_ .return_value
6166
6267 # fixtures -------------------------------------------------------
6368
69+ @pytest .fixture
70+ def document_blob_fixture (self , request , serialize_part_xml_ ):
71+ document_elm = instance_mock (request , CT_Document )
72+ document = _Document (None , None , document_elm , None )
73+ return document , document_elm , serialize_part_xml_
74+
6475 @pytest .fixture
6576 def document_body_fixture (self , request , _Body_ ):
6677 document_elm = (
@@ -79,6 +90,20 @@ def _Body_(self, request):
7990 def init (self , request ):
8091 return initializer_mock (request , _Document )
8192
93+ @pytest .fixture
94+ def InlineShapes_ (self , request ):
95+ return class_mock (request , 'docx.parts.InlineShapes' )
96+
97+ @pytest .fixture
98+ def inline_shapes_fixture (self , request , InlineShapes_ ):
99+ document_elm = (
100+ a_document ().with_nsdecls ().with_child (
101+ a_body ())
102+ ).element
103+ body_elm = document_elm [0 ]
104+ document = _Document (None , None , document_elm , None )
105+ return document , InlineShapes_ , body_elm
106+
82107 @pytest .fixture
83108 def oxml_fromstring_ (self , request ):
84109 return function_mock (request , 'docx.parts.oxml_fromstring' )
0 commit comments