Fix exception message plus unit tests

This commit is contained in:
Elijah 2024-10-25 16:35:21 +00:00
parent ccaf2c65d4
commit a6530a7e78
2 changed files with 58 additions and 1 deletions

View File

@ -145,5 +145,5 @@ class DynamicComponentInvalidSignature(ReflexError, TypeError):
"""Raised when a dynamic component has an invalid signature."""
class InvalidPropValueError(ReflexError, ValueError):
class InvalidPropValueError(ReflexError):
"""Raised when a prop value is invalid."""

View File

@ -0,0 +1,57 @@
import pytest
from reflex.utils.exceptions import InvalidPropValueError
from reflex.components.props import NoExtrasAllowedProps
class PropA(NoExtrasAllowedProps):
"""Base prop class."""
foo: str
bar: str
class PropB(NoExtrasAllowedProps):
"""Prop class with nested props."""
foobar: str
foobaz: PropA
@pytest.mark.parametrize(
"props_class, kwargs, should_raise",
[
(PropA, {"foo": "value", "bar": "another_value"}, False),
(PropA, {"fooz": "value", "bar": "another_value"}, True),
(
PropB,
{
"foobaz": {"foo": "value", "bar": "another_value"},
"foobar": "foo_bar_value",
},
False,
),
(
PropB,
{
"fooba": {"foo": "value", "bar": "another_value"},
"foobar": "foo_bar_value",
},
True,
),
(
PropB,
{
"foobaz": {"foobar": "value", "bar": "another_value"},
"foobar": "foo_bar_value",
},
True,
),
],
)
def test_no_extras_allowed_props(props_class, kwargs, should_raise):
if should_raise:
with pytest.raises(InvalidPropValueError):
props_class(**kwargs)
else:
props_instance = props_class(**kwargs)
assert isinstance(props_instance, props_class)