Skip to content

Commit df9d2ba

Browse files
author
Steve Canny
committed
acpt: add scenarios for add/delete latent style
1 parent 8562eb7 commit df9d2ba

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

features/steps/styles.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ def given_the_style_collection_of_a_document(context):
192192

193193
# when =====================================================
194194

195+
@when('I add a latent style named \'Foobar\'')
196+
def when_I_add_a_latent_style_named_Foobar(context):
197+
latent_styles = context.document.styles.latent_styles
198+
context.latent_styles = latent_styles
199+
context.latent_style_count = len(latent_styles)
200+
latent_styles.add_latent_style('Foobar')
201+
202+
195203
@when('I assign a new name to the style')
196204
def when_I_assign_a_new_name_to_the_style(context):
197205
context.style.name = 'Foobar'
@@ -267,6 +275,14 @@ def when_I_call_add_style(context, name, type_str, builtin_str):
267275
styles.add_style(name, type, builtin=builtin)
268276

269277

278+
@when('I delete a latent style')
279+
def when_I_delete_a_latent_style(context):
280+
latent_styles = context.document.styles.latent_styles
281+
context.latent_styles = latent_styles
282+
context.latent_style_count = len(latent_styles)
283+
latent_styles['Normal'].delete()
284+
285+
270286
@when('I delete a style')
271287
def when_I_delete_a_style(context):
272288
context.document.styles['No List'].delete()
@@ -337,6 +353,13 @@ def then_latent_style_prop_name_is_value(context, prop_name, value):
337353
assert actual_value == expected_value
338354

339355

356+
@then('latent_styles[\'Foobar\'] is a latent style')
357+
def then_latentStyles_Foobar_is_a_latent_style(context):
358+
latent_styles = context.latent_styles
359+
latent_style = latent_styles['Foobar']
360+
assert isinstance(latent_style, _LatentStyle)
361+
362+
340363
@then('latent_styles.{prop_name} is {value}')
341364
def then_latent_styles_prop_name_is_value(context, prop_name, value):
342365
latent_styles = context.latent_styles
@@ -468,6 +491,16 @@ def then_styles_name_is_a_style(context, name):
468491
assert isinstance(style, BaseStyle)
469492

470493

494+
@then('the deleted latent style is not in the latent styles collection')
495+
def then_the_deleted_latent_style_is_not_in_the_collection(context):
496+
latent_styles = context.latent_styles
497+
try:
498+
latent_styles['Normal']
499+
except KeyError:
500+
return
501+
raise AssertionError('Latent style not deleted')
502+
503+
471504
@then('the deleted style is not in the styles collection')
472505
def then_the_deleted_style_is_not_in_the_styles_collection(context):
473506
document = context.document
@@ -478,6 +511,14 @@ def then_the_deleted_style_is_not_in_the_styles_collection(context):
478511
raise AssertionError('Style not deleted')
479512

480513

514+
@then('the document has one additional latent style')
515+
def then_the_document_has_one_additional_latent_style(context):
516+
latent_styles = context.document.styles.latent_styles
517+
latent_style_count = len(latent_styles)
518+
expected_count = context.latent_style_count + 1
519+
assert latent_style_count == expected_count
520+
521+
481522
@then('the document has one additional style')
482523
def then_the_document_has_one_additional_style(context):
483524
document = context.document
@@ -486,6 +527,13 @@ def then_the_document_has_one_additional_style(context):
486527
assert style_count == expected_style_count
487528

488529

530+
@then('the document has one fewer latent styles')
531+
def then_the_document_has_one_fewer_latent_styles(context):
532+
latent_style_count = len(context.latent_styles)
533+
expected_count = context.latent_style_count - 1
534+
assert latent_style_count == expected_count
535+
536+
489537
@then('the document has one fewer styles')
490538
def then_the_document_has_one_fewer_styles(context):
491539
document = context.document

features/sty-latent-add-del.feature

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Feature: Add or delete a latent style
2+
In order to determine which latent styles are defined in a document
3+
As a developer using python-docx
4+
I need a way to add and delete a latent style
5+
6+
7+
@wip
8+
Scenario: Add a latent style
9+
Given a document having known styles
10+
When I add a latent style named 'Foobar'
11+
Then the document has one additional latent style
12+
And latent_styles['Foobar'] is a latent style
13+
14+
15+
@wip
16+
Scenario: Delete a latent style
17+
Given a document having known styles
18+
When I delete a latent style
19+
Then the document has one fewer latent styles
20+
And the deleted latent style is not in the latent styles collection

0 commit comments

Comments
 (0)