Skip to content

Commit 9c86462

Browse files
author
Steve Canny
committed
acpt: add run-clear-run.feature
Scenario for Run.clear() API method.
1 parent 1a05663 commit 9c86462

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

features/run-clear-run.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Feature: Remove the content of a run
2+
In order to edit the content of a run while preserving its formatting
3+
As a developer using python-docx
4+
I need a way to clear the content of a run
5+
6+
7+
@wip
8+
Scenario: Clear run content
9+
Given a run having known text and formatting
10+
When I clear the run
11+
Then the run contains no text
12+
But the run formatting is preserved

features/steps/text.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ def given_a_run_having_bool_prop_set_on(context, bool_prop_name):
3030
context.run = run
3131

3232

33+
@given('a run having known text and formatting')
34+
def given_a_run_having_known_text_and_formatting(context):
35+
run = Document().add_paragraph().add_run('foobar')
36+
run.bold = True
37+
run.italic = True
38+
context.run = run
39+
40+
3341
@given('a run having {underline_type} underline')
3442
def given_a_run_having_underline_type(context, underline_type):
3543
run_idx = {
@@ -85,6 +93,11 @@ def when_assign_true_to_bool_run_prop(context, value_str, bool_prop_name):
8593
setattr(run, bool_prop_name, value)
8694

8795

96+
@when('I clear the run')
97+
def when_I_clear_the_run(context):
98+
context.run.clear()
99+
100+
88101
@when('I set the character style of the run to {char_style}')
89102
def when_I_set_the_character_style_of_the_run(context, char_style):
90103
style_value = {
@@ -151,11 +164,22 @@ def then_run_appears_without_bool_prop(context, boolean_prop_name):
151164
assert getattr(run, boolean_prop_name) is False
152165

153166

167+
@then('the run contains no text')
168+
def then_the_run_contains_no_text(context):
169+
assert context.run.text == ''
170+
171+
154172
@then('the run contains the text I specified')
155173
def then_the_run_contains_the_text_I_specified(context):
156174
assert context.run.text == test_text
157175

158176

177+
@then('the run formatting is preserved')
178+
def then_the_run_formatting_is_preserved(context):
179+
assert context.run.bold is True
180+
assert context.run.italic is True
181+
182+
159183
@then('the run underline property value is {underline_value}')
160184
def then_the_run_underline_property_value_is(context, underline_value):
161185
expected_value = {

0 commit comments

Comments
 (0)