88
99from docx import Document
1010
11- from helpers import test_docx
11+ from helpers import test_docx , test_file
1212
1313
1414# given ====================================================
@@ -27,6 +27,18 @@ def given_a_Header_object_with_or_no_header_definition(context, with_or_no):
2727 context .header = context .sections [section_idx ].header
2828
2929
30+ @given ("a _Run object from a footer as run" )
31+ def given_a_Run_object_from_a_footer_as_run (context ):
32+ footer = Document (test_docx ("hdr-header-footer" )).sections [0 ].footer
33+ context .run = footer .paragraphs [0 ].add_run ()
34+
35+
36+ @given ("a _Run object from a header as run" )
37+ def given_a_Run_object_from_a_header_as_run (context ):
38+ header = Document (test_docx ("hdr-header-footer" )).sections [0 ].header
39+ context .run = header .paragraphs [0 ].add_run ()
40+
41+
3042@given ("the next _Footer object with no footer definition as footer_2" )
3143def given_the_next_Footer_object_with_no_footer_definition (context ):
3244 context .footer_2 = context .sections [1 ].footer
@@ -39,6 +51,16 @@ def given_the_next_Header_object_with_no_header_definition(context):
3951
4052# when =====================================================
4153
54+ @when ("I assign \" Normal\" to footer.paragraphs[0].style" )
55+ def when_I_assign_Body_Text_to_footer_style (context ):
56+ context .footer .paragraphs [0 ].style = "Normal"
57+
58+
59+ @when ("I assign \" Normal\" to header.paragraphs[0].style" )
60+ def when_I_assign_Body_Text_to_header_style (context ):
61+ context .header .paragraphs [0 ].style = "Normal"
62+
63+
4264@when ("I assign {value} to header.is_linked_to_previous" )
4365def when_I_assign_value_to_header_is_linked_to_previous (context , value ):
4466 context .header .is_linked_to_previous = eval (value )
@@ -49,6 +71,11 @@ def when_I_assign_value_to_footer_is_linked_to_previous(context, value):
4971 context .footer .is_linked_to_previous = eval (value )
5072
5173
74+ @when ("I call run.add_picture()" )
75+ def when_I_call_run_add_picture (context ):
76+ context .run .add_picture (test_file ("test.png" ))
77+
78+
5279# then =====================================================
5380
5481@then ("footer.is_linked_to_previous is {value}" )
@@ -58,11 +85,11 @@ def then_footer_is_linked_to_previous_is_value(context, value):
5885 assert actual == expected , "footer.is_linked_to_previous is %s" % actual
5986
6087
61- @then ("footer_2 .paragraphs[0].text == footer.paragraphs[0].text " )
62- def then_footer_2_text_eq_footer_text (context ):
63- actual = context .footer_2 .paragraphs [0 ].text
64- expected = context . footer . paragraphs [ 0 ]. text
65- assert actual == expected , "footer_2 .paragraphs[0].text == %s" % actual
88+ @then ("footer .paragraphs[0].style.name == \" Normal \" " )
89+ def then_footer_paragraphs_0_style_name_eq_Normal (context ):
90+ actual = context .footer .paragraphs [0 ].style . name
91+ expected = "Normal"
92+ assert actual == expected , "footer .paragraphs[0].style.name is %s" % actual
6693
6794
6895@then ("footer_2.is_linked_to_previous is {value}" )
@@ -72,13 +99,27 @@ def then_footer_2_is_linked_to_previous_is_value(context, value):
7299 assert actual == expected , "footer_2.is_linked_to_previous is %s" % actual
73100
74101
102+ @then ("footer_2.paragraphs[0].text == footer.paragraphs[0].text" )
103+ def then_footer_2_text_eq_footer_text (context ):
104+ actual = context .footer_2 .paragraphs [0 ].text
105+ expected = context .footer .paragraphs [0 ].text
106+ assert actual == expected , "footer_2.paragraphs[0].text == %s" % actual
107+
108+
75109@then ("header.is_linked_to_previous is {value}" )
76110def then_header_is_linked_to_previous_is_value (context , value ):
77111 actual = context .header .is_linked_to_previous
78112 expected = eval (value )
79113 assert actual == expected , "header.is_linked_to_previous is %s" % actual
80114
81115
116+ @then ("header.paragraphs[0].style.name == \" Normal\" " )
117+ def then_header_paragraphs_0_style_name_eq_Normal (context ):
118+ actual = context .header .paragraphs [0 ].style .name
119+ expected = "Normal"
120+ assert actual == expected , "header.paragraphs[0].style.name is %s" % actual
121+
122+
82123@then ("header_2.is_linked_to_previous is {value}" )
83124def then_header_2_is_linked_to_previous_is_value (context , value ):
84125 actual = context .header_2 .is_linked_to_previous
@@ -91,3 +132,8 @@ def then_header_2_text_eq_header_text(context):
91132 actual = context .header_2 .paragraphs [0 ].text
92133 expected = context .header .paragraphs [0 ].text
93134 assert actual == expected , "header_2.paragraphs[0].text == %s" % actual
135+
136+
137+ @then ("I can't detect the image but no exception is raised" )
138+ def then_I_cant_detect_the_image_but_no_exception_is_raised (context ):
139+ pass
0 commit comments