Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e52d32f

Browse files
committed
acpt: add header /footer content insert scenarios
1 parent 0c90ce3 commit e52d32f

File tree

2 files changed

+80
-6
lines changed

2 files changed

+80
-6
lines changed

features/hdr-header-footer.feature

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ Feature: Header and footer behaviors
3434
And header_2.is_linked_to_previous is True
3535

3636

37+
@wip
38+
Scenario: _Header text accepts style assignment
39+
Given a _Header object with a header definition as header
40+
When I assign "Normal" to header.paragraphs[0].style
41+
Then header.paragraphs[0].style.name == "Normal"
42+
43+
44+
@wip
45+
Scenario: _Header allows image insertion
46+
Given a _Run object from a header as run
47+
When I call run.add_picture()
48+
Then I can't detect the image but no exception is raised
49+
50+
3751
Scenario Outline: _Footer.is_linked_to_previous getter
3852
Given a _Footer object <with-or-no> footer definition as footer
3953
Then footer.is_linked_to_previous is <value>
@@ -62,3 +76,17 @@ Feature: Header and footer behaviors
6276
And the next _Footer object with no footer definition as footer_2
6377
Then footer_2.paragraphs[0].text == footer.paragraphs[0].text
6478
And footer_2.is_linked_to_previous is True
79+
80+
81+
@wip
82+
Scenario: _Footer text accepts style assignment
83+
Given a _Footer object with a footer definition as footer
84+
When I assign "Normal" to footer.paragraphs[0].style
85+
Then footer.paragraphs[0].style.name == "Normal"
86+
87+
88+
@wip
89+
Scenario: _Footer allows image insertion
90+
Given a _Run object from a footer as run
91+
When I call run.add_picture()
92+
Then I can't detect the image but no exception is raised

features/steps/hdrftr.py

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from 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")
3143
def 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")
4365
def 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}")
76110
def 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}")
83124
def 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

Comments
 (0)