Fix exception message plus unit tests
This commit is contained in:
parent
ccaf2c65d4
commit
a6530a7e78
@ -145,5 +145,5 @@ class DynamicComponentInvalidSignature(ReflexError, TypeError):
|
|||||||
"""Raised when a dynamic component has an invalid signature."""
|
"""Raised when a dynamic component has an invalid signature."""
|
||||||
|
|
||||||
|
|
||||||
class InvalidPropValueError(ReflexError, ValueError):
|
class InvalidPropValueError(ReflexError):
|
||||||
"""Raised when a prop value is invalid."""
|
"""Raised when a prop value is invalid."""
|
||||||
|
57
tests/units/components/test_props.py
Normal file
57
tests/units/components/test_props.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user