@@ -139,6 +139,11 @@ def it_knows_its_character_style(self, style_get_fixture):
139139 run , expected_style = style_get_fixture
140140 assert run .style == expected_style
141141
142+ def it_can_change_its_character_style (self , style_set_fixture ):
143+ run , style , expected_xml = style_set_fixture
144+ run .style = style
145+ assert run ._r .xml == expected_xml
146+
142147 def it_can_add_text (self , add_text_fixture ):
143148 run , text_str , expected_xml , Text_ = add_text_fixture
144149 _text = run .add_text (text_str )
@@ -313,16 +318,24 @@ def bool_prop_set_fixture(self, request):
313318 @pytest .fixture (params = ['Foobar' , None ])
314319 def style_get_fixture (self , request ):
315320 style = request .param
316- r_bldr = an_r ().with_nsdecls ()
317- if style is not None :
318- r_bldr .with_child (
319- an_rPr ().with_child (
320- an_rStyle ().with_val (style ))
321- )
322- r = r_bldr .element
321+ r = self .r_bldr_with_style (style ).element
323322 run = Run (r )
324323 return run , style
325324
325+ @pytest .fixture (params = [
326+ (None , None ),
327+ (None , 'Foobar' ),
328+ ('Foobar' , None ),
329+ ('Foobar' , 'Foobar' ),
330+ ('Foobar' , 'Barfoo' ),
331+ ])
332+ def style_set_fixture (self , request ):
333+ before_style , after_style = request .param
334+ r = self .r_bldr_with_style (before_style ).element
335+ run = Run (r )
336+ expected_xml = self .r_bldr_with_style (after_style ).xml ()
337+ return run , after_style , expected_xml
338+
326339 @pytest .fixture
327340 def text_prop_fixture (self , Text_ ):
328341 r = (
@@ -340,6 +353,13 @@ def run(self):
340353 r = an_r ().with_nsdecls ().element
341354 return Run (r )
342355
356+ def r_bldr_with_style (self , style ):
357+ rPr_bldr = an_rPr ()
358+ if style is not None :
359+ rPr_bldr .with_child (an_rStyle ().with_val (style ))
360+ r_bldr = an_r ().with_nsdecls ().with_child (rPr_bldr )
361+ return r_bldr
362+
343363 @pytest .fixture
344364 def Text_ (self , request ):
345365 return class_mock (request , 'docx.text.Text' )
0 commit comments