Skip to content

Commit f5e4d3e

Browse files
author
Steve Canny
committed
acpt: add act-section-props.feature
1 parent e053724 commit f5e4d3e

File tree

5 files changed

+100
-22
lines changed

5 files changed

+100
-22
lines changed

docs/dev/analysis/features/sections.rst

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ working with sections::
3838

3939
>>> sections = document.sections
4040
>>> sections
41-
<docx.section.Sections object at 0x1deadbeef>
41+
<docx.parts.document.Sections object at 0x1deadbeef>
4242
>>> len(sections)
4343
3
4444
>>> section = sections[-1] # the sentinel section
@@ -119,27 +119,6 @@ LANDSCAPE (1)
119119
PORTRAIT (0)
120120
Portrait orientation.
121121

122-
::
123-
124-
@alias(WD_SECTION)
125-
class WD_SECTION_START(Enumeration):
126-
127-
CONTINUOUS (0)
128-
Continuous section break.
129-
130-
EVENPAGE (3)
131-
Even pages section break.
132-
133-
NEWCOLUMN (1)
134-
New column section break.
135-
136-
NEWPAGE (2)
137-
New page section break.
138-
139-
ODDPAGE (4)
140-
Odd pages section break.
141-
142-
143122

144123
Specimen XML
145124
------------

docx/enum/section.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Enumerations related to the main document in WordprocessingML files
5+
"""
6+
7+
from __future__ import absolute_import, print_function, unicode_literals
8+
9+
from .base import alias, XmlEnumeration, XmlMappedEnumMember
10+
11+
12+
@alias('WD_SECTION')
13+
class WD_SECTION_START(XmlEnumeration):
14+
"""
15+
Specifies the start type of a section break.
16+
"""
17+
18+
__ms_name__ = 'WdSectionStart'
19+
20+
__url__ = 'http://msdn.microsoft.com/en-us/library/office/ff840975.aspx'
21+
22+
__members__ = (
23+
XmlMappedEnumMember(
24+
'CONTINUOUS', 0, 'continuous', 'Continuous section break.'
25+
),
26+
XmlMappedEnumMember(
27+
'NEW_COLUMN', 1, 'nextColumn', 'New column section break.'
28+
),
29+
XmlMappedEnumMember(
30+
'NEW_PAGE', 2, 'nextPage', 'New page section break.'
31+
),
32+
XmlMappedEnumMember(
33+
'EVEN_PAGE', 3, 'evenPage', 'Even pages section break.'
34+
),
35+
XmlMappedEnumMember(
36+
'ODD_PAGE', 4, 'oddPage', 'Section begins on next odd page.'
37+
),
38+
)

features/sct-section-props.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Feature: Access and change section properties
2+
In order to discover and modify document section behaviors
3+
As a developer using python-docx
4+
I need a way to get and set the properties of a section
5+
6+
7+
@wip
8+
Scenario Outline: Get section start type
9+
Given a section having start type <start-type>
10+
Then the reported section start type is <start-type>
11+
12+
Examples: Section start types
13+
| start-type |
14+
| CONTINUOUS |
15+
| NEW_COLUMN |
16+
| NEW_PAGE |
17+
| EVEN_PAGE |
18+
| ODD_PAGE |

features/steps/section.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Step implementations for section-related features
5+
"""
6+
7+
from __future__ import absolute_import, print_function, unicode_literals
8+
9+
from behave import given, then
10+
11+
from docx import Document
12+
from docx.enum.section import WD_SECTION
13+
14+
from helpers import test_docx
15+
16+
17+
# given ====================================================
18+
19+
@given('a section having start type {start_type}')
20+
def given_a_section_having_start_type(context, start_type):
21+
section_idx = {
22+
'CONTINUOUS': 0,
23+
'NEW_PAGE': 1,
24+
'ODD_PAGE': 2,
25+
'EVEN_PAGE': 3,
26+
'NEW_COLUMN': 4,
27+
}[start_type]
28+
document = Document(test_docx('sct-section-props'))
29+
context.section = document.sections[section_idx]
30+
31+
32+
# then =====================================================
33+
34+
@then('the reported section start type is {start_type}')
35+
def then_the_reported_section_start_type_is_type(context, start_type):
36+
expected_start_type = {
37+
'CONTINUOUS': WD_SECTION.CONTINUOUS,
38+
'EVEN_PAGE': WD_SECTION.EVEN_PAGE,
39+
'NEW_COLUMN': WD_SECTION.NEW_COLUMN,
40+
'NEW_PAGE': WD_SECTION.NEW_PAGE,
41+
'ODD_PAGE': WD_SECTION.ODD_PAGE,
42+
}[start_type]
43+
assert context.section.start_type == expected_start_type
27.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)