This commit is contained in:
Will McGugan
2022-07-20 16:23:11 +01:00
parent 4b58171d0a
commit e0a59d0e9a

View File

@@ -4,8 +4,7 @@ import pytest
from textual.color import Color from textual.color import Color
from textual.css.errors import UnresolvedVariableError from textual.css.parse import substitute_references, TokenError
from textual.css.parse import substitute_references
from textual.css.scalar import Scalar, Unit from textual.css.scalar import Scalar, Unit
from textual.css.stylesheet import Stylesheet, StylesheetParseError from textual.css.stylesheet import Stylesheet, StylesheetParseError
from textual.css.tokenize import tokenize from textual.css.tokenize import tokenize
@@ -214,7 +213,7 @@ class TestVariableReferenceSubstitution:
def test_undefined_variable(self): def test_undefined_variable(self):
css = ".thing { border: $not-defined; }" css = ".thing { border: $not-defined; }"
with pytest.raises(UnresolvedVariableError): with pytest.raises(TokenError):
list(substitute_references(tokenize(css, ""))) list(substitute_references(tokenize(css, "")))
def test_transitive_reference(self): def test_transitive_reference(self):
@@ -907,17 +906,20 @@ class TestParseText:
class TestParseColor: class TestParseColor:
"""More in-depth tests around parsing of CSS colors""" """More in-depth tests around parsing of CSS colors"""
@pytest.mark.parametrize("value,result", [ @pytest.mark.parametrize(
("rgb(1,255,50)", Color(1, 255, 50)), "value,result",
("rgb( 1, 255,50 )", Color(1, 255, 50)), [
("rgba( 1, 255,50,0.3 )", Color(1, 255, 50, 0.3)), ("rgb(1,255,50)", Color(1, 255, 50)),
("rgba( 1, 255,50, 1.3 )", Color(1, 255, 50, 1.0)), ("rgb( 1, 255,50 )", Color(1, 255, 50)),
("hsl( 180, 50%, 50% )", Color(64, 191, 191)), ("rgba( 1, 255,50,0.3 )", Color(1, 255, 50, 0.3)),
("hsl(180,50%,50%)", Color(64, 191, 191)), ("rgba( 1, 255,50, 1.3 )", Color(1, 255, 50, 1.0)),
("hsla(180,50%,50%,0.25)", Color(64, 191, 191, 0.25)), ("hsl( 180, 50%, 50% )", Color(64, 191, 191)),
("hsla( 180, 50% ,50%,0.25 )", Color(64, 191, 191, 0.25)), ("hsl(180,50%,50%)", Color(64, 191, 191)),
("hsla( 180, 50% , 50% , 1.5 )", Color(64, 191, 191)), ("hsla(180,50%,50%,0.25)", Color(64, 191, 191, 0.25)),
]) ("hsla( 180, 50% ,50%,0.25 )", Color(64, 191, 191, 0.25)),
("hsla( 180, 50% , 50% , 1.5 )", Color(64, 191, 191)),
],
)
def test_rgb_and_hsl(self, value, result): def test_rgb_and_hsl(self, value, result):
css = f""".box {{ css = f""".box {{
color: {value}; color: {value};
@@ -1021,6 +1023,7 @@ class TestParseOverflow:
assert styles.overflow_x == "hidden" assert styles.overflow_x == "hidden"
assert styles.overflow_y == "auto" assert styles.overflow_y == "auto"
class TestParseTransition: class TestParseTransition:
@pytest.mark.parametrize( @pytest.mark.parametrize(
"duration, parsed_duration", "duration, parsed_duration",