Skip to content

Commit d11d160

Browse files
committed
acpt: add basic scenario for section.Header
1 parent 13dd6f0 commit d11d160

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

docx/header.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Header(object):
2+
@property
3+
def text(self):
4+
text = ''
5+
for p in self.paragraphs:
6+
text += p.text + '\n'
7+
8+
return text
9+
10+
@text.setter
11+
def text(self, text):
12+
raise NotImplementedError('todo')

docx/section.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def __init__(self, sectPr):
4141
super(Section, self).__init__()
4242
self._sectPr = sectPr
4343

44+
@property
45+
def header(self):
46+
return "I am not a header"
47+
4448
@property
4549
def bottom_margin(self):
4650
"""

features/sct-section-header.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Feature: Header stuff
2+
Scenario: Basic
3+
Given a section
4+
Then section.header is a Header object
5+
6+
Given a header having a definition
7+
Then header.is_linked_to_previous is False
8+
9+
Given a header having a definition
10+
Then header.text is the text contained in the header

features/steps/header.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from __future__ import (
2+
absolute_import, division, print_function, unicode_literals
3+
)
4+
5+
from behave import given, then
6+
7+
from docx import Document
8+
from docx.header import Header
9+
10+
from helpers import test_docx
11+
12+
13+
# given ===================================================
14+
15+
@given('a section')
16+
def given_a_section(context):
17+
document = Document(test_docx('doc-default'))
18+
context.section = document.sections[0]
19+
20+
21+
@given('a header having a definition')
22+
def given_a_header_having_a_definition(context):
23+
document = Document(test_docx('doc-default'))
24+
header = document.sections[0].header
25+
context.header = header
26+
27+
28+
# then =====================================================
29+
30+
@then('section.header is a Header object')
31+
def section_header_is_a_header_object(context):
32+
section = context.section
33+
assert isinstance(section.header, Header)
34+
35+
36+
@then('header.is_linked_to_previous is False')
37+
def header_is_linked_to_previous_is_False(context):
38+
header = context.header
39+
assert header.is_linked_to_previous is False
40+
41+
42+
@then('header.text is the text contained in the header')
43+
def header_text_is_the_text_contained_in_the_header(context):
44+
header = context.header
45+
assert header.text == 'paragraph1\nparagraph2'

0 commit comments

Comments
 (0)