mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Improve color parsing tests
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user