fix units tests
This commit is contained in:
parent
780291576a
commit
6a81fe0c84
@ -1,7 +1,5 @@
|
|||||||
"""Data display component tests fixtures."""
|
"""Data display component tests fixtures."""
|
||||||
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -54,11 +52,11 @@ def data_table_state3():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
class DataTableState(BaseState):
|
class DataTableState(BaseState):
|
||||||
_data: List = []
|
_data: list = []
|
||||||
_columns: List = ["col1", "col2"]
|
_columns: list = ["col1", "col2"]
|
||||||
|
|
||||||
@rx.var
|
@rx.var
|
||||||
def data(self) -> List:
|
def data(self) -> list:
|
||||||
return self._data
|
return self._data
|
||||||
|
|
||||||
@rx.var
|
@rx.var
|
||||||
@ -77,15 +75,15 @@ def data_table_state4():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
class DataTableState(BaseState):
|
class DataTableState(BaseState):
|
||||||
_data: List = []
|
_data: list = []
|
||||||
_columns: List = ["col1", "col2"]
|
_columns: list[str] = ["col1", "col2"]
|
||||||
|
|
||||||
@rx.var
|
@rx.var
|
||||||
def data(self):
|
def data(self):
|
||||||
return self._data
|
return self._data
|
||||||
|
|
||||||
@rx.var
|
@rx.var
|
||||||
def columns(self) -> List:
|
def columns(self) -> list:
|
||||||
return self._columns
|
return self._columns
|
||||||
|
|
||||||
return DataTableState
|
return DataTableState
|
||||||
|
@ -4,6 +4,7 @@ import pytest
|
|||||||
import reflex as rx
|
import reflex as rx
|
||||||
from reflex.components.gridjs.datatable import DataTable
|
from reflex.components.gridjs.datatable import DataTable
|
||||||
from reflex.utils import types
|
from reflex.utils import types
|
||||||
|
from reflex.utils.exceptions import UntypedComputedVarError
|
||||||
from reflex.utils.serializers import serialize, serialize_dataframe
|
from reflex.utils.serializers import serialize, serialize_dataframe
|
||||||
|
|
||||||
|
|
||||||
@ -75,17 +76,17 @@ def test_invalid_props(props):
|
|||||||
[
|
[
|
||||||
(
|
(
|
||||||
"data_table_state2",
|
"data_table_state2",
|
||||||
"Annotation of the computed var assigned to the data field should be provided.",
|
"Computed var 'data' must have a type annotation.",
|
||||||
True,
|
True,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"data_table_state3",
|
"data_table_state3",
|
||||||
"Annotation of the computed var assigned to the column field should be provided.",
|
"Computed var 'columns' must have a type annotation.",
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"data_table_state4",
|
"data_table_state4",
|
||||||
"Annotation of the computed var assigned to the data field should be provided.",
|
"Computed var 'data' must have a type annotation.",
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -99,7 +100,7 @@ def test_computed_var_without_annotation(fixture, request, err_msg, is_data_fram
|
|||||||
err_msg: expected error message.
|
err_msg: expected error message.
|
||||||
is_data_frame: whether data field is a pandas dataframe.
|
is_data_frame: whether data field is a pandas dataframe.
|
||||||
"""
|
"""
|
||||||
with pytest.raises(ValueError) as err:
|
with pytest.raises(UntypedComputedVarError) as err:
|
||||||
if is_data_frame:
|
if is_data_frame:
|
||||||
DataTable.create(data=request.getfixturevalue(fixture).data)
|
DataTable.create(data=request.getfixturevalue(fixture).data)
|
||||||
else:
|
else:
|
||||||
|
@ -199,16 +199,15 @@ def test_event_redirect(input, output):
|
|||||||
input: The input for running the test.
|
input: The input for running the test.
|
||||||
output: The expected output to validate the test.
|
output: The expected output to validate the test.
|
||||||
"""
|
"""
|
||||||
path, external, replace = input
|
path, is_external, replace = input
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if external is not None:
|
if is_external is not None:
|
||||||
kwargs["external"] = external
|
kwargs["is_external"] = is_external
|
||||||
if replace is not None:
|
if replace is not None:
|
||||||
kwargs["replace"] = replace
|
kwargs["replace"] = replace
|
||||||
spec = event.redirect(path, **kwargs)
|
spec = event.redirect(path, **kwargs)
|
||||||
assert isinstance(spec, EventSpec)
|
assert isinstance(spec, EventSpec)
|
||||||
assert spec.handler.fn.__qualname__ == "_redirect"
|
assert spec.handler.fn.__qualname__ == "_redirect"
|
||||||
|
|
||||||
assert format.format_event(spec) == output
|
assert format.format_event(spec) == output
|
||||||
|
|
||||||
|
|
||||||
|
@ -1143,7 +1143,7 @@ def test_child_state():
|
|||||||
|
|
||||||
class ChildState(MainState):
|
class ChildState(MainState):
|
||||||
@computed_var
|
@computed_var
|
||||||
def rendered_var(self):
|
def rendered_var(self) -> int:
|
||||||
return self.v
|
return self.v
|
||||||
|
|
||||||
ms = MainState()
|
ms = MainState()
|
||||||
@ -1420,7 +1420,7 @@ def test_computed_var_dependencies():
|
|||||||
return self.testprop
|
return self.testprop
|
||||||
|
|
||||||
@rx.var(cache=True)
|
@rx.var(cache=True)
|
||||||
def comp_w(self):
|
def comp_w(self) -> Callable[[], int]:
|
||||||
"""Nested lambda.
|
"""Nested lambda.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -1429,7 +1429,7 @@ def test_computed_var_dependencies():
|
|||||||
return lambda: self.w
|
return lambda: self.w
|
||||||
|
|
||||||
@rx.var(cache=True)
|
@rx.var(cache=True)
|
||||||
def comp_x(self):
|
def comp_x(self) -> Callable[[], int]:
|
||||||
"""Nested function.
|
"""Nested function.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -1442,7 +1442,7 @@ def test_computed_var_dependencies():
|
|||||||
return _
|
return _
|
||||||
|
|
||||||
@rx.var(cache=True)
|
@rx.var(cache=True)
|
||||||
def comp_y(self) -> List[int]:
|
def comp_y(self) -> list[int]:
|
||||||
"""Comprehension iterating over attribute.
|
"""Comprehension iterating over attribute.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -3122,7 +3122,7 @@ async def test_get_state_from_sibling_not_cached(mock_app: rx.App, token: str):
|
|||||||
child3_var: int = 0
|
child3_var: int = 0
|
||||||
|
|
||||||
@rx.var
|
@rx.var
|
||||||
def v(self):
|
def v(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Grandchild3(Child3):
|
class Grandchild3(Child3):
|
||||||
|
@ -11,7 +11,10 @@ import reflex as rx
|
|||||||
from reflex.base import Base
|
from reflex.base import Base
|
||||||
from reflex.constants.base import REFLEX_VAR_CLOSING_TAG, REFLEX_VAR_OPENING_TAG
|
from reflex.constants.base import REFLEX_VAR_CLOSING_TAG, REFLEX_VAR_OPENING_TAG
|
||||||
from reflex.state import BaseState
|
from reflex.state import BaseState
|
||||||
from reflex.utils.exceptions import PrimitiveUnserializableToJSON
|
from reflex.utils.exceptions import (
|
||||||
|
PrimitiveUnserializableToJSON,
|
||||||
|
UntypedComputedVarError,
|
||||||
|
)
|
||||||
from reflex.utils.imports import ImportVar
|
from reflex.utils.imports import ImportVar
|
||||||
from reflex.vars import VarData
|
from reflex.vars import VarData
|
||||||
from reflex.vars.base import (
|
from reflex.vars.base import (
|
||||||
@ -804,7 +807,7 @@ def test_shadow_computed_var_error(request: pytest.FixtureRequest, fixture: str)
|
|||||||
request: Fixture Request.
|
request: Fixture Request.
|
||||||
fixture: The state fixture.
|
fixture: The state fixture.
|
||||||
"""
|
"""
|
||||||
with pytest.raises(NameError):
|
with pytest.raises(UntypedComputedVarError):
|
||||||
state = request.getfixturevalue(fixture)
|
state = request.getfixturevalue(fixture)
|
||||||
state.var_without_annotation.foo
|
state.var_without_annotation.foo
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user