Improve color parsing tests

This commit is contained in:
Darren Burns
2022-06-07 16:21:05 +01:00
parent 2086062b56
commit 01bedd7f04

View File

@@ -108,12 +108,34 @@ def test_color_blend():
("rgb(2,3,4)", Color(2, 3, 4, 1.0)),
("rgba(2,3,4,1.0)", Color(2, 3, 4, 1.0)),
("rgba(2,3,4,0.058823529411764705)", Color(2, 3, 4, 0.058823529411764705)),
("hsl(45,25%,25%)", Color(80, 72, 48)),
("hsla(45,25%,25%,0.35)", Color(80, 72, 48, 0.35)),
],
)
def test_color_parse(text, expected):
assert Color.parse(text) == expected
@pytest.mark.parametrize("input,output", [
("rgb( 300, 300 , 300 )", Color(255, 255, 255)),
("rgba( 2 , 3 , 4, 1.0 )", Color(2, 3, 4, 1.0)),
("hsl( 45, 25% , 25% )", Color(80, 72, 48)),
("hsla( 45, 25% , 25%, 0.35 )", Color(80, 72, 48, 0.35)),
])
def test_color_parse_input_has_spaces(input, output):
assert Color.parse(input) == output
@pytest.mark.parametrize("input,output", [
("rgb(300, 300, 300)", Color(255, 255, 255)),
("rgba(300, 300, 300, 300)", Color(255, 255, 255, 1.0)),
("hsl(400, 200%, 250%)", Color(255, 255, 255, 1.0)),
("hsla(400, 200%, 250%, 1.9)", Color(255, 255, 255, 1.0)),
])
def test_color_parse_clamp(input, output):
assert Color.parse(input) == output
def test_color_parse_color():
# as a convenience, if Color.parse is passed a color object, it will return it
color = Color(20, 30, 40, 0.5)