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