44Step implementations for styles-related features
55"""
66
7- from behave import given , then
7+ from behave import given , then , when
88
99from docx import Document
1010from 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}' )
6175def 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
0 commit comments