mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Improve a docstring, add tests for CSS opacity parsing
This commit is contained in:
@@ -21,10 +21,11 @@ from ..geometry import Spacing, SpacingDimensions, clamp
|
||||
|
||||
|
||||
def _join_tokens(tokens: Iterable[Token], joiner: str = "") -> str:
|
||||
"""Convert tokens into a string
|
||||
"""Convert tokens into a string by joining their values
|
||||
|
||||
Args:
|
||||
tokens (Iterable[Token]): Tokens to join
|
||||
joiner (str): String to join on, defaults to ""
|
||||
|
||||
Returns:
|
||||
str: The tokens, joined together to form a string.
|
||||
|
||||
@@ -314,3 +314,29 @@ class TestParseTransition:
|
||||
assert len(stylesheet_errors) == 1
|
||||
assert stylesheet_errors[0][0].value == invalid_func_name
|
||||
assert ex.value.errors is not None
|
||||
|
||||
|
||||
class TestParseOpacity:
|
||||
@pytest.mark.parametrize("css_value, styles_value", [
|
||||
["-0.2", 0.0],
|
||||
["0.4", 0.4],
|
||||
["1.3", 1.0],
|
||||
["-20%", 0.0],
|
||||
["25%", 0.25],
|
||||
["128%", 1.0],
|
||||
])
|
||||
def test_opacity_to_styles(self, css_value, styles_value):
|
||||
css = f"#some-widget {{ opacity: {css_value} }}"
|
||||
stylesheet = Stylesheet()
|
||||
stylesheet.parse(css)
|
||||
|
||||
assert stylesheet.rules[0].styles.opacity == styles_value
|
||||
assert not stylesheet.rules[0].errors
|
||||
|
||||
def test_opacity_invalid_value(self):
|
||||
css = "#some-widget { opacity: 123x }"
|
||||
stylesheet = Stylesheet()
|
||||
|
||||
with pytest.raises(StylesheetParseError):
|
||||
stylesheet.parse(css)
|
||||
assert stylesheet.rules[0].errors
|
||||
|
||||
Reference in New Issue
Block a user