Skip to content

Commit 13b1e74

Browse files
author
Steve Canny
committed
acpt: migrate scenario for Document.styles
1 parent 804aad1 commit 13b1e74

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

features/doc-access-collections.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ Feature: Access document collections
1717
Scenario: Access the section collection of a document
1818
Given a document having sections
1919
Then document.sections is a Sections object
20+
21+
22+
Scenario: Access the styles collection of a document
23+
Given a document having styles
24+
Then document.styles is a Styles object

features/doc-styles.feature

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
Feature: Access document styles
2-
In order to discover and manipulate document styles
1+
Feature: Access a document style
2+
In order to operate on a particular document style
33
As a developer using python-docx
4-
I need a way to access document styles
4+
I access to each style in the document style collection
55

66

7-
Scenario Outline: Access document styles collection
7+
Scenario Outline: Access style in style collection
88
Given a document having <styles-state>
9-
Then I can access the document styles collection
10-
And len(styles) is <style-count>
9+
Then len(styles) is <style-count>
10+
And I can iterate over its styles
11+
And I can access a style by style id
12+
And I can access a style by its UI name
1113

1214
Examples: having styles or not
1315
| styles-state | style-count |
1416
| a styles part | 6 |
1517
| no styles part | 4 |
1618

1719

18-
Scenario: Access style in style collection
19-
Given a document having a styles part
20-
Then I can iterate over its styles
21-
And I can access a style by style id
22-
And I can access a style by its UI name

features/steps/document.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from docx.parts.document import InlineShapes
1414
from docx.shared import Inches
1515
from docx.section import Sections
16+
from docx.styles.styles import Styles
1617
from docx.table import Table
1718

1819
from helpers import test_docx, test_file
@@ -35,6 +36,11 @@ def given_a_document_having_sections(context):
3536
context.document = Document(test_docx('doc-access-sections'))
3637

3738

39+
@given('a document having styles')
40+
def given_a_document_having_styles(context):
41+
context.document = Document(test_docx('sty-having-styles-part'))
42+
43+
3844
@given('a single-section document having portrait layout')
3945
def given_a_single_section_document_having_portrait_layout(context):
4046
context.document = Document(test_docx('doc-add-section'))
@@ -152,19 +158,25 @@ def then_document_inline_shapes_is_an_InlineShapes_object(context):
152158
assert isinstance(inline_shapes, InlineShapes)
153159

154160

161+
@then('document.paragraphs is a list containing three paragraphs')
162+
def then_document_paragraphs_is_a_list_containing_three_paragraphs(context):
163+
document = context.document
164+
paragraphs = document.paragraphs
165+
assert isinstance(paragraphs, list)
166+
assert len(paragraphs) == 3
167+
168+
155169
@then('document.sections is a Sections object')
156170
def then_document_sections_is_a_Sections_object(context):
157171
sections = context.document.sections
158172
msg = 'document.sections not instance of Sections'
159173
assert isinstance(sections, Sections), msg
160174

161175

162-
@then('document.paragraphs is a list containing three paragraphs')
163-
def then_document_paragraphs_is_a_list_containing_three_paragraphs(context):
164-
document = context.document
165-
paragraphs = document.paragraphs
166-
assert isinstance(paragraphs, list)
167-
assert len(paragraphs) == 3
176+
@then('document.styles is a Styles object')
177+
def then_document_styles_is_a_Styles_object(context):
178+
styles = context.document.styles
179+
assert isinstance(styles, Styles)
168180

169181

170182
@then('the document contains a 2 x 2 table')

features/steps/styles.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from docx import Document
1010
from docx.enum.style import WD_STYLE_TYPE
1111
from docx.styles.latent import _LatentStyle, LatentStyles
12-
from docx.styles.styles import Styles
1312
from docx.styles.style import BaseStyle
1413
from docx.text.paragraph import ParagraphFormat
1514
from docx.text.run import Font
@@ -331,13 +330,6 @@ def then_I_can_access_a_style_by_style_id(context):
331330
assert isinstance(style, BaseStyle)
332331

333332

334-
@then('I can access the document styles collection')
335-
def then_I_can_access_the_document_styles_collection(context):
336-
document = context.document
337-
styles = document.styles
338-
assert isinstance(styles, Styles)
339-
340-
341333
@then('I can iterate over its styles')
342334
def then_I_can_iterate_over_its_styles(context):
343335
styles = [s for s in context.document.styles]

0 commit comments

Comments
 (0)