88 absolute_import , division , print_function , unicode_literals
99)
1010
11- from docx .enum .dml import MSO_COLOR_TYPE
11+ from docx .enum .dml import MSO_COLOR_TYPE , MSO_THEME_COLOR
1212from docx .dml .color import ColorFormat
1313from docx .shared import RGBColor
1414
@@ -32,6 +32,10 @@ def it_can_change_its_RGB_value(self, rgb_set_fixture):
3232 color_format .rgb = new_value
3333 assert color_format ._element .xml == expected_xml
3434
35+ def it_knows_its_theme_color (self , theme_color_get_fixture ):
36+ color_format , expected_value = theme_color_get_fixture
37+ assert color_format .theme_color == expected_value
38+
3539 # fixtures ---------------------------------------------
3640
3741 @pytest .fixture (params = [
@@ -67,6 +71,22 @@ def rgb_set_fixture(self, request):
6771 expected_xml = xml (expected_cxml )
6872 return color_format , new_value , expected_xml
6973
74+ @pytest .fixture (params = [
75+ ('w:r' , None ),
76+ ('w:r/w:rPr' , None ),
77+ ('w:r/w:rPr/w:color{w:val=auto}' , None ),
78+ ('w:r/w:rPr/w:color{w:val=4224FF}' , None ),
79+ ('w:r/w:rPr/w:color{w:themeColor=accent1}' , 'ACCENT_1' ),
80+ ('w:r/w:rPr/w:color{w:val=F00BA9,w:themeColor=dark1}' , 'DARK_1' ),
81+ ])
82+ def theme_color_get_fixture (self , request ):
83+ r_cxml , value = request .param
84+ color_format = ColorFormat (element (r_cxml ))
85+ expected_value = (
86+ None if value is None else getattr (MSO_THEME_COLOR , value )
87+ )
88+ return color_format , expected_value
89+
7090 @pytest .fixture (params = [
7191 ('w:r' , None ),
7292 ('w:r/w:rPr' , None ),
0 commit comments