1313
1414from helpers import test_docx
1515
16+ bool_vals = {
17+ 'True' : True ,
18+ 'False' : False
19+ }
20+
21+ style_types = {
22+ 'WD_STYLE_TYPE.CHARACTER' : WD_STYLE_TYPE .CHARACTER ,
23+ 'WD_STYLE_TYPE.PARAGRAPH' : WD_STYLE_TYPE .PARAGRAPH ,
24+ 'WD_STYLE_TYPE.LIST' : WD_STYLE_TYPE .LIST ,
25+ 'WD_STYLE_TYPE.TABLE' : WD_STYLE_TYPE .TABLE ,
26+ }
27+
1628
1729# given ===================================================
1830
@@ -22,6 +34,14 @@ def given_a_document_having_a_styles_part(context):
2234 context .document = Document (docx_path )
2335
2436
37+ @given ('a document having known styles' )
38+ def given_a_document_having_known_styles (context ):
39+ docx_path = test_docx ('sty-known-styles' )
40+ document = Document (docx_path )
41+ context .document = document
42+ context .style_count = len (document .styles )
43+
44+
2545@given ('a document having no styles part' )
2646def given_a_document_having_no_styles_part (context ):
2747 docx_path = test_docx ('sty-having-no-styles-part' )
@@ -47,6 +67,14 @@ def when_I_assign_a_new_value_to_style_style_id(context):
4767 context .style .style_id = 'Foo42'
4868
4969
70+ @when ('I call add_style(\' {name}\' , {type_str}, builtin={builtin_str})' )
71+ def when_I_call_add_style (context , name , type_str , builtin_str ):
72+ styles = context .document .styles
73+ type = style_types [type_str ]
74+ builtin = bool_vals [builtin_str ]
75+ styles .add_style (name , type , builtin = builtin )
76+
77+
5078# then =====================================================
5179
5280@then ('I can access a style by its UI name' )
@@ -82,6 +110,13 @@ def then_len_styles_is_style_count(context, style_count_str):
82110 assert len (context .document .styles ) == int (style_count_str )
83111
84112
113+ @then ('style.builtin is {builtin_str}' )
114+ def then_style_builtin_is_builtin (context , builtin_str ):
115+ style = context .style
116+ builtin = bool_vals [builtin_str ]
117+ assert style .builtin == builtin
118+
119+
85120@then ('style.name is the {which} name' )
86121def then_style_name_is_the_which_name (context , which ):
87122 expected_name = {
@@ -106,3 +141,25 @@ def then_style_style_id_is_the_which_style_id(context, which):
106141def then_style_type_is_the_known_type (context ):
107142 style = context .style
108143 assert style .type == WD_STYLE_TYPE .PARAGRAPH
144+
145+
146+ @then ('style.type is {type_str}' )
147+ def then_style_type_is_type (context , type_str ):
148+ style = context .style
149+ style_type = style_types [type_str ]
150+ assert style .type == style_type
151+
152+
153+ @then ('styles[\' {name}\' ] is a style' )
154+ def then_styles_name_is_a_style (context , name ):
155+ styles = context .document .styles
156+ style = context .style = styles [name ]
157+ assert isinstance (style , BaseStyle )
158+
159+
160+ @then ('the document has one additional style' )
161+ def then_the_document_has_one_additional_style (context ):
162+ document = context .document
163+ style_count = len (document .styles )
164+ expected_style_count = context .style_count + 1
165+ assert style_count == expected_style_count
0 commit comments