update from last round
This commit is contained in:
+27
-14
@@ -2,7 +2,8 @@ from copy import deepcopy
|
||||
from re import S
|
||||
from black import main
|
||||
import pytest
|
||||
from rota.shifts import NoWorkers, RotaBuilder, SingleShift, days
|
||||
from pytest import approx
|
||||
from rota.shifts import NoWorkers, RotaBuilder, SingleShift, WarningTermination, days
|
||||
|
||||
import datetime
|
||||
|
||||
@@ -285,14 +286,14 @@ class TestDemoRotaNights:
|
||||
worker = self.Rota.get_worker_by_name(worker_name)
|
||||
|
||||
if worker.fte == 40:
|
||||
assert worker_shifts["night_weekday"] in (0, 4)
|
||||
assert worker_shifts["night_weekend"] in (0, 3)
|
||||
assert worker_shifts["night_weekday"] in (approx(0), approx(4))
|
||||
assert worker_shifts["night_weekend"] in (approx(0), approx(3))
|
||||
elif worker.fte == 60:
|
||||
assert worker_shifts["night_weekday"] in (0, 4, 8)
|
||||
assert worker_shifts["night_weekend"] in (0, 3, 6)
|
||||
assert worker_shifts["night_weekday"] in (approx(0), approx(4), approx(8))
|
||||
assert worker_shifts["night_weekend"] in (approx(0), approx(3), approx(6))
|
||||
else:
|
||||
assert worker_shifts["night_weekday"] in (4, 8)
|
||||
assert worker_shifts["night_weekend"] in (3, 6)
|
||||
assert worker_shifts["night_weekday"] in (approx(4), approx(8))
|
||||
assert worker_shifts["night_weekend"] in (approx(3), approx(6))
|
||||
|
||||
|
||||
class TestDemoRotaClear:
|
||||
@@ -326,7 +327,7 @@ class TestDemoRotaClear:
|
||||
name="a",
|
||||
length=12.5,
|
||||
days=days[:5],
|
||||
balance_offset=40,
|
||||
#balance_offset=40,
|
||||
workers_required=2,
|
||||
constraint=[{"name": "pre", "options": 1}],
|
||||
),
|
||||
@@ -335,7 +336,7 @@ class TestDemoRotaClear:
|
||||
name="b",
|
||||
length=12.5,
|
||||
days=days[:5],
|
||||
balance_offset=40,
|
||||
#balance_offset=40,
|
||||
workers_required=2,
|
||||
),
|
||||
SingleShift(
|
||||
@@ -343,7 +344,7 @@ class TestDemoRotaClear:
|
||||
name="c",
|
||||
length=12.5,
|
||||
days=days[3],
|
||||
balance_offset=40,
|
||||
#balance_offset=40,
|
||||
workers_required=1,
|
||||
constraint=[{"name": "pre", "options": 1}, {"name": "post", "options": 1}],
|
||||
),
|
||||
@@ -481,7 +482,7 @@ class TestDemoRotaShiftConstraints:
|
||||
def test_max_shifts_fail(self):
|
||||
self.Rota.constraint_options["max_shifts_per_month"] = 13
|
||||
self.Rota.build_and_solve()
|
||||
assert self.Rota.results.solver.status == "warning"
|
||||
assert self.Rota.results.solver.status in ("warning", "error")
|
||||
assert self.Rota.results.solver.termination_condition == "infeasible"
|
||||
|
||||
def test_max_shifts_extra_worker(self):
|
||||
@@ -495,7 +496,7 @@ class TestDemoRotaShiftConstraints:
|
||||
self.Rota.constraint_options["max_shifts_per_week"] = 3
|
||||
self.Rota.build_and_solve()
|
||||
|
||||
assert self.Rota.results.solver.status == "warning"
|
||||
assert self.Rota.results.solver.status in ("warning", "error")
|
||||
assert self.Rota.results.solver.termination_condition == "infeasible"
|
||||
|
||||
def test_max_shifts_per_week_pass(self):
|
||||
@@ -550,7 +551,17 @@ class TestDemoRotaBalanceShiftSites:
|
||||
self.Rota.constraint_options["balance_nights_across_sites"] = False
|
||||
self.Rota.constraint_options["balance_nights"] = False
|
||||
self.Rota.constraint_options["constrain_time_off_after_nights"] = False
|
||||
|
||||
# Worker 5 and 6 don't have any valid shifts so this should fail
|
||||
#with pytest.raises(WarningTermination):
|
||||
# self.Rota.build_and_solve(options={"ratio": 0.0})
|
||||
|
||||
# Unless we remove the warning
|
||||
self.Rota.terminate_on_warning.remove("Worker/no valid shifts")
|
||||
self.Rota.build_and_solve(options={"ratio": 0.0})
|
||||
|
||||
assert len(self.Rota.get_warnings("Worker/no valid shifts")) == 2
|
||||
|
||||
self.Rota.export_rota_to_html("test5")
|
||||
|
||||
print(self.Rota.get_workers_by_group())
|
||||
@@ -586,6 +597,8 @@ class TestDemoRotaBalanceShiftSites:
|
||||
self.Rota.constraint_options["balance_nights_across_sites"] = False
|
||||
self.Rota.constraint_options["balance_nights"] = False
|
||||
self.Rota.constraint_options["constrain_time_off_after_nights"] = False
|
||||
|
||||
self.Rota.terminate_on_warning.remove("Worker/no valid shifts")
|
||||
self.Rota.build_and_solve(options={"ratio": 0.1})
|
||||
|
||||
group_workers = self.Rota.get_workers_by_group()
|
||||
@@ -1151,7 +1164,7 @@ class TestNightUnavailable:
|
||||
self.Rota.build_and_solve(options={"ratio": 0.00})
|
||||
self.Rota.export_rota_to_html("testnight_unavail")
|
||||
|
||||
assert self.Rota.results.solver.status == "warning"
|
||||
assert self.Rota.results.solver.status in ("warning", "error")
|
||||
assert self.Rota.results.solver.termination_condition == "infeasible"
|
||||
|
||||
def test_assign_non_night_prior_to_unavailablity(self):
|
||||
@@ -1252,7 +1265,7 @@ class TestNightUnavailable:
|
||||
#
|
||||
# self.Rota.build_and_solve(options={"ratio": 0.00})
|
||||
#
|
||||
# assert self.Rota.results.solver.status == "warning"
|
||||
# assert self.Rota.results.solver.status in ("warning", "error")
|
||||
|
||||
if __name__ == "__main__":
|
||||
t = TestLimitConstraints()
|
||||
|
||||
Reference in New Issue
Block a user