Skip to content

Commit 6b0014a

Browse files
author
Steve Canny
committed
acpt: add doc-access-sections.feature
New version of flake8 caught some new PEP8 bits in conf.py
1 parent 597617a commit 6b0014a

File tree

6 files changed

+142
-37
lines changed

6 files changed

+142
-37
lines changed

docs/conf.py

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# -- General configuration ---------------------------------------------------
2727

2828
# If your documentation needs a minimal Sphinx version, state it here.
29-
#needs_sphinx = '1.0'
29+
# needs_sphinx = '1.0'
3030

3131
# Add any Sphinx extension module names here, as strings. They can be
3232
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
@@ -45,7 +45,7 @@
4545
source_suffix = '.rst'
4646

4747
# The encoding of source files.
48-
#source_encoding = 'utf-8-sig'
48+
# source_encoding = 'utf-8-sig'
4949

5050
# The master toctree document.
5151
master_doc = 'index'
@@ -113,6 +113,10 @@
113113
114114
.. |Run| replace:: :class:`Run`
115115
116+
.. |Section| replace:: :class:`.Section`
117+
118+
.. |Sections| replace:: :class:`.Sections`
119+
116120
.. |StylesPart| replace:: :class:`StylesPart`
117121
118122
.. |Table| replace:: :class:`.Table`
@@ -131,24 +135,24 @@
131135

132136
# The reST default role (used for this markup: `text`) to use for all
133137
# documents.
134-
#default_role = None
138+
# default_role = None
135139

136140
# If true, '()' will be appended to :func: etc. cross-reference text.
137-
#add_function_parentheses = True
141+
# add_function_parentheses = True
138142

139143
# If true, the current module name will be prepended to all description
140144
# unit titles (such as .. function::).
141-
#add_module_names = True
145+
# add_module_names = True
142146

143147
# If true, sectionauthor and moduleauthor directives will be shown in the
144148
# output. They are ignored by default.
145-
#show_authors = False
149+
# show_authors = False
146150

147151
# The name of the Pygments (syntax highlighting) style to use.
148152
pygments_style = 'sphinx'
149153

150154
# A list of ignored prefixes for module index sorting.
151-
#modindex_common_prefix = []
155+
# modindex_common_prefix = []
152156

153157

154158
# -- Options for HTML output ------------------------------------------------
@@ -160,26 +164,26 @@
160164
# Theme options are theme-specific and customize the look and feel of a theme
161165
# further. For a list of options available for each theme, see the
162166
# documentation.
163-
#html_theme_options = {}
167+
# html_theme_options = {}
164168

165169
# Add any paths that contain custom themes here, relative to this directory.
166170
html_theme_path = ['_themes']
167171

168172
# The name for this set of Sphinx documents. If None, it defaults to
169173
# "<project> v<release> documentation".
170-
#html_title = None
174+
# html_title = None
171175

172176
# A shorter title for the navigation bar. Default is the same as html_title.
173-
#html_short_title = None
177+
# html_short_title = None
174178

175179
# The name of an image file (relative to this directory) to place at the top
176180
# of the sidebar.
177-
#html_logo = None
181+
# html_logo = None
178182

179183
# The name of an image file (within the static path) to use as favicon of the
180184
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
181185
# pixels large.
182-
#html_favicon = None
186+
# html_favicon = None
183187

184188
# Add any paths that contain custom static files (such as style sheets) here,
185189
# relative to this directory. They are copied after the builtin static files,
@@ -188,48 +192,48 @@
188192

189193
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
190194
# using the given strftime format.
191-
#html_last_updated_fmt = '%b %d, %Y'
195+
# html_last_updated_fmt = '%b %d, %Y'
192196

193197
# If true, SmartyPants will be used to convert quotes and dashes to
194198
# typographically correct entities.
195-
#html_use_smartypants = True
199+
# html_use_smartypants = True
196200

197201
# Custom sidebar templates, maps document names to template names.
198-
#html_sidebars = {}
202+
# html_sidebars = {}
199203
html_sidebars = {
200204
'**': ['localtoc.html', 'relations.html', 'sidebarlinks.html',
201205
'searchbox.html']
202206
}
203207

204208
# Additional templates that should be rendered to pages, maps page names to
205209
# template names.
206-
#html_additional_pages = {}
210+
# html_additional_pages = {}
207211

208212
# If false, no module index is generated.
209-
#html_domain_indices = True
213+
# html_domain_indices = True
210214

211215
# If false, no index is generated.
212-
#html_use_index = True
216+
# html_use_index = True
213217

214218
# If true, the index is split into individual pages for each letter.
215-
#html_split_index = False
219+
# html_split_index = False
216220

217221
# If true, links to the reST sources are added to the pages.
218-
#html_show_sourcelink = True
222+
# html_show_sourcelink = True
219223

220224
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
221-
#html_show_sphinx = True
225+
# html_show_sphinx = True
222226

223227
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
224-
#html_show_copyright = True
228+
# html_show_copyright = True
225229

226230
# If true, an OpenSearch description file will be output, and all pages will
227231
# contain a <link> tag referring to it. The value of this option must be the
228232
# base URL from which the finished HTML is served.
229-
#html_use_opensearch = ''
233+
# html_use_opensearch = ''
230234

231235
# This is the file name suffix for HTML files (e.g. ".xhtml").
232-
#html_file_suffix = None
236+
# html_file_suffix = None
233237

234238
# Output file base name for HTML help builder.
235239
htmlhelp_basename = 'python-docxdoc'
@@ -239,13 +243,13 @@
239243

240244
latex_elements = {
241245
# The paper size ('letterpaper' or 'a4paper').
242-
#'papersize': 'letterpaper',
246+
# 'papersize': 'letterpaper',
243247

244248
# The font size ('10pt', '11pt' or '12pt').
245-
#'pointsize': '10pt',
249+
# 'pointsize': '10pt',
246250

247251
# Additional stuff for the LaTeX preamble.
248-
#'preamble': '',
252+
# 'preamble': '',
249253
}
250254

251255
# Grouping the document tree into LaTeX files. List of tuples
@@ -261,23 +265,23 @@
261265

262266
# The name of an image file (relative to this directory) to place at the top of
263267
# the title page.
264-
#latex_logo = None
268+
# latex_logo = None
265269

266270
# For "manual" documents, if this is true, then toplevel headings are parts,
267271
# not chapters.
268-
#latex_use_parts = False
272+
# latex_use_parts = False
269273

270274
# If true, show page references after internal links.
271-
#latex_show_pagerefs = False
275+
# latex_show_pagerefs = False
272276

273277
# If true, show URL addresses after external links.
274-
#latex_show_urls = False
278+
# latex_show_urls = False
275279

276280
# Documents to append as an appendix to all manuals.
277-
#latex_appendices = []
281+
# latex_appendices = []
278282

279283
# If false, no module index is generated.
280-
#latex_domain_indices = True
284+
# latex_domain_indices = True
281285

282286

283287
# -- Options for manual page output -----------------------------------------
@@ -290,7 +294,7 @@
290294
]
291295

292296
# If true, show URL addresses after external links.
293-
#man_show_urls = False
297+
# man_show_urls = False
294298

295299

296300
# -- Options for Texinfo output ---------------------------------------------
@@ -305,13 +309,13 @@
305309
]
306310

307311
# Documents to append as an appendix to all manuals.
308-
#texinfo_appendices = []
312+
# texinfo_appendices = []
309313

310314
# If false, no module index is generated.
311-
#texinfo_domain_indices = True
315+
# texinfo_domain_indices = True
312316

313317
# How to display URL addresses: 'footnote', 'no', or 'inline'.
314-
#texinfo_show_urls = 'footnote'
318+
# texinfo_show_urls = 'footnote'
315319

316320

317321
# Example configuration for intersphinx: refer to the Python standard library.

docx/parts/document.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,10 @@ def _inline_lst(self):
214214
body = self._body
215215
xpath = './w:p/w:r/w:drawing/wp:inline'
216216
return body.xpath(xpath)
217+
218+
219+
class Sections(object):
220+
"""
221+
Sequence of |Section| objects corresponding to the sections in the
222+
document.
223+
"""

docx/section.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# encoding: utf-8
2+
3+
"""
4+
The |Section| object and related proxy classes.
5+
"""
6+
7+
from __future__ import absolute_import, print_function, unicode_literals
8+
9+
10+
class Section(object):
11+
"""
12+
Document section, providing access to section and page setup settings.
13+
"""
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Feature: Access document sections
2+
In order to discover and apply section-level settings
3+
As a developer using python-docx
4+
I need a way to access document sections
5+
6+
7+
@wip
8+
Scenario: Access section collection of a document
9+
Given a document having three sections
10+
Then I can access the section collection of the document
11+
And the length of the section collection is 3
12+
13+
14+
@wip
15+
Scenario: Access section in section collection
16+
Given a section collection
17+
Then I can iterate over the sections
18+
And I can access a section by index

features/steps/document.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Step implementations for document-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.parts.document import Sections
13+
from docx.section import Section
14+
15+
from helpers import test_docx
16+
17+
18+
# given ===================================================
19+
20+
@given('a document having three sections')
21+
def given_a_document_having_three_sections(context):
22+
context.document = Document(test_docx('doc-access-sections'))
23+
24+
25+
@given('a section collection')
26+
def given_a_section_collection(context):
27+
document = Document(test_docx('doc-access-sections'))
28+
context.sections = document.sections
29+
30+
31+
# then ====================================================
32+
33+
@then('I can access a section by index')
34+
def then_I_can_access_a_section_by_index(context):
35+
sections = context.sections
36+
for idx in range(3):
37+
section = sections[idx]
38+
assert isinstance(section, Section)
39+
40+
41+
@then('I can access the section collection of the document')
42+
def then_I_can_access_the_section_collection_of_the_document(context):
43+
sections = context.document.sections
44+
msg = 'document.sections not instance of Sections'
45+
assert isinstance(sections, Sections), msg
46+
47+
48+
@then('I can iterate over the sections')
49+
def then_I_can_iterate_over_the_sections(context):
50+
sections = context.sections
51+
actual_count = 0
52+
for section in sections:
53+
actual_count += 1
54+
assert isinstance(section, Section)
55+
assert actual_count == 3
56+
57+
58+
@then('the length of the section collection is 3')
59+
def then_the_length_of_the_section_collection_is_3(context):
60+
sections = context.sections
61+
assert len(sections) == 3, (
62+
'expected len(sections) of 2, got %s' % len(sections)
63+
)
25 KB
Binary file not shown.

0 commit comments

Comments
 (0)