Skip to content

Commit 397cef4

Browse files
author
Steve Canny
committed
acpt: add scenarios for ColorFormat.type
1 parent f2a3d7c commit 397cef4

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

features/steps/font.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from docx import Document
1414
from docx.dml.color import ColorFormat
15+
from docx.enum.dml import MSO_COLOR_TYPE
1516
from docx.enum.text import WD_UNDERLINE
1617

1718
from helpers import test_docx
@@ -25,6 +26,13 @@ def given_a_font(context):
2526
context.font = document.paragraphs[0].runs[0].font
2627

2728

29+
@given('a font having {type} color')
30+
def given_a_font_having_type_color(context, type):
31+
run_idx = ['no', 'auto', 'an RGB', 'a theme'].index(type)
32+
document = Document(test_docx('fnt-color'))
33+
context.font = document.paragraphs[0].runs[run_idx].font
34+
35+
2836
@given('a font having typeface name {name}')
2937
def given_a_font_having_typeface_name(context, name):
3038
document = Document(test_docx('txt-font-props'))
@@ -122,6 +130,15 @@ def then_font_color_is_a_ColorFormat_object(context):
122130
assert isinstance(font.color, ColorFormat)
123131

124132

133+
@then('font.color.type is {value}')
134+
def then_font_color_type_is_value(context, value):
135+
font = context.font
136+
expected_value = (
137+
None if value == 'None' else getattr(MSO_COLOR_TYPE, value)
138+
)
139+
assert font.color.type == expected_value
140+
141+
125142
@then('font.name is {value}')
126143
def then_font_name_is_value(context, value):
127144
font = context.font
15.5 KB
Binary file not shown.

features/txt-font-color.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Feature: Get and set font color
2+
In order to work with the color of text
3+
As a developer using python-docx
4+
I need a way to get and set the text color
5+
6+
7+
@wip
8+
Scenario Outline: Get font color type
9+
Given a font having <type> color
10+
Then font.color.type is <value>
11+
12+
Examples: Color type settings
13+
| type | value |
14+
| no | None |
15+
| auto | AUTO |
16+
| an RGB | RGB |
17+
| a theme | THEME |

0 commit comments

Comments
 (0)