add tests

This commit is contained in:
Khaleel Al-Adhami 2024-10-11 11:40:00 -07:00
parent 220a058273
commit cd6b02468f
2 changed files with 27 additions and 0 deletions

View File

@ -195,6 +195,8 @@ def unionize(*args: GenericType) -> Type:
return Any
if len(args) == 1:
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
# In Python versions >= 3.11, we can simply do `return Union[*args]`
midpoint = len(args) // 2

View File

@ -398,6 +398,31 @@ def test_list_tuple_contains(var, expected):
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(
"var, expected",
[