Refactor shift constraints in tests to use new constraint classes

- Updated test cases in `test_workers.py` to replace dictionary-based constraints with instances of `PreShiftConstraint`, `PostShiftConstraint`, and `MaxShiftsPerWeekConstraint`.
- Added a new test `test_worker_assign_as_block_preference2` to verify worker preferences for block assignments.
- Marked tests as slow where appropriate to improve test suite performance.
This commit is contained in:
Ross
2025-08-11 13:03:08 +01:00
parent d7bcfce78c
commit 76f3b48c1d
12 changed files with 790 additions and 987 deletions
+5 -5
View File
@@ -1,6 +1,6 @@
import pytest
import datetime
from rota.shifts import RotaBuilder, SingleShift, days
from rota.shifts import NightConstraint, RotaBuilder, SingleShift, days
from rota.workers import Worker
@pytest.fixture
@@ -45,7 +45,7 @@ def test_basic_assignment(demo_rota_night_unavailable):
name="night_weekend",
length=12.5,
days=days[5:],
constraint=[{"name": "night"}],
constraints=[NightConstraint()],
),
)
Rota.build_and_solve(options={"ratio": 0.00})
@@ -66,7 +66,7 @@ def test_assign_night_prior_to_unavailablity(demo_rota_night_unavailable):
length=12.5,
days=days[5:],
workers_required=2,
constraint=[{"name": "night"}],
constraints=[NightConstraint()],
),
)
Rota.build_and_solve(options={"ratio": 0.00})
@@ -101,7 +101,7 @@ def test_assign_prior_to_unavailablity_non_night(demo_rota_night_unavailable):
length=12.5,
days=days[5:],
workers_required=2,
constraint=[],
constraints=[],
),
)
Rota.build_and_solve(options={"ratio": 0.00})
@@ -135,7 +135,7 @@ def test_assign_split(demo_rota_night_unavailable):
length=12.5,
days=days[5:],
workers_required=3,
constraint=[],
constraints=[],
),
)
Rota.build_and_solve(options={"ratio": 0.00})