1010
1111import pytest
1212
13+ from docx .enum .style import WD_STYLE_TYPE
1314from docx .styles .style import BaseStyle
1415from docx .styles .styles import Styles
1516
@@ -52,11 +53,23 @@ def it_raises_on_style_not_found(self, get_raises_fixture):
5253 def it_can_get_a_style_of_type_by_id (self , get_by_id_fixture ):
5354 styles , style_id , style_type = get_by_id_fixture [:3 ]
5455 default_calls , _get_by_id_calls , style_ = get_by_id_fixture [3 :]
56+
5557 style = styles .get_by_id (style_id , style_type )
58+
5659 assert styles .default .call_args_list == default_calls
5760 assert styles ._get_by_id .call_args_list == _get_by_id_calls
5861 assert style is style_
5962
63+ def it_gets_a_style_by_id_to_help (self , _get_by_id_fixture ):
64+ styles , style_id , style_type , default_calls = _get_by_id_fixture [:4 ]
65+ StyleFactory_ , StyleFactory_calls , style_ = _get_by_id_fixture [4 :]
66+
67+ style = styles ._get_by_id (style_id , style_type )
68+
69+ assert styles .default .call_args_list == default_calls
70+ assert StyleFactory_ .call_args_list == StyleFactory_calls
71+ assert style is style_
72+
6073 # fixture --------------------------------------------------------
6174
6275 @pytest .fixture (params = [None , 'Foo' ])
@@ -73,6 +86,27 @@ def get_by_id_fixture(self, request, default_, _get_by_id_, style_):
7386 style_
7487 )
7588
89+ @pytest .fixture (params = [
90+ ('w:styles/w:style{w:type=paragraph,w:styleId=Foo}' , 'Foo' ,
91+ WD_STYLE_TYPE .PARAGRAPH ),
92+ ('w:styles/w:style{w:type=paragraph,w:styleId=Foo}' , 'Bar' ,
93+ WD_STYLE_TYPE .PARAGRAPH ),
94+ ('w:styles/w:style{w:type=table,w:styleId=Bar}' , 'Bar' ,
95+ WD_STYLE_TYPE .PARAGRAPH ),
96+ ])
97+ def _get_by_id_fixture (self , request , default_ , StyleFactory_ , style_ ):
98+ styles_cxml , style_id , style_type = request .param
99+ styles_elm = element (styles_cxml )
100+ style_elm = styles_elm [0 ]
101+ styles = Styles (styles_elm )
102+ default_calls = [] if style_id == 'Foo' else [call (style_type )]
103+ StyleFactory_calls = [call (style_elm )] if style_id == 'Foo' else []
104+ default_ .return_value = StyleFactory_ .return_value = style_
105+ return (
106+ styles , style_id , style_type , default_calls , StyleFactory_ ,
107+ StyleFactory_calls , style_
108+ )
109+
76110 @pytest .fixture (params = [
77111 ('w:styles/(w:style{%s,w:styleId=Foobar},w:style,w:style)' , 0 ),
78112 ('w:styles/(w:style,w:style{%s,w:styleId=Foobar},w:style)' , 1 ),
0 commit comments