8
8
absolute_import , division , print_function , unicode_literals
9
9
)
10
10
11
+ from docx .enum .style import WD_STYLE_TYPE
11
12
from docx .enum .text import WD_BREAK , WD_UNDERLINE
12
- from docx .parts .document import InlineShapes
13
+ from docx .parts .document import DocumentPart , InlineShapes
13
14
from docx .shape import InlineShape
14
15
from docx .shared import Pt
15
16
from docx .text .paragraph import Paragraph
18
19
import pytest
19
20
20
21
from ..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
22
23
23
24
24
25
class DescribeRun (object ):
@@ -33,8 +34,12 @@ def it_can_change_its_bool_prop_settings(self, bool_prop_set_fixture):
33
34
assert run ._r .xml == expected_xml
34
35
35
36
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_
38
43
39
44
def it_can_change_its_character_style (self , style_set_fixture ):
40
45
run , style , expected_xml = style_set_fixture
@@ -220,14 +225,13 @@ def font_fixture(self, Font_, font_):
220
225
run = Run (element ('w:r' ), None )
221
226
return run , Font_ , font_
222
227
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
229
232
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_
231
235
232
236
@pytest .fixture (params = [
233
237
('w:r' , None ,
@@ -313,6 +317,10 @@ def underline_raise_fixture(self, request):
313
317
314
318
# fixture components ---------------------------------------------
315
319
320
+ @pytest .fixture
321
+ def document_part_ (self , request ):
322
+ return instance_mock (request , DocumentPart )
323
+
316
324
@pytest .fixture
317
325
def Font_ (self , request , font_ ):
318
326
return class_mock (request , 'docx.text.run.Font' , return_value = font_ )
@@ -331,6 +339,12 @@ def inline_shapes_(self, request, picture_):
331
339
def paragraph_ (self , request ):
332
340
return instance_mock (request , Paragraph )
333
341
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
+
334
348
@pytest .fixture
335
349
def picture_ (self , request ):
336
350
return instance_mock (request , InlineShape )
0 commit comments