Skip to content

Commit 8f6ba19

Browse files
author
Steve Canny
committed
acpt: add run-bold-italic.feature
1 parent d04bbd0 commit 8f6ba19

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

docx/text.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ def add_text(self, text):
8989
t = self._r.add_t(text)
9090
return Text(t)
9191

92+
@property
93+
def bold(self):
94+
"""
95+
Read/write. The bold setting for this run, one of |True|, |False|, or
96+
|None|. When |True|, the run will appear in bold unconditionally.
97+
When |False| it will appear without bold unconditionally. When
98+
|None|, the run will inherit its bold setting from its style
99+
hierarchy.
100+
"""
101+
raise NotImplementedError
102+
92103
@property
93104
def text(self):
94105
"""

features/run-bold-italic.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Feature: Apply bold or italic to run
2+
In order to apply emphasis to a particular word or phrase in a paragraph
3+
As a python-docx developer
4+
I need a way to query and set bold and italic on a run
5+
6+
@wip
7+
Scenario: Apply bold to a run
8+
Given a run
9+
When I assign True to its bold property
10+
Then the run appears in bold typeface
11+
12+
@wip
13+
Scenario: Remove bold from a run
14+
Given a run having bold set on
15+
When I assign None to its bold property
16+
Then the run appears with its inherited bold setting
17+
18+
@wip
19+
Scenario: Set bold off unconditionally
20+
Given a run
21+
When I assign False to its bold property
22+
Then the run appears without bold regardless of its style hierarchy

features/steps/text.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ def given_a_run(context):
2121
context.run = p.add_run()
2222

2323

24+
@given('a run having bold set on')
25+
def given_a_run_having_bold_set_on(context):
26+
run = Document().add_paragraph().add_run()
27+
run.bold = True
28+
context.run = run
29+
30+
2431
# when ====================================================
2532

2633
@when('I add a column break')
@@ -41,6 +48,13 @@ def when_add_page_break(context):
4148
run.add_break(WD_BREAK.PAGE)
4249

4350

51+
@when('I assign {value_str} to its bold property')
52+
def when_assign_true_to_its_bold_property(context, value_str):
53+
value = {'True': True, 'False': False, 'None': None}[value_str]
54+
run = context.run
55+
run.bold = value
56+
57+
4458
# then =====================================================
4559

4660
@then('it is a column break')
@@ -69,3 +83,21 @@ def then_last_item_in_run_is_a_break(context):
6983
'{http://schemas.openxmlformats.org/wordprocessingml/2006/main}br'
7084
)
7185
assert context.last_child.tag == expected_tag
86+
87+
88+
@then('the run appears in bold typeface')
89+
def then_run_appears_in_bold_typeface(context):
90+
run = context.run
91+
assert run.bold is True
92+
93+
94+
@then('the run appears with its inherited bold setting')
95+
def then_run_appears_with_its_inherited_bold_setting(context):
96+
run = context.run
97+
assert run.bold is None
98+
99+
100+
@then('the run appears without bold regardless of its style hierarchy')
101+
def then_run_appears_without_bold_regardless(context):
102+
run = context.run
103+
assert run.bold is False

0 commit comments

Comments
 (0)