Skip to content

Commit 1c30ccb

Browse files
author
Steve Canny
committed
acpt: add italic scenarios
1 parent 6be61e4 commit 1c30ccb

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

docx/text.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ def bold(self, value):
115115
if bool(value) is False:
116116
b.val = False
117117

118+
@property
119+
def italic(self):
120+
"""
121+
Read/write. The italic setting for this run, one of |True|, |False|,
122+
or |None|. When |True|, the run will appear in italic
123+
unconditionally. When |False| it will appear without italic
124+
unconditionally. When |None|, the run will inherit its italic setting
125+
from its style hierarchy.
126+
"""
127+
118128
@property
119129
def text(self):
120130
"""

features/run-bold-italic.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,21 @@ Feature: Apply bold or italic to run
1717
Given a run
1818
When I assign False to its bold property
1919
Then the run appears without bold regardless of its style hierarchy
20+
21+
@wip
22+
Scenario: Apply italic to a run
23+
Given a run
24+
When I assign True to its italic property
25+
Then the run appears in italic typeface
26+
27+
@wip
28+
Scenario: Remove italic from a run
29+
Given a run having italic set on
30+
When I assign None to its italic property
31+
Then the run appears with its inherited italic setting
32+
33+
@wip
34+
Scenario: Set italic off unconditionally
35+
Given a run
36+
When I assign False to its italic property
37+
Then the run appears without italic regardless of its style hierarchy

features/steps/text.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ def given_a_run_having_bold_set_on(context):
2828
context.run = run
2929

3030

31+
@given('a run having italic set on')
32+
def given_a_run_having_italic_set_on(context):
33+
run = Document().add_paragraph().add_run()
34+
run.italic = True
35+
context.run = run
36+
37+
3138
# when ====================================================
3239

3340
@when('I add a column break')
@@ -55,6 +62,13 @@ def when_assign_true_to_its_bold_property(context, value_str):
5562
run.bold = value
5663

5764

65+
@when('I assign {value_str} to its italic property')
66+
def when_assign_true_to_its_italic_property(context, value_str):
67+
value = {'True': True, 'False': False, 'None': None}[value_str]
68+
run = context.run
69+
run.italic = value
70+
71+
5872
# then =====================================================
5973

6074
@then('it is a column break')
@@ -91,13 +105,31 @@ def then_run_appears_in_bold_typeface(context):
91105
assert run.bold is True
92106

93107

108+
@then('the run appears in italic typeface')
109+
def then_run_appears_in_italic_typeface(context):
110+
run = context.run
111+
assert run.italic is True
112+
113+
94114
@then('the run appears with its inherited bold setting')
95115
def then_run_appears_with_its_inherited_bold_setting(context):
96116
run = context.run
97117
assert run.bold is None
98118

99119

120+
@then('the run appears with its inherited italic setting')
121+
def then_run_appears_with_its_inherited_italic_setting(context):
122+
run = context.run
123+
assert run.italic is None
124+
125+
100126
@then('the run appears without bold regardless of its style hierarchy')
101127
def then_run_appears_without_bold_regardless(context):
102128
run = context.run
103129
assert run.bold is False
130+
131+
132+
@then('the run appears without italic regardless of its style hierarchy')
133+
def then_run_appears_without_italic_regardless(context):
134+
run = context.run
135+
assert run.italic is False

0 commit comments

Comments
 (0)