Skip to content

Commit

Permalink
Align unit tests for CapturedCallable with new way of validating it
Browse files Browse the repository at this point in the history
  • Loading branch information
maxschulz-COL committed Dec 3, 2024
1 parent f05c474 commit 906a448
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions vizro-core/tests/unit/vizro/models/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import plotly.graph_objects as go
import plotly.io as pio
import pytest
from pydantic import Field, ValidationError
from pydantic import Field, ValidationError, field_validator
from pydantic.json_schema import SkipJsonSchema

# try:
# from pydantic.v1 import Field, ValidationError
# except ImportError: # pragma: no cov
# from pydantic import Field, ValidationError
from vizro.models import VizroBaseModel
from vizro.models.types import CapturedCallable, capture
from vizro.models.types import CapturedCallable, capture, validate_captured_callable


def positional_only_function(a, /):
Expand Down Expand Up @@ -163,12 +164,18 @@ def invalid_decorated_graph_function():

class ModelWithAction(VizroBaseModel):
# The import_path here makes it possible to import the above function using getattr(import_path, _target_).
function: CapturedCallable = Field(..., import_path=__name__, mode="action")
function: SkipJsonSchema[CapturedCallable] = Field(
..., json_schema_extra={"mode": "action", "import_path": __name__}
)
_validate_figure = field_validator("function", mode="before")(validate_captured_callable)


class ModelWithGraph(VizroBaseModel):
# The import_path here makes it possible to import the above function using getattr(import_path, _target_).
function: CapturedCallable = Field(..., import_path=__name__, mode="graph")
function: SkipJsonSchema[CapturedCallable] = Field(
..., json_schema_extra={"mode": "graph", "import_path": __name__}
)
_validate_figure = field_validator("function", mode="before")(validate_captured_callable)


class TestModelFieldPython:
Expand Down

0 comments on commit 906a448

Please sign in to comment.