add tests
This commit is contained in:
parent
220a058273
commit
cd6b02468f
@ -195,6 +195,8 @@ def unionize(*args: GenericType) -> Type:
|
|||||||
return Any
|
return Any
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
return args[0]
|
return args[0]
|
||||||
|
if sys.version_info >= (3, 11):
|
||||||
|
return Union[*args] # type: ignore
|
||||||
# We are bisecting the args list here to avoid hitting the recursion limit
|
# We are bisecting the args list here to avoid hitting the recursion limit
|
||||||
# In Python versions >= 3.11, we can simply do `return Union[*args]`
|
# In Python versions >= 3.11, we can simply do `return Union[*args]`
|
||||||
midpoint = len(args) // 2
|
midpoint = len(args) // 2
|
||||||
|
@ -398,6 +398,31 @@ def test_list_tuple_contains(var, expected):
|
|||||||
assert str(var.contains(other_var)) == f"{expected}.includes(other)"
|
assert str(var.contains(other_var)) == f"{expected}.includes(other)"
|
||||||
|
|
||||||
|
|
||||||
|
class Foo(rx.Base):
|
||||||
|
bar: int
|
||||||
|
baz: str
|
||||||
|
|
||||||
|
|
||||||
|
class Bar(rx.Base):
|
||||||
|
bar: str
|
||||||
|
baz: str
|
||||||
|
foo: int
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("var", "var_type"),
|
||||||
|
[
|
||||||
|
(Var(_js_expr="", _var_type=Foo | Bar).guess_type(), Foo | Bar),
|
||||||
|
(Var(_js_expr="", _var_type=Union[Foo, Bar]).guess_type(), Union[Foo, Bar]),
|
||||||
|
(Var(_js_expr="", _var_type=Union[Foo, Bar]).guess_type().bar, Union[int, str]),
|
||||||
|
(Var(_js_expr="", _var_type=Union[Foo, Bar]).guess_type().baz, str),
|
||||||
|
(Var(_js_expr="", _var_type=Union[Foo, Bar]).guess_type().foo, Union[int, None]),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_var_types(var, var_type):
|
||||||
|
assert var._var_type == var_type
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"var, expected",
|
"var, expected",
|
||||||
[
|
[
|
||||||
|
Loading…
Reference in New Issue
Block a user