Skip to content

Commit a93373a

Browse files
ondrej-111scanny
authored andcommitted
acpt: add scenarios for headers and footers
1 parent fd1d336 commit a93373a

File tree

5 files changed

+194
-0
lines changed

5 files changed

+194
-0
lines changed

features/hdr-header-footer.feature

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Feature: Header and footer behaviors
2+
In order to control the appearance of page headers and footers
3+
As a developer using python-docx
4+
I need properties and methods on _Header and _Footer objects
5+
6+
7+
@wip
8+
Scenario Outline: _Header.is_linked_to_previous getter
9+
Given a _Header object <with-or-no> header definition as header
10+
Then header.is_linked_to_previous is <value>
11+
12+
Examples: _Header.is_linked_to_previous states
13+
| with-or-no | value |
14+
| with a | False |
15+
| with no | True |
16+
17+
18+
@wip
19+
Scenario Outline: _Header.is_linked_to_previous setter
20+
Given a _Header object <with-or-no> header definition as header
21+
When I assign <value> to header.is_linked_to_previous
22+
Then header.is_linked_to_previous is <value>
23+
24+
Examples: _Header.is_linked_to_previous state changes
25+
| with-or-no | value |
26+
| with a | True |
27+
| with no | False |
28+
| with a | False |
29+
| with no | True |
30+
31+
32+
@wip
33+
Scenario: _Header inherits content
34+
Given a _Header object with a header definition as header
35+
And the next _Header object with no header definition as header_2
36+
Then header_2.paragraphs[0].text == header.paragraphs[0].text
37+
And header_2.is_linked_to_previous is True
38+
39+
40+
@wip
41+
Scenario Outline: _Footer.is_linked_to_previous getter
42+
Given a _Footer object <with-or-no> footer definition as footer
43+
Then footer.is_linked_to_previous is <value>
44+
45+
Examples: _Footer.is_linked_to_previous states
46+
| with-or-no | value |
47+
| with a | False |
48+
| with no | True |
49+
50+
51+
@wip
52+
Scenario Outline: _Footer.is_linked_to_previous setter
53+
Given a _Footer object <with-or-no> footer definition as footer
54+
When I assign <value> to footer.is_linked_to_previous
55+
Then footer.is_linked_to_previous is <value>
56+
57+
Examples: _Footer.is_linked_to_previous state changes
58+
| with-or-no | value |
59+
| with a | True |
60+
| with no | False |
61+
| with a | False |
62+
| with no | True |
63+
64+
65+
@wip
66+
Scenario: _Footer inherits content
67+
Given a _Footer object with a footer definition as footer
68+
And the next _Footer object with no footer definition as footer_2
69+
Then footer_2.paragraphs[0].text == footer.paragraphs[0].text
70+
And footer_2.is_linked_to_previous is True
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ Feature: Access and change section properties
44
I need a way to get and set the properties of a section
55

66

7+
@wip
8+
Scenario: Section.footer
9+
Given a Section object as section
10+
Then section.footer is a _Footer object
11+
12+
13+
@wip
14+
Scenario: Section.header
15+
Given a Section object as section
16+
Then section.header is a _Header object
17+
18+
719
Scenario Outline: Get section start type
820
Given a section having start type <start-type>
921
Then the reported section start type is <start-type>

features/steps/hdrftr.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# encoding: utf-8
2+
3+
"""Step implementations for header and footer-related features"""
4+
5+
from __future__ import absolute_import, division, print_function, unicode_literals
6+
7+
from behave import given, then, when
8+
9+
from docx import Document
10+
11+
from helpers import test_docx
12+
13+
14+
# given ====================================================
15+
16+
@given("a _Footer object {with_or_no} footer definition as footer")
17+
def given_a_Footer_object_with_or_no_footer_definition(context, with_or_no):
18+
section_idx = {"with a": 0, "with no": 1}[with_or_no]
19+
context.sections = Document(test_docx("hdr-header-footer")).sections
20+
context.footer = context.sections[section_idx].footer
21+
22+
23+
@given("a _Header object {with_or_no} header definition as header")
24+
def given_a_Header_object_with_or_no_header_definition(context, with_or_no):
25+
section_idx = {"with a": 0, "with no": 1}[with_or_no]
26+
context.sections = Document(test_docx("hdr-header-footer")).sections
27+
context.header = context.sections[section_idx].header
28+
29+
30+
@given("the next _Footer object with no footer definition as footer_2")
31+
def given_the_next_Footer_object_with_no_footer_definition(context):
32+
context.footer_2 = context.sections[1].footer
33+
34+
35+
@given("the next _Header object with no header definition as header_2")
36+
def given_the_next_Header_object_with_no_header_definition(context):
37+
context.header_2 = context.sections[1].header
38+
39+
40+
# when =====================================================
41+
42+
@when("I assign {value} to header.is_linked_to_previous")
43+
def when_I_assign_value_to_header_is_linked_to_previous(context, value):
44+
context.header.is_linked_to_previous = eval(value)
45+
46+
47+
@when("I assign {value} to footer.is_linked_to_previous")
48+
def when_I_assign_value_to_footer_is_linked_to_previous(context, value):
49+
context.footer.is_linked_to_previous = eval(value)
50+
51+
52+
# then =====================================================
53+
54+
@then("footer.is_linked_to_previous is {value}")
55+
def then_footer_is_linked_to_previous_is_value(context, value):
56+
actual = context.footer.is_linked_to_previous
57+
expected = eval(value)
58+
assert actual == expected, "footer.is_linked_to_previous is %s" % actual
59+
60+
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
66+
67+
68+
@then("footer_2.is_linked_to_previous is {value}")
69+
def then_footer_2_is_linked_to_previous_is_value(context, value):
70+
actual = context.footer_2.is_linked_to_previous
71+
expected = eval(value)
72+
assert actual == expected, "footer_2.is_linked_to_previous is %s" % actual
73+
74+
75+
@then("header.is_linked_to_previous is {value}")
76+
def then_header_is_linked_to_previous_is_value(context, value):
77+
actual = context.header.is_linked_to_previous
78+
expected = eval(value)
79+
assert actual == expected, "header.is_linked_to_previous is %s" % actual
80+
81+
82+
@then("header_2.is_linked_to_previous is {value}")
83+
def then_header_2_is_linked_to_previous_is_value(context, value):
84+
actual = context.header_2.is_linked_to_previous
85+
expected = eval(value)
86+
assert actual == expected, "header_2.is_linked_to_previous is %s" % actual
87+
88+
89+
@then("header_2.paragraphs[0].text == header.paragraphs[0].text")
90+
def then_header_2_text_eq_header_text(context):
91+
actual = context.header_2.paragraphs[0].text
92+
expected = context.header.paragraphs[0].text
93+
assert actual == expected, "header_2.paragraphs[0].text == %s" % actual

features/steps/section.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
# given ====================================================
2020

21+
@given("a Section object as section")
22+
def given_a_Section_object_as_section(context):
23+
context.section = Document(test_docx("sct-section-props")).sections[-1]
24+
25+
2126
@given('a section collection containing 3 sections')
2227
def given_a_section_collection_containing_3_sections(context):
2328
document = Document(test_docx('doc-access-sections'))
@@ -137,6 +142,20 @@ def then_len_sections_is_3(context):
137142
)
138143

139144

145+
@then("section.footer is a _Footer object")
146+
def then_section_footer_is_a_Footer_object(context):
147+
actual = type(context.section.footer).__name__
148+
expected = "_Footer"
149+
assert actual == expected, "section.footer is a %s object" % actual
150+
151+
152+
@then("section.header is a _Header object")
153+
def then_section_header_is_a_Header_object(context):
154+
actual = type(context.section.header).__name__
155+
expected = "_Header"
156+
assert actual == expected, "section.header is a %s object" % actual
157+
158+
140159
@then('the reported {margin_side} margin is {inches} inches')
141160
def then_the_reported_margin_is_inches(context, margin_side, inches):
142161
prop_name = {
17.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)