|
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 |
|
| 7 | +from pptx.dml.color import ColorFormat |
7 | 8 | from pptx.dml.effect import ShadowFormat |
| 9 | +from pptx.util import Emu, Pt |
8 | 10 |
|
9 | 11 | from ..unitutil.cxml import element, xml |
10 | 12 |
|
11 | 13 |
|
12 | 14 | class DescribeShadowFormat(object): |
| 15 | + @pytest.mark.parametrize( |
| 16 | + ("spPr_cxml", "expected_value"), |
| 17 | + [ |
| 18 | + ("p:spPr", False), |
| 19 | + ("p:spPr/a:effectLst", False), |
| 20 | + ("p:spPr/a:effectLst/a:outerShdw", True), |
| 21 | + ], |
| 22 | + ) |
| 23 | + def it_knows_whether_a_shadow_is_visible(self, spPr_cxml: str, expected_value: bool): |
| 24 | + shadow = ShadowFormat(element(spPr_cxml)) |
| 25 | + assert shadow.visible is expected_value |
| 26 | + |
| 27 | + def it_can_make_a_shadow_visible(self): |
| 28 | + spPr = element("p:spPr") |
| 29 | + shadow = ShadowFormat(spPr) |
| 30 | + shadow.visible = True |
| 31 | + assert shadow.visible is True |
| 32 | + assert spPr.effectLst is not None |
| 33 | + assert spPr.effectLst.outerShdw is not None |
| 34 | + |
| 35 | + def it_can_make_a_shadow_invisible(self): |
| 36 | + spPr = element("p:spPr/a:effectLst/a:outerShdw") |
| 37 | + shadow = ShadowFormat(spPr) |
| 38 | + shadow.visible = False |
| 39 | + assert shadow.visible is False |
| 40 | + |
| 41 | + @pytest.mark.parametrize( |
| 42 | + ("spPr_cxml", "expected_value"), |
| 43 | + [ |
| 44 | + ("p:spPr", None), |
| 45 | + ("p:spPr/a:effectLst", None), |
| 46 | + ("p:spPr/a:effectLst/a:outerShdw", 0.0), |
| 47 | + ("p:spPr/a:effectLst/a:outerShdw{dir=2700000}", 45.0), |
| 48 | + ("p:spPr/a:effectLst/a:outerShdw{dir=5400000}", 90.0), |
| 49 | + ], |
| 50 | + ) |
| 51 | + def it_knows_the_shadow_angle(self, spPr_cxml: str, expected_value: float | None): |
| 52 | + shadow = ShadowFormat(element(spPr_cxml)) |
| 53 | + assert shadow.angle == expected_value |
| 54 | + |
| 55 | + def it_can_set_the_shadow_angle(self): |
| 56 | + spPr = element("p:spPr") |
| 57 | + shadow = ShadowFormat(spPr) |
| 58 | + shadow.angle = 45.0 |
| 59 | + assert shadow.angle == 45.0 |
| 60 | + |
| 61 | + @pytest.mark.parametrize( |
| 62 | + ("spPr_cxml", "expected_value"), |
| 63 | + [ |
| 64 | + ("p:spPr", None), |
| 65 | + ("p:spPr/a:effectLst/a:outerShdw", 0), |
| 66 | + ("p:spPr/a:effectLst/a:outerShdw{blurRad=50800}", 50800), |
| 67 | + ], |
| 68 | + ) |
| 69 | + def it_knows_the_blur_radius(self, spPr_cxml: str, expected_value: int | None): |
| 70 | + shadow = ShadowFormat(element(spPr_cxml)) |
| 71 | + assert shadow.blur_radius == expected_value |
| 72 | + |
| 73 | + def it_can_set_the_blur_radius(self): |
| 74 | + spPr = element("p:spPr") |
| 75 | + shadow = ShadowFormat(spPr) |
| 76 | + shadow.blur_radius = Pt(4) |
| 77 | + assert shadow.blur_radius == Pt(4) |
| 78 | + |
| 79 | + @pytest.mark.parametrize( |
| 80 | + ("spPr_cxml", "expected_value"), |
| 81 | + [ |
| 82 | + ("p:spPr", None), |
| 83 | + ("p:spPr/a:effectLst/a:outerShdw", 0), |
| 84 | + ("p:spPr/a:effectLst/a:outerShdw{dist=38100}", 38100), |
| 85 | + ], |
| 86 | + ) |
| 87 | + def it_knows_the_shadow_distance(self, spPr_cxml: str, expected_value: int | None): |
| 88 | + shadow = ShadowFormat(element(spPr_cxml)) |
| 89 | + assert shadow.distance == expected_value |
| 90 | + |
| 91 | + def it_can_set_the_shadow_distance(self): |
| 92 | + spPr = element("p:spPr") |
| 93 | + shadow = ShadowFormat(spPr) |
| 94 | + shadow.distance = Pt(3) |
| 95 | + assert shadow.distance == Pt(3) |
| 96 | + |
| 97 | + def it_provides_access_to_the_shadow_color(self): |
| 98 | + spPr = element("p:spPr") |
| 99 | + shadow = ShadowFormat(spPr) |
| 100 | + assert isinstance(shadow.color, ColorFormat) |
| 101 | + |
| 102 | + @pytest.mark.parametrize( |
| 103 | + ("spPr_cxml", "expected_value"), |
| 104 | + [ |
| 105 | + ("p:spPr", None), |
| 106 | + ("p:spPr/a:effectLst/a:outerShdw", True), |
| 107 | + ("p:spPr/a:effectLst/a:outerShdw{rotWithShape=0}", False), |
| 108 | + ("p:spPr/a:effectLst/a:outerShdw{rotWithShape=1}", True), |
| 109 | + ], |
| 110 | + ) |
| 111 | + def it_knows_rotate_with_shape(self, spPr_cxml: str, expected_value: bool | None): |
| 112 | + shadow = ShadowFormat(element(spPr_cxml)) |
| 113 | + assert shadow.rotate_with_shape == expected_value |
| 114 | + |
13 | 115 | def it_knows_whether_it_inherits(self, inherit_get_fixture): |
14 | 116 | shadow, expected_value = inherit_get_fixture |
15 | 117 | inherit = shadow.inherit |
|
0 commit comments