88 absolute_import , division , print_function , unicode_literals
99)
1010
11+ from docx .enum .style import WD_STYLE_TYPE
1112from docx .enum .text import WD_BREAK , WD_UNDERLINE
12- from docx .parts .document import InlineShapes
13+ from docx .parts .document import DocumentPart , InlineShapes
1314from docx .shape import InlineShape
1415from docx .shared import Pt
1516from docx .text .paragraph import Paragraph
1819import pytest
1920
2021from ..unitutil .cxml import element , xml
21- from ..unitutil .mock import class_mock , instance_mock
22+ from ..unitutil .mock import class_mock , instance_mock , property_mock
2223
2324
2425class DescribeRun (object ):
@@ -33,8 +34,12 @@ def it_can_change_its_bool_prop_settings(self, bool_prop_set_fixture):
3334 assert run ._r .xml == expected_xml
3435
3536 def it_knows_its_character_style (self , style_get_fixture ):
36- run , expected_style = style_get_fixture
37- assert run .style == expected_style
37+ run , style_id_ , style_ = style_get_fixture
38+ style = run .style
39+ run .part .get_style .assert_called_once_with (
40+ style_id_ , WD_STYLE_TYPE .CHARACTER
41+ )
42+ assert style is style_
3843
3944 def it_can_change_its_character_style (self , style_set_fixture ):
4045 run , style , expected_xml = style_set_fixture
@@ -220,14 +225,13 @@ def font_fixture(self, Font_, font_):
220225 run = Run (element ('w:r' ), None )
221226 return run , Font_ , font_
222227
223- @pytest .fixture (params = [
224- ('w:r' , None ),
225- ('w:r/w:rPr/w:rStyle{w:val=Foobar}' , 'Foobar' ),
226- ])
227- def style_get_fixture (self , request ):
228- r_cxml , expected_style = request .param
228+ @pytest .fixture
229+ def style_get_fixture (self , part_prop_ ):
230+ style_id = 'Barfoo'
231+ r_cxml = 'w:r/w:rPr/w:rStyle{w:val=%s}' % style_id
229232 run = Run (element (r_cxml ), None )
230- return run , expected_style
233+ style_ = part_prop_ .return_value .get_style .return_value
234+ return run , style_id , style_
231235
232236 @pytest .fixture (params = [
233237 ('w:r' , None ,
@@ -313,6 +317,10 @@ def underline_raise_fixture(self, request):
313317
314318 # fixture components ---------------------------------------------
315319
320+ @pytest .fixture
321+ def document_part_ (self , request ):
322+ return instance_mock (request , DocumentPart )
323+
316324 @pytest .fixture
317325 def Font_ (self , request , font_ ):
318326 return class_mock (request , 'docx.text.run.Font' , return_value = font_ )
@@ -331,6 +339,12 @@ def inline_shapes_(self, request, picture_):
331339 def paragraph_ (self , request ):
332340 return instance_mock (request , Paragraph )
333341
342+ @pytest .fixture
343+ def part_prop_ (self , request , document_part_ ):
344+ return property_mock (
345+ request , Run , 'part' , return_value = document_part_
346+ )
347+
334348 @pytest .fixture
335349 def picture_ (self , request ):
336350 return instance_mock (request , InlineShape )
0 commit comments