Cleanup and new test.

This commit is contained in:
Rodrigo Girão Serrão
2023-01-17 10:29:19 +00:00
parent 8f877d826f
commit 2b9cd81ca5
2 changed files with 13 additions and 3 deletions

View File

@@ -912,7 +912,7 @@ class StyleFlagsProperty:
)
try:
style = Style.parse(style_flags)
except rich.errors.StyleSyntaxError as exc:
except rich.errors.StyleSyntaxError as error:
if "none" in words and len(words) > 1:
raise StyleValueError(
"cannot mix 'none' with other style flags",
@@ -920,7 +920,7 @@ class StyleFlagsProperty:
self.name, " ".join(words), context="inline"
),
) from None
raise exc from None
raise error from None
if obj.set_rule(self.name, style):
obj.refresh()

View File

@@ -18,5 +18,15 @@ def test_text_style_none_with_others(style_attr):
"""Style "none" mixed with others should give custom Textual exception."""
styles = Styles()
with pytest.raises(StyleValueError) as exc_info:
with pytest.raises(StyleValueError):
setattr(styles, style_attr, "bold none underline italic")
@pytest.mark.parametrize("style_attr", ["text_style", "link_style"])
def test_text_style_set_to_none(style_attr):
"""Setting text style to "none" should clear the styles."""
styles = Styles()
setattr(styles, style_attr, "bold underline italic")
assert getattr(styles, style_attr) != Style.null()
setattr(styles, style_attr, "none")
assert getattr(styles, style_attr) == Style.null()