|
@@ -1,8 +1,9 @@
|
|
import typing
|
|
import typing
|
|
-from typing import Dict, List, Tuple
|
|
|
|
|
|
+from typing import Dict, List, Set, Tuple
|
|
|
|
|
|
import cloudpickle
|
|
import cloudpickle
|
|
import pytest
|
|
import pytest
|
|
|
|
+from pandas import DataFrame
|
|
|
|
|
|
from reflex.base import Base
|
|
from reflex.base import Base
|
|
from reflex.state import State
|
|
from reflex.state import State
|
|
@@ -293,11 +294,54 @@ def test_var_indexing_lists(var):
|
|
# Test negative indexing.
|
|
# Test negative indexing.
|
|
assert str(var[-1]) == f"{{{var.name}.at(-1)}}"
|
|
assert str(var[-1]) == f"{{{var.name}.at(-1)}}"
|
|
|
|
|
|
- # Test non-integer indexing raises an error.
|
|
|
|
- with pytest.raises(TypeError):
|
|
|
|
- var["a"]
|
|
|
|
|
|
+
|
|
|
|
+@pytest.mark.parametrize(
|
|
|
|
+ "var, index",
|
|
|
|
+ [
|
|
|
|
+ (BaseVar(name="lst", type_=List[int]), [1, 2]),
|
|
|
|
+ (BaseVar(name="lst", type_=List[int]), {"name": "dict"}),
|
|
|
|
+ (BaseVar(name="lst", type_=List[int]), {"set"}),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="lst", type_=List[int]),
|
|
|
|
+ (
|
|
|
|
+ 1,
|
|
|
|
+ 2,
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ (BaseVar(name="lst", type_=List[int]), 1.5),
|
|
|
|
+ (BaseVar(name="lst", type_=List[int]), "str"),
|
|
|
|
+ (BaseVar(name="lst", type_=List[int]), BaseVar(name="string_var", type_=str)),
|
|
|
|
+ (BaseVar(name="lst", type_=List[int]), BaseVar(name="float_var", type_=float)),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="lst", type_=List[int]),
|
|
|
|
+ BaseVar(name="list_var", type_=List[int]),
|
|
|
|
+ ),
|
|
|
|
+ (BaseVar(name="lst", type_=List[int]), BaseVar(name="set_var", type_=Set[str])),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="lst", type_=List[int]),
|
|
|
|
+ BaseVar(name="dict_var", type_=Dict[str, str]),
|
|
|
|
+ ),
|
|
|
|
+ (BaseVar(name="str", type_=str), [1, 2]),
|
|
|
|
+ (BaseVar(name="lst", type_=str), {"name": "dict"}),
|
|
|
|
+ (BaseVar(name="lst", type_=str), {"set"}),
|
|
|
|
+ (BaseVar(name="lst", type_=str), BaseVar(name="string_var", type_=str)),
|
|
|
|
+ (BaseVar(name="lst", type_=str), BaseVar(name="float_var", type_=float)),
|
|
|
|
+ (BaseVar(name="str", type_=Tuple[str]), [1, 2]),
|
|
|
|
+ (BaseVar(name="lst", type_=Tuple[str]), {"name": "dict"}),
|
|
|
|
+ (BaseVar(name="lst", type_=Tuple[str]), {"set"}),
|
|
|
|
+ (BaseVar(name="lst", type_=Tuple[str]), BaseVar(name="string_var", type_=str)),
|
|
|
|
+ (BaseVar(name="lst", type_=Tuple[str]), BaseVar(name="float_var", type_=float)),
|
|
|
|
+ ],
|
|
|
|
+)
|
|
|
|
+def test_var_unsupported_indexing_lists(var, index):
|
|
|
|
+ """Test unsupported indexing throws a type error.
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ var: The base var.
|
|
|
|
+ index: The base var index.
|
|
|
|
+ """
|
|
with pytest.raises(TypeError):
|
|
with pytest.raises(TypeError):
|
|
- var[1.5]
|
|
|
|
|
|
+ var[index]
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
@pytest.mark.parametrize(
|
|
@@ -328,6 +372,84 @@ def test_dict_indexing():
|
|
assert str(dct["asdf"]) == '{dct["asdf"]}'
|
|
assert str(dct["asdf"]) == '{dct["asdf"]}'
|
|
|
|
|
|
|
|
|
|
|
|
+@pytest.mark.parametrize(
|
|
|
|
+ "var, index",
|
|
|
|
+ [
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="dict", type_=Dict[str, str]),
|
|
|
|
+ [1, 2],
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="dict", type_=Dict[str, str]),
|
|
|
|
+ {"name": "dict"},
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="dict", type_=Dict[str, str]),
|
|
|
|
+ {"set"},
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="dict", type_=Dict[str, str]),
|
|
|
|
+ (
|
|
|
|
+ 1,
|
|
|
|
+ 2,
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="lst", type_=Dict[str, str]),
|
|
|
|
+ BaseVar(name="list_var", type_=List[int]),
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="lst", type_=Dict[str, str]),
|
|
|
|
+ BaseVar(name="set_var", type_=Set[str]),
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="lst", type_=Dict[str, str]),
|
|
|
|
+ BaseVar(name="dict_var", type_=Dict[str, str]),
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="df", type_=DataFrame),
|
|
|
|
+ [1, 2],
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="df", type_=DataFrame),
|
|
|
|
+ {"name": "dict"},
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="df", type_=DataFrame),
|
|
|
|
+ {"set"},
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="df", type_=DataFrame),
|
|
|
|
+ (
|
|
|
|
+ 1,
|
|
|
|
+ 2,
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="df", type_=DataFrame),
|
|
|
|
+ BaseVar(name="list_var", type_=List[int]),
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="df", type_=DataFrame),
|
|
|
|
+ BaseVar(name="set_var", type_=Set[str]),
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ BaseVar(name="df", type_=DataFrame),
|
|
|
|
+ BaseVar(name="dict_var", type_=Dict[str, str]),
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+)
|
|
|
|
+def test_var_unsupported_indexing_dicts(var, index):
|
|
|
|
+ """Test unsupported indexing throws a type error.
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ var: The base var.
|
|
|
|
+ index: The base var index.
|
|
|
|
+ """
|
|
|
|
+ with pytest.raises(TypeError):
|
|
|
|
+ var[index]
|
|
|
|
+
|
|
|
|
+
|
|
@pytest.mark.parametrize(
|
|
@pytest.mark.parametrize(
|
|
"fixture,full_name",
|
|
"fixture,full_name",
|
|
[
|
|
[
|