def test_from_xml(self, Stop): src = """ <stop position=".5"> <color rgb="00999999"></color> </stop> """ node = fromstring(src) stop = Stop.from_tree(node) assert stop == Stop('999999', .5)
def test_ctor(self, Stop): stop = Stop('999999', .5) xml = tostring(stop.to_tree()) expected = """ <stop position="0.5"> <color rgb="00999999"></color> </stop> """ diff = compare_xml(xml, expected) assert diff is None, diff
def test_create(self, GradientFill, Stop): src = """ <fill> <gradientFill xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" degree="90"> <stop position="0"> <color theme="0"/> </stop> <stop position="1"> <color theme="4"/> </stop> </gradientFill> </fill> """ xml = fromstring(src) fill = GradientFill.from_tree(xml) assert fill.stop == [ Stop(Color(theme=0), position=0), Stop(Color(theme=4), position=1) ]
def test_serialise(self, GradientFill, Stop): gf = GradientFill(degree=90, left=1, right=2, top=3, bottom=4, stop=[Stop(BLACK, 0), Stop(WHITE, 1)]) xml = tostring(gf.to_tree()) expected = """ <fill> <gradientFill bottom="4" degree="90" left="1" right="2" top="3" type="linear"> <stop position="0"> <color rgb="00000000"></color> </stop> <stop position="1"> <color rgb="00FFFFFF"></color> </stop> </gradientFill> </fill> """ diff = compare_xml(xml, expected) assert diff is None, diff
def test_duplicate_position(self, Stop): from ..fills import _assign_position with pytest.raises(ValueError): _assign_position([Stop(BLACK, 0.5), Stop(BLACK, 0.5)])
def test_invalid_stop_color_mix(self, Stop): from ..fills import _assign_position with pytest.raises(ValueError): _assign_position([Stop(BLACK, .1), WHITE])
def test_stop_sequence(self, GradientFill, Stop, colors): gf = GradientFill(stop=[Stop(colors[0], 0), Stop(colors[1], .5)]) assert gf.stop[0].color.rgb == BLACK assert gf.stop[1].color.rgb == WHITE assert gf.stop[0].position == 0 assert gf.stop[1].position == .5
def test_position_invalid(self, Stop, position, exception): with pytest.raises(exception): Stop('999999', position)
def test_position_valid(self, Stop, position): # smoke test Stop('999999', position)