@@ -173,12 +173,14 @@ def given_a_run_having_underline_type(context, underline_type):
173173 context .run = document .paragraphs [0 ].runs [run_idx ]
174174
175175
176- @given ('a run having style {char_style} ' )
177- def given_a_run_having_style_char_style (context , char_style ):
176+ @given ('a run having {style} style ' )
177+ def given_a_run_having_style (context , style ):
178178 run_idx = {
179- 'None' : 0 , 'Emphasis' : 1 , 'Strong' : 2
180- }[char_style ]
181- document = Document (test_docx ('run-char-style' ))
179+ 'no explicit' : 0 ,
180+ 'Emphasis' : 1 ,
181+ 'Strong' : 2 ,
182+ }[style ]
183+ context .document = document = Document (test_docx ('run-char-style' ))
182184 context .run = document .paragraphs [0 ].runs [run_idx ]
183185
184186
@@ -361,19 +363,23 @@ def when_assign_true_to_bool_run_prop(context, value_str, bool_prop_name):
361363 setattr (run , bool_prop_name , value )
362364
363365
366+ @when ('I assign {value} to run.style' )
367+ def when_I_assign_value_to_run_style (context , value ):
368+ if value == 'None' :
369+ new_value = None
370+ elif value .startswith ('styles[' ):
371+ new_value = context .document .styles [value .split ('\' ' )[1 ]]
372+ else :
373+ new_value = context .document .styles [value ]
374+
375+ context .run .style = new_value
376+
377+
364378@when ('I clear the run' )
365379def when_I_clear_the_run (context ):
366380 context .run .clear ()
367381
368382
369- @when ('I set the character style of the run to {char_style}' )
370- def when_I_set_the_character_style_of_the_run (context , char_style ):
371- style_value = {
372- 'None' : None , 'Emphasis' : 'Emphasis' , 'Strong' : 'Strong'
373- }[char_style ]
374- context .run .style = style_value
375-
376-
377383@when ('I set the run underline to {underline_value}' )
378384def when_I_set_the_run_underline_to_value (context , underline_value ):
379385 new_value = {
@@ -521,6 +527,13 @@ def then_run_font_is_the_Font_object_for_the_run(context):
521527 assert font .element is run .element
522528
523529
530+ @then ('run.style is styles[\' {style_name}\' ]' )
531+ def then_run_style_is_style (context , style_name ):
532+ expected_value = context .document .styles [style_name ]
533+ run = context .run
534+ assert run .style == expected_value , 'got %s' % run .style
535+
536+
524537@then ('the last item in the run is a break' )
525538def then_last_item_in_run_is_a_break (context ):
526539 run = context .run
@@ -591,14 +604,6 @@ def then_the_run_underline_property_value_is(context, underline_value):
591604 assert context .run .underline == expected_value
592605
593606
594- @then ('the style of the run is {char_style}' )
595- def then_the_style_of_the_run_is_char_style (context , char_style ):
596- expected_value = {
597- 'None' : None , 'Emphasis' : 'Emphasis' , 'Strong' : 'Strong'
598- }[char_style ]
599- assert context .run .style == expected_value
600-
601-
602607@then ('the tab appears at the end of the run' )
603608def then_the_tab_appears_at_the_end_of_the_run (context ):
604609 r = context .run ._r
0 commit comments