Skip to content

Commit

Permalink
Merge pull request #150 from eoyilmaz/149-add-cache_ok-true-for-type-…
Browse files Browse the repository at this point in the history
…decorators

[#149] Updated type decorators under `stalker.models.enum` to set the…
  • Loading branch information
eoyilmaz authored Jan 30, 2025
2 parents e4267a2 + d849dbf commit 81cb92f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/stalker/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.1.1.dev0
4 changes: 4 additions & 0 deletions src/stalker/models/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion tests/models/test_dependency_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from stalker.models.enum import DependencyTarget
from stalker.models.enum import DependencyTarget, DependencyTargetDecorator


@pytest.mark.parametrize(
Expand Down Expand Up @@ -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
7 changes: 6 additions & 1 deletion tests/models/test_schedule_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from stalker.models.enum import ScheduleConstraint
from stalker.models.enum import ScheduleConstraint, ScheduleConstraintDecorator


@pytest.mark.parametrize(
Expand Down Expand Up @@ -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
7 changes: 6 additions & 1 deletion tests/models/test_schedule_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from stalker.models.enum import ScheduleModel
from stalker.models.enum import ScheduleModel, ScheduleModelDecorator


@pytest.mark.parametrize(
Expand Down Expand Up @@ -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
7 changes: 6 additions & 1 deletion tests/models/test_time_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from stalker.models.enum import TimeUnit
from stalker.models.enum import TimeUnit, TimeUnitDecorator


@pytest.mark.parametrize(
Expand Down Expand Up @@ -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

0 comments on commit 81cb92f

Please sign in to comment.