X Tutup
Skip to content

Commit a346cd7

Browse files
author
Steve Canny
committed
acpt: rewrite run style scenarios
... to accommodate new Run.style property interface
1 parent ba40612 commit a346cd7

File tree

3 files changed

+47
-37
lines changed

3 files changed

+47
-37
lines changed

features/par-add-run.feature

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ Feature: Add a run with optional text and style
33
As a python-docx programmer
44
I want a way to add a styled run of text in a single step
55

6+
67
Scenario: Add a run specifying its text
78
Given a paragraph
89
When I add a run specifying its text
910
Then the run contains the text I specified
1011

12+
13+
@wip
1114
Scenario: Add a run specifying its style
1215
Given a paragraph
1316
When I add a run specifying the character style Emphasis
14-
Then the style of the run is Emphasis
17+
Then run.style is styles['Emphasis']

features/run-char-style.feature

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,28 @@ Feature: Each run has a read/write style
44
I need the ability to get and set the character style of a run
55

66

7+
@wip
78
Scenario Outline: Get the character style of a run
8-
Given a run having style <char style>
9-
Then the style of the run is <char style>
9+
Given a run having <style> style
10+
Then run.style is styles['<value>']
1011

1112
Examples: Character styles
12-
| char style |
13-
| None |
14-
| Emphasis |
15-
| Strong |
13+
| style | value |
14+
| no explicit | Default Paragraph Font |
15+
| Emphasis | Emphasis |
16+
| Strong | Strong |
1617

1718

19+
@wip
1820
Scenario Outline: Set the style of a run
19-
Given a run having style <char style>
20-
When I set the character style of the run to <new char style>
21-
Then the style of the run is <new char style>
21+
Given a run having <style> style
22+
When I assign <value> to run.style
23+
Then run.style is styles['<style-name>']
2224

2325
Examples: Character style transitions
24-
| char style | new char style |
25-
| None | None |
26-
| None | Emphasis |
27-
| Emphasis | None |
28-
| Emphasis | Emphasis |
29-
| Emphasis | Strong |
26+
| style | value | style-name |
27+
| no explicit | Emphasis | Emphasis |
28+
| no explicit | styles['Emphasis'] | Emphasis |
29+
| Emphasis | Strong | Strong |
30+
| Emphasis | styles['Strong'] | Strong |
31+
| Strong | None | Default Paragraph Font |

features/steps/text.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,14 @@ def given_a_run_having_underline_type(context, underline_type):
173173
context.run = document.paragraphs[0].runs[run_idx]
174174

175175

176-
@given('a run having style {char_style}')
177-
def given_a_run_having_style_char_style(context, char_style):
176+
@given('a run having {style} style')
177+
def given_a_run_having_style(context, style):
178178
run_idx = {
179-
'None': 0, 'Emphasis': 1, 'Strong': 2
180-
}[char_style]
181-
document = Document(test_docx('run-char-style'))
179+
'no explicit': 0,
180+
'Emphasis': 1,
181+
'Strong': 2,
182+
}[style]
183+
context.document = document = Document(test_docx('run-char-style'))
182184
context.run = document.paragraphs[0].runs[run_idx]
183185

184186

@@ -361,19 +363,23 @@ def when_assign_true_to_bool_run_prop(context, value_str, bool_prop_name):
361363
setattr(run, bool_prop_name, value)
362364

363365

366+
@when('I assign {value} to run.style')
367+
def when_I_assign_value_to_run_style(context, value):
368+
if value == 'None':
369+
new_value = None
370+
elif value.startswith('styles['):
371+
new_value = context.document.styles[value.split('\'')[1]]
372+
else:
373+
new_value = context.document.styles[value]
374+
375+
context.run.style = new_value
376+
377+
364378
@when('I clear the run')
365379
def when_I_clear_the_run(context):
366380
context.run.clear()
367381

368382

369-
@when('I set the character style of the run to {char_style}')
370-
def when_I_set_the_character_style_of_the_run(context, char_style):
371-
style_value = {
372-
'None': None, 'Emphasis': 'Emphasis', 'Strong': 'Strong'
373-
}[char_style]
374-
context.run.style = style_value
375-
376-
377383
@when('I set the run underline to {underline_value}')
378384
def when_I_set_the_run_underline_to_value(context, underline_value):
379385
new_value = {
@@ -521,6 +527,13 @@ def then_run_font_is_the_Font_object_for_the_run(context):
521527
assert font.element is run.element
522528

523529

530+
@then('run.style is styles[\'{style_name}\']')
531+
def then_run_style_is_style(context, style_name):
532+
expected_value = context.document.styles[style_name]
533+
run = context.run
534+
assert run.style == expected_value, 'got %s' % run.style
535+
536+
524537
@then('the last item in the run is a break')
525538
def then_last_item_in_run_is_a_break(context):
526539
run = context.run
@@ -591,14 +604,6 @@ def then_the_run_underline_property_value_is(context, underline_value):
591604
assert context.run.underline == expected_value
592605

593606

594-
@then('the style of the run is {char_style}')
595-
def then_the_style_of_the_run_is_char_style(context, char_style):
596-
expected_value = {
597-
'None': None, 'Emphasis': 'Emphasis', 'Strong': 'Strong'
598-
}[char_style]
599-
assert context.run.style == expected_value
600-
601-
602607
@then('the tab appears at the end of the run')
603608
def then_the_tab_appears_at_the_end_of_the_run(context):
604609
r = context.run._r

0 commit comments

Comments
 (0)
X Tutup