1414from docx .table import Table
1515from docx .text import Paragraph
1616
17- from .oxml .unitdata .parts import a_body
17+ from .oxml .unitdata .parts import a_body , a_document
1818from .oxml .unitdata .table import (
1919 a_gridCol , a_tbl , a_tblGrid , a_tblPr , a_tc , a_tr
2020)
2121from .oxml .unitdata .text import a_p , a_sectPr
22- from .unitutil import class_mock , function_mock , initializer_mock
22+ from .unitutil import (
23+ function_mock , class_mock , initializer_mock
24+ )
2325
2426
2527class Describe_Document (object ):
@@ -42,19 +44,15 @@ def it_can_be_constructed_by_opc_part_factory(
4244 )
4345 assert isinstance (doc , _Document )
4446
45- def it_has_a_body (self , init , _Body_ ):
46- # mockery ----------------------
47- doc = _Document (None , None , None )
48- doc ._element = Mock (name = '_element' )
49- # exercise ---------------------
50- body = doc .body
51- # verify -----------------------
52- _Body_ .assert_called_once_with (doc ._element .body )
53- assert body is _Body_ .return_value
47+ def it_has_a_body (self , document_body_fixture ):
48+ document , _Body_ , body_elm = document_body_fixture
49+ _body = document .body
50+ _Body_ .assert_called_once_with (body_elm )
51+ assert _body is _Body_ .return_value
5452
55- def it_can_serialize_to_xml (self , init , serialize_part_xml_ ):
53+ def it_can_serialize_to_xml (self , serialize_part_xml_ ):
5654 # mockery ----------------------
57- doc = _Document (None , None , None )
55+ doc = _Document (None , None , None , None )
5856 doc ._element = Mock (name = '_element' )
5957 # exercise ---------------------
6058 doc .blob
@@ -63,6 +61,16 @@ def it_can_serialize_to_xml(self, init, serialize_part_xml_):
6361
6462 # fixtures -------------------------------------------------------
6563
64+ @pytest .fixture
65+ def document_body_fixture (self , request , _Body_ ):
66+ document_elm = (
67+ a_document ().with_nsdecls ().with_child (
68+ a_body ())
69+ ).element
70+ body_elm = document_elm [0 ]
71+ document = _Document (None , None , document_elm , None )
72+ return document , _Body_ , body_elm
73+
6674 @pytest .fixture
6775 def _Body_ (self , request ):
6876 return class_mock (request , 'docx.parts._Body' )
0 commit comments