Skip to content

Commit 6f0bc1f

Browse files
author
Steve Canny
committed
acpt: add scenarios for Style.style_id
1 parent 7fc1c2c commit 6f0bc1f

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

features/steps/styles.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Step implementations for styles-related features
55
"""
66

7-
from behave import given, then
7+
from behave import given, then, when
88

99
from docx import Document
1010
from docx.styles.styles import Styles
@@ -27,6 +27,20 @@ def given_a_document_having_no_styles_part(context):
2727
context.document = Document(docx_path)
2828

2929

30+
@given('a style having a known style id')
31+
def given_a_style_having_a_known_style_id(context):
32+
docx_path = test_docx('sty-having-styles-part')
33+
document = Document(docx_path)
34+
context.style = document.styles['Normal']
35+
36+
37+
# when =====================================================
38+
39+
@when('I assign a new value to style.style_id')
40+
def when_I_assign_a_new_value_to_style_style_id(context):
41+
context.style.style_id = 'Foo42'
42+
43+
3044
# then =====================================================
3145

3246
@then('I can access a style by its UI name')
@@ -60,3 +74,13 @@ def then_I_can_iterate_over_its_styles(context):
6074
@then('len(styles) is {style_count_str}')
6175
def then_len_styles_is_style_count(context, style_count_str):
6276
assert len(context.document.styles) == int(style_count_str)
77+
78+
79+
@then('style.style_id is the {which} style id')
80+
def then_style_style_id_is_the_which_style_id(context, which):
81+
expected_style_id = {
82+
'known': 'Normal',
83+
'new': 'Foo42',
84+
}[which]
85+
style = context.style
86+
assert style.style_id == expected_style_id

features/sty-style-props.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Feature: Get and set style properties
2+
In order to adjust styles to suit my needs
3+
As a developer using python-docx
4+
I need a set of read/write style properties
5+
6+
7+
@wip
8+
Scenario: Get style id
9+
Given a style having a known style id
10+
Then style.style_id is the known style id
11+
12+
13+
@wip
14+
Scenario: Set style id
15+
Given a style having a known style id
16+
When I assign a new value to style.style_id
17+
Then style.style_id is the new style id

0 commit comments

Comments
 (0)