12
12
from docx .dml .color import ColorFormat
13
13
from docx .shared import RGBColor
14
14
15
- from ..unitutil .cxml import element
15
+ from ..unitutil .cxml import element , xml
16
16
17
17
import pytest
18
18
@@ -27,6 +27,11 @@ def it_knows_its_RGB_value(self, rgb_get_fixture):
27
27
color_format , expected_value = rgb_get_fixture
28
28
assert color_format .rgb == expected_value
29
29
30
+ def it_can_change_its_RGB_value (self , rgb_set_fixture ):
31
+ color_format , new_value , expected_xml = rgb_set_fixture
32
+ color_format .rgb = new_value
33
+ assert color_format ._element .xml == expected_xml
34
+
30
35
# fixtures ---------------------------------------------
31
36
32
37
@pytest .fixture (params = [
@@ -43,6 +48,25 @@ def rgb_get_fixture(self, request):
43
48
expected_value = None if rgb is None else RGBColor .from_string (rgb )
44
49
return color_format , expected_value
45
50
51
+ @pytest .fixture (params = [
52
+ ('w:r' , RGBColor (10 , 20 , 30 ), 'w:r/w:rPr/w:color{w:val=0A141E}' ),
53
+ ('w:r/w:rPr' , RGBColor (1 , 2 , 3 ), 'w:r/w:rPr/w:color{w:val=010203}' ),
54
+ ('w:r/w:rPr/w:color{w:val=123abc}' , RGBColor (42 , 24 , 99 ),
55
+ 'w:r/w:rPr/w:color{w:val=2A1863}' ),
56
+ ('w:r/w:rPr/w:color{w:val=auto}' , RGBColor (16 , 17 , 18 ),
57
+ 'w:r/w:rPr/w:color{w:val=101112}' ),
58
+ ('w:r/w:rPr/w:color{w:val=234bcd,w:themeColor=dark1}' ,
59
+ RGBColor (24 , 42 , 99 ), 'w:r/w:rPr/w:color{w:val=182A63}' ),
60
+ ('w:r/w:rPr/w:color{w:val=234bcd,w:themeColor=dark1}' ,
61
+ None , 'w:r/w:rPr' ),
62
+ ('w:r' , None , 'w:r' ),
63
+ ])
64
+ def rgb_set_fixture (self , request ):
65
+ r_cxml , new_value , expected_cxml = request .param
66
+ color_format = ColorFormat (element (r_cxml ))
67
+ expected_xml = xml (expected_cxml )
68
+ return color_format , new_value , expected_xml
69
+
46
70
@pytest .fixture (params = [
47
71
('w:r' , None ),
48
72
('w:r/w:rPr' , None ),
0 commit comments