mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
[css] Use a HelpText for unknown CSS property name errors
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from contextlib import nullcontext as does_not_raise
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from textual.color import Color
|
||||
from textual.css._help_renderables import HelpText
|
||||
from textual.css.stylesheet import Stylesheet, StylesheetParseError
|
||||
from textual.css.tokenizer import TokenizeError
|
||||
|
||||
@@ -60,6 +63,7 @@ def test_color_property_parsing(css_value, expectation, expected_color):
|
||||
[
|
||||
["backgroundu", "background"],
|
||||
["bckgroundu", "background"],
|
||||
["ofset-x", "offset-x"],
|
||||
["colr", "color"],
|
||||
["colour", "color"],
|
||||
["wdth", "width"],
|
||||
@@ -81,12 +85,17 @@ def test_did_you_mean_for_css_property_names(
|
||||
"${PROPERTY}", css_property_name
|
||||
)
|
||||
|
||||
stylesheet.add_source(css)
|
||||
with pytest.raises(StylesheetParseError) as err:
|
||||
stylesheet.parse(css)
|
||||
stylesheet.parse()
|
||||
|
||||
error_token, error_message = err.value.errors.stylesheet.rules[0].errors[0]
|
||||
if expected_property_name_suggestion is None:
|
||||
assert "did you mean" not in error_message
|
||||
else:
|
||||
expected_did_you_mean_error_message = f"unknown declaration '{css_property_name}'; did you mean '{expected_property_name_suggestion}'?"
|
||||
assert expected_did_you_mean_error_message == error_message
|
||||
_, help_text = err.value.errors.rules[0].errors[0] # type: Any, HelpText
|
||||
assert help_text.summary == f"Invalid CSS property [i]{css_property_name}[/]"
|
||||
|
||||
expected_bullets_length = 1 if expected_property_name_suggestion else 0
|
||||
assert len(help_text.bullets) == expected_bullets_length
|
||||
if expected_property_name_suggestion is not None:
|
||||
expected_suggestion_message = (
|
||||
f"Did you mean [i]{expected_property_name_suggestion}[/]?"
|
||||
)
|
||||
assert help_text.bullets[0].markup == expected_suggestion_message
|
||||
|
||||
Reference in New Issue
Block a user