Skip to content

Commit

Permalink
Rename validator
Browse files Browse the repository at this point in the history
  • Loading branch information
huong-li-nguyen committed Jul 18, 2024
1 parent 9f4481a commit 9806db5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions vizro-core/src/vizro/models/_components/_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from vizro.models import VizroBaseModel
from vizro.models._components.form import Checklist, Dropdown, RadioItems, RangeSlider, Slider
from vizro.models._layout import set_layout
from vizro.models._models_utils import _log_call, validate_components_type, validate_min_length
from vizro.models._models_utils import _log_call, check_captured_callable, validate_min_length
from vizro.models.types import _FormComponentType

if TYPE_CHECKING:
Expand All @@ -34,7 +34,7 @@ class Form(VizroBaseModel):
layout: Layout = None # type: ignore[assignment]

# Re-used validators
_validate_components_type = validator("components", allow_reuse=True, always=True, pre=True)(validate_components_type)
_check_captured_callable = validator("components", allow_reuse=True, always=True, pre=True)(check_captured_callable)
_validate_components_length = validator("components", allow_reuse=True, always=True)(validate_min_length)
_validate_layout = validator("layout", allow_reuse=True, always=True)(set_layout)

Expand Down
4 changes: 2 additions & 2 deletions vizro-core/src/vizro/models/_components/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from vizro.models import VizroBaseModel
from vizro.models._layout import set_layout
from vizro.models._models_utils import _log_call, validate_components_type, validate_min_length
from vizro.models._models_utils import _log_call, check_captured_callable, validate_min_length
from vizro.models.types import ComponentType

if TYPE_CHECKING:
Expand All @@ -36,7 +36,7 @@ class Container(VizroBaseModel):
layout: Layout = None # type: ignore[assignment]

# Re-used validators
_validate_components_type = validator("components", allow_reuse=True, always=True, pre=True)(validate_components_type)
_check_captured_callable = validator("components", allow_reuse=True, always=True, pre=True)(check_captured_callable)
_validate_components_length = validator("components", allow_reuse=True, always=True)(validate_min_length)
_validate_layout = validator("layout", allow_reuse=True, always=True)(set_layout)

Expand Down
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/models/_models_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def validate_min_length(cls, field):
return field


def validate_components_type(cls, field):
def check_captured_callable(cls, field):
mode_to_error = {
"figure": "A callable of mode `figure` has been provided. Please wrap it inside the `vm.Figure(figure=...)`.",
"table": "A callable of mode `table` has been provided. Please wrap it inside the `vm.Table(figure=...)`.",
Expand Down
4 changes: 2 additions & 2 deletions vizro-core/src/vizro/models/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from vizro.models import Action, Layout, VizroBaseModel
from vizro.models._action._actions_chain import ActionsChain, Trigger
from vizro.models._layout import set_layout
from vizro.models._models_utils import _log_call, validate_components_type, validate_min_length
from vizro.models._models_utils import _log_call, check_captured_callable, validate_min_length

from .types import ComponentType, ControlType

Expand Down Expand Up @@ -52,7 +52,7 @@ class Page(VizroBaseModel):
actions: List[ActionsChain] = []

# Re-used validators
_validate_components_type = validator("components", allow_reuse=True, always=True, pre=True)(validate_components_type)
_check_captured_callable = validator("components", allow_reuse=True, always=True, pre=True)(check_captured_callable)
_validate_components_length = validator("components", allow_reuse=True, always=True)(validate_min_length)
_validate_layout = validator("layout", allow_reuse=True, always=True)(set_layout)

Expand Down
2 changes: 1 addition & 1 deletion vizro-core/tests/unit/vizro/models/test_models_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_validate_min_length(self, model_with_layout):
with pytest.raises(ValidationError, match="Ensure this value has at least 1 item."):
model_with_layout(title="Title", components=[])

def test_validate_components_type(self, model_with_layout, standard_px_chart):
def test_check_captured_callable(self, model_with_layout, standard_px_chart):
with pytest.raises(
ValidationError,
match="A callable of mode `graph` has been provided. " "Please wrap it inside the `vm.Graph(figure=...)`.",
Expand Down

0 comments on commit 9806db5

Please sign in to comment.