@@ -21,17 +21,10 @@ def given_a_run(context):
2121 context .run = p .add_run ()
2222
2323
24- @given ('a run having bold set on' )
25- def given_a_run_having_bold_set_on (context ):
24+ @given ('a run having {bool_prop_name} set on' )
25+ def given_a_run_having_bool_prop_set_on (context , bool_prop_name ):
2626 run = Document ().add_paragraph ().add_run ()
27- run .bold = True
28- context .run = run
29-
30-
31- @given ('a run having italic set on' )
32- def given_a_run_having_italic_set_on (context ):
33- run = Document ().add_paragraph ().add_run ()
34- run .italic = True
27+ setattr (run , bool_prop_name , True )
3528 context .run = run
3629
3730
@@ -55,18 +48,11 @@ def when_add_page_break(context):
5548 run .add_break (WD_BREAK .PAGE )
5649
5750
58- @when ('I assign {value_str} to its bold property' )
59- def when_assign_true_to_its_bold_property (context , value_str ):
51+ @when ('I assign {value_str} to its {bool_prop_name} property' )
52+ def when_assign_true_to_bool_run_prop (context , value_str , bool_prop_name ):
6053 value = {'True' : True , 'False' : False , 'None' : None }[value_str ]
6154 run = context .run
62- run .bold = value
63-
64-
65- @when ('I assign {value_str} to its italic property' )
66- def when_assign_true_to_its_italic_property (context , value_str ):
67- value = {'True' : True , 'False' : False , 'None' : None }[value_str ]
68- run = context .run
69- run .italic = value
55+ setattr (run , bool_prop_name , value )
7056
7157
7258# then =====================================================
@@ -99,37 +85,19 @@ def then_last_item_in_run_is_a_break(context):
9985 assert context .last_child .tag == expected_tag
10086
10187
102- @then ('the run appears in bold typeface' )
103- def then_run_appears_in_bold_typeface (context ):
104- run = context .run
105- assert run .bold is True
106-
107-
108- @then ('the run appears in italic typeface' )
109- def then_run_appears_in_italic_typeface (context ):
110- run = context .run
111- assert run .italic is True
112-
113-
114- @then ('the run appears with its inherited bold setting' )
115- def then_run_appears_with_its_inherited_bold_setting (context ):
116- run = context .run
117- assert run .bold is None
118-
119-
120- @then ('the run appears with its inherited italic setting' )
121- def then_run_appears_with_its_inherited_italic_setting (context ):
88+ @then ('the run appears in {boolean_prop_name} unconditionally' )
89+ def then_run_appears_in_boolean_prop_name (context , boolean_prop_name ):
12290 run = context .run
123- assert run . italic is None
91+ assert getattr ( run , boolean_prop_name ) is True
12492
12593
126- @then ('the run appears without bold regardless of its style hierarchy ' )
127- def then_run_appears_without_bold_regardless (context ):
94+ @then ('the run appears with its inherited {boolean_prop_name} setting ' )
95+ def then_run_inherits_bool_prop_value (context , boolean_prop_name ):
12896 run = context .run
129- assert run . bold is False
97+ assert getattr ( run , boolean_prop_name ) is None
13098
13199
132- @then ('the run appears without italic regardless of its style hierarchy ' )
133- def then_run_appears_without_italic_regardless (context ):
100+ @then ('the run appears without {boolean_prop_name} unconditionally ' )
101+ def then_run_appears_without_bool_prop (context , boolean_prop_name ):
134102 run = context .run
135- assert run . italic is False
103+ assert getattr ( run , boolean_prop_name ) is False
0 commit comments