From d849dbf1a1ba19eab3ae92b870ae635335787396 Mon Sep 17 00:00:00 2001 From: Erkan Ozgur Yilmaz Date: Thu, 30 Jan 2025 14:31:52 +0000 Subject: [PATCH] [#149] Updated type decorators under `stalker.models.enum` to set the `cache_ok=True`. --- src/stalker/VERSION | 2 +- src/stalker/models/enum.py | 4 ++++ tests/models/test_dependency_target.py | 7 ++++++- tests/models/test_schedule_constraint.py | 7 ++++++- tests/models/test_schedule_model.py | 7 ++++++- tests/models/test_time_unit.py | 7 ++++++- 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/stalker/VERSION b/src/stalker/VERSION index 1cc5f657..fc18cb64 100644 --- a/src/stalker/VERSION +++ b/src/stalker/VERSION @@ -1 +1 @@ -1.1.0 \ No newline at end of file +1.1.1.dev0 \ No newline at end of file diff --git a/src/stalker/models/enum.py b/src/stalker/models/enum.py index 2729add4..fda70ba2 100644 --- a/src/stalker/models/enum.py +++ b/src/stalker/models/enum.py @@ -79,6 +79,7 @@ def to_constraint( class ScheduleConstraintDecorator(TypeDecorator): """Store ScheduleConstraint as an integer and restore as ScheduleConstraint.""" + cache_ok = True impl = Integer def process_bind_param(self, value, dialect) -> int: @@ -169,6 +170,7 @@ def to_unit(cls, unit: Union[str, "TimeUnit"]) -> "TimeUnit": class TimeUnitDecorator(TypeDecorator): """Store TimeUnit as an str and restore as TimeUnit.""" + cache_ok = True impl = saEnum(*[u.value for u in TimeUnit], name="TimeUnit") def process_bind_param(self, value: TimeUnit, dialect: str) -> str: @@ -256,6 +258,7 @@ def to_model(cls, model: Union[str, "ScheduleModel"]) -> "ScheduleModel": class ScheduleModelDecorator(TypeDecorator): """Store ScheduleModel as a str and restore as ScheduleModel.""" + cache_ok = True impl = saEnum(*[m.value for m in ScheduleModel], name="ScheduleModel") def process_bind_param(self, value, dialect) -> str: @@ -342,6 +345,7 @@ def to_target(cls, target: Union[str, "DependencyTarget"]) -> "DependencyTarget" class DependencyTargetDecorator(TypeDecorator): """Store DependencyTarget as an enum and restore as DependencyTarget.""" + cache_ok = True impl = saEnum(*[m.value for m in DependencyTarget], name="TaskDependencyTarget") def process_bind_param(self, value, dialect) -> str: diff --git a/tests/models/test_dependency_target.py b/tests/models/test_dependency_target.py index bd0ba7ef..09715237 100644 --- a/tests/models/test_dependency_target.py +++ b/tests/models/test_dependency_target.py @@ -5,7 +5,7 @@ import pytest -from stalker.models.enum import DependencyTarget +from stalker.models.enum import DependencyTarget, DependencyTargetDecorator @pytest.mark.parametrize( @@ -121,3 +121,8 @@ def test_to_target_target_is_not_a_valid_str(): def test_to_target_is_working_properly(target_name, target): """DependencyTarget can parse dependency target names.""" assert DependencyTarget.to_target(target_name) == target + + +def test_cache_ok_is_true_in_type_decorator(): + """DependencyTargetDecorator.cache_ok is True.""" + assert DependencyTargetDecorator.cache_ok is True diff --git a/tests/models/test_schedule_constraint.py b/tests/models/test_schedule_constraint.py index 3b31171d..0842bba3 100644 --- a/tests/models/test_schedule_constraint.py +++ b/tests/models/test_schedule_constraint.py @@ -5,7 +5,7 @@ import pytest -from stalker.models.enum import ScheduleConstraint +from stalker.models.enum import ScheduleConstraint, ScheduleConstraintDecorator @pytest.mark.parametrize( @@ -133,3 +133,8 @@ def test_to_constraint_constraint_is_not_a_valid_str(): def test_to_constraint_is_working_properly(constraint_name, constraint): """ScheduleConstraint can parse schedule constraint names.""" assert ScheduleConstraint.to_constraint(constraint_name) == constraint + + +def test_cache_ok_is_true_in_type_decorator(): + """ScheduleConstraintDecorator.cache_ok is True.""" + assert ScheduleConstraintDecorator.cache_ok is True diff --git a/tests/models/test_schedule_model.py b/tests/models/test_schedule_model.py index 8c02b11a..3a51b32c 100644 --- a/tests/models/test_schedule_model.py +++ b/tests/models/test_schedule_model.py @@ -5,7 +5,7 @@ import pytest -from stalker.models.enum import ScheduleModel +from stalker.models.enum import ScheduleModel, ScheduleModelDecorator @pytest.mark.parametrize( @@ -136,3 +136,8 @@ def test_to_model_model_is_not_a_valid_str(): def test_to_model_is_working_properly(model_name, model): """ScheduleModel can parse schedule model names.""" assert ScheduleModel.to_model(model_name) == model + + +def test_cache_ok_is_true_in_type_decorator(): + """ScheduleModelDecorator.cache_ok is True.""" + assert ScheduleModelDecorator.cache_ok is True diff --git a/tests/models/test_time_unit.py b/tests/models/test_time_unit.py index 7b24a11c..1da1f3ed 100644 --- a/tests/models/test_time_unit.py +++ b/tests/models/test_time_unit.py @@ -5,7 +5,7 @@ import pytest -from stalker.models.enum import TimeUnit +from stalker.models.enum import TimeUnit, TimeUnitDecorator @pytest.mark.parametrize( @@ -182,3 +182,8 @@ def test_to_unit_unit_is_not_a_valid_str(): def test_schedule_unit_to_unit_is_working_properly(unit_name, unit): """TimeUnit can parse schedule unit names.""" assert TimeUnit.to_unit(unit_name) == unit + + +def test_cache_ok_is_true_in_type_decorator(): + """TimeUnitDecorator.cache_ok is True.""" + assert TimeUnitDecorator.cache_ok is True