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:
+19
-19
@@ -1,6 +1,6 @@
|
||||
import datetime
|
||||
import pytest
|
||||
from rota.shifts import InvalidShift, NoWorkers, RotaBuilder, SingleShift, days
|
||||
from rota.shifts import InvalidShift, NightConstraint, NoWorkers, PostShiftConstraint, PreShiftConstraint, RotaBuilder, SingleShift, days
|
||||
from rota.workers import Worker
|
||||
|
||||
def generate_basic_rota(weeks_to_rota=10):
|
||||
@@ -35,7 +35,7 @@ def test_nights():
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}, {"name": "pre", "options": 2}],
|
||||
constraints=[NightConstraint(), PreShiftConstraint(days=2)],
|
||||
workers_required=2,
|
||||
),
|
||||
SingleShift(
|
||||
@@ -60,7 +60,7 @@ def test_nights_pre3():
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}, {"name": "pre", "options": 3}],
|
||||
constraints=[NightConstraint(), PreShiftConstraint(days=3)],
|
||||
workers_required=2,
|
||||
),
|
||||
SingleShift(
|
||||
@@ -84,7 +84,7 @@ def test_nights_pre3_2():
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}, {"name": "pre", "options": 3}],
|
||||
constraints=[NightConstraint(), PreShiftConstraint(days=3)],
|
||||
workers_required=1,
|
||||
),
|
||||
SingleShift(
|
||||
@@ -108,7 +108,7 @@ def test_nights_fail():
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}, {"name": "pre", "options": 3}],
|
||||
constraints=[NightConstraint(), PreShiftConstraint(days=3)],
|
||||
workers_required=2,
|
||||
),
|
||||
SingleShift(
|
||||
@@ -132,7 +132,7 @@ def test_nights2():
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
constraints=[NightConstraint()],
|
||||
workers_required=2,
|
||||
),
|
||||
SingleShift(
|
||||
@@ -158,10 +158,10 @@ def test_nights_pre_wrap_around():
|
||||
length=12.5,
|
||||
days=days[:2],
|
||||
force_as_block=True,
|
||||
constraint=[
|
||||
{"name": "night"},
|
||||
{"name": "pre", "options": 5},
|
||||
{"name": "post", "options": 5},
|
||||
constraints=[
|
||||
NightConstraint(),
|
||||
PreShiftConstraint(days=5),
|
||||
PostShiftConstraint(days=5),
|
||||
],
|
||||
workers_required=3,
|
||||
),
|
||||
@@ -195,7 +195,7 @@ def test_nights_max_frequency():
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
constraints=[NightConstraint()],
|
||||
workers_required=2,
|
||||
),
|
||||
)
|
||||
@@ -213,7 +213,7 @@ def test_nights_max_frequency_fail():
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
constraints=[NightConstraint()],
|
||||
workers_required=2,
|
||||
),
|
||||
)
|
||||
@@ -230,7 +230,7 @@ def test_nights_max_frequency3():
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
constraints=[NightConstraint()],
|
||||
workers_required=1,
|
||||
),
|
||||
SingleShift(
|
||||
@@ -239,7 +239,7 @@ def test_nights_max_frequency3():
|
||||
length=12.5,
|
||||
days=days[:5],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
constraints=[NightConstraint()],
|
||||
workers_required=1,
|
||||
),
|
||||
)
|
||||
@@ -257,7 +257,7 @@ def test_nights_max_frequency4():
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
constraints=[NightConstraint()],
|
||||
workers_required=1,
|
||||
),
|
||||
SingleShift(
|
||||
@@ -266,7 +266,7 @@ def test_nights_max_frequency4():
|
||||
length=12.5,
|
||||
days=days[:5],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
constraints=[NightConstraint()],
|
||||
workers_required=1,
|
||||
),
|
||||
)
|
||||
@@ -291,7 +291,7 @@ def test_nights_max_frequency_exclusions():
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
constraints=[NightConstraint()],
|
||||
workers_required=2,
|
||||
),
|
||||
)
|
||||
@@ -310,7 +310,7 @@ def test_nights_max_frequency_exclusions2():
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
constraints=[NightConstraint()],
|
||||
workers_required=2,
|
||||
),
|
||||
)
|
||||
@@ -346,7 +346,7 @@ def test_nights_max_frequency_exclusions3():
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
balance_offset=10,
|
||||
constraint=[{"name": "night"}],
|
||||
constraints=[NightConstraint()],
|
||||
workers_required=2,
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user