rewrite test
This commit is contained in:
+14
-63
@@ -5,7 +5,6 @@ import datetime
|
|||||||
from rota.workers import NonWorkingDays, NotAvailableToWork, Worker, generate_not_available_to_works
|
from rota.workers import NonWorkingDays, NotAvailableToWork, Worker, generate_not_available_to_works
|
||||||
from rota.workers import WorkRequests
|
from rota.workers import WorkRequests
|
||||||
|
|
||||||
|
|
||||||
def generate_basic_rota(
|
def generate_basic_rota(
|
||||||
weeks_to_rota=10, workers=0, start_date=datetime.date(2022, 3, 7)
|
weeks_to_rota=10, workers=0, start_date=datetime.date(2022, 3, 7)
|
||||||
):
|
):
|
||||||
@@ -25,9 +24,7 @@ def generate_basic_rota(
|
|||||||
|
|
||||||
return Rota
|
return Rota
|
||||||
|
|
||||||
|
def test_no_workers():
|
||||||
class TestWorkers:
|
|
||||||
def test_no_workers(self):
|
|
||||||
"""Check error raised if attempt to solve with no workers"""
|
"""Check error raised if attempt to solve with no workers"""
|
||||||
Rota = generate_basic_rota()
|
Rota = generate_basic_rota()
|
||||||
|
|
||||||
@@ -52,7 +49,7 @@ class TestWorkers:
|
|||||||
with pytest.raises(NoWorkers):
|
with pytest.raises(NoWorkers):
|
||||||
Rota.build_and_solve(solve=False)
|
Rota.build_and_solve(solve=False)
|
||||||
|
|
||||||
def test_workers_duplicate_name(self):
|
def test_workers_duplicate_name():
|
||||||
Rota = generate_basic_rota()
|
Rota = generate_basic_rota()
|
||||||
|
|
||||||
workers = []
|
workers = []
|
||||||
@@ -77,7 +74,7 @@ class TestWorkers:
|
|||||||
with pytest.raises(WarningTermination):
|
with pytest.raises(WarningTermination):
|
||||||
Rota.build_and_solve(solve=False)
|
Rota.build_and_solve(solve=False)
|
||||||
|
|
||||||
def test_worker_ftes(self):
|
def test_worker_ftes():
|
||||||
weeks_to_rota = 10
|
weeks_to_rota = 10
|
||||||
start_date = datetime.date(2022, 3, 7)
|
start_date = datetime.date(2022, 3, 7)
|
||||||
|
|
||||||
@@ -87,9 +84,7 @@ class TestWorkers:
|
|||||||
)
|
)
|
||||||
|
|
||||||
worker1_end_date = start_date + datetime.timedelta(weeks=weeks_to_rota / 2)
|
worker1_end_date = start_date + datetime.timedelta(weeks=weeks_to_rota / 2)
|
||||||
|
|
||||||
worker2_start_date = start_date + datetime.timedelta(weeks=weeks_to_rota / 2)
|
worker2_start_date = start_date + datetime.timedelta(weeks=weeks_to_rota / 2)
|
||||||
|
|
||||||
worker3_start_date = start_date + datetime.timedelta(weeks=weeks_to_rota / 4)
|
worker3_start_date = start_date + datetime.timedelta(weeks=weeks_to_rota / 4)
|
||||||
worker3_end_date = start_date + datetime.timedelta(weeks=3 * weeks_to_rota / 4)
|
worker3_end_date = start_date + datetime.timedelta(weeks=3 * weeks_to_rota / 4)
|
||||||
|
|
||||||
@@ -195,7 +190,7 @@ class TestWorkers:
|
|||||||
|
|
||||||
Rota.export_rota_to_html("worker_ftes")
|
Rota.export_rota_to_html("worker_ftes")
|
||||||
|
|
||||||
def test_worker_oops(self):
|
def test_worker_oops():
|
||||||
weeks_to_rota = 10
|
weeks_to_rota = 10
|
||||||
start_date = datetime.date(2022, 3, 7)
|
start_date = datetime.date(2022, 3, 7)
|
||||||
|
|
||||||
@@ -332,7 +327,7 @@ class TestWorkers:
|
|||||||
|
|
||||||
Rota.export_rota_to_html("worker_oops")
|
Rota.export_rota_to_html("worker_oops")
|
||||||
|
|
||||||
def test_worker_pairs(self):
|
def test_worker_pairs():
|
||||||
Rota = generate_basic_rota()
|
Rota = generate_basic_rota()
|
||||||
|
|
||||||
Rota.add_shifts(
|
Rota.add_shifts(
|
||||||
@@ -405,7 +400,7 @@ class TestWorkers:
|
|||||||
assert Rota.results.solver.status == "ok"
|
assert Rota.results.solver.status == "ok"
|
||||||
assert Rota.get_workers_total_shifts()["worker3"] == 50
|
assert Rota.get_workers_total_shifts()["worker3"] == 50
|
||||||
|
|
||||||
def test_not_available_to_work(self):
|
def test_not_available_to_work():
|
||||||
Rota = generate_basic_rota()
|
Rota = generate_basic_rota()
|
||||||
|
|
||||||
Rota.add_shifts(
|
Rota.add_shifts(
|
||||||
@@ -448,9 +443,7 @@ class TestWorkers:
|
|||||||
Rota.get_worker_by_name("worker2")
|
Rota.get_worker_by_name("worker2")
|
||||||
).endswith("-")
|
).endswith("-")
|
||||||
|
|
||||||
|
def test_worker_ftes_2():
|
||||||
class TestWorkerFtes:
|
|
||||||
def test_worker_ftes(self):
|
|
||||||
Rota = generate_basic_rota(workers=2)
|
Rota = generate_basic_rota(workers=2)
|
||||||
|
|
||||||
Rota.add_workers(
|
Rota.add_workers(
|
||||||
@@ -500,7 +493,7 @@ class TestWorkerFtes:
|
|||||||
assert worker.get_fte() == 40
|
assert worker.get_fte() == 40
|
||||||
assert total_shifts[worker.name] == 8
|
assert total_shifts[worker.name] == 8
|
||||||
|
|
||||||
def test_worker_fte_shift_override(self):
|
def test_worker_fte_shift_override():
|
||||||
Rota = generate_basic_rota(workers=1)
|
Rota = generate_basic_rota(workers=1)
|
||||||
|
|
||||||
Rota.add_workers(
|
Rota.add_workers(
|
||||||
@@ -548,8 +541,7 @@ class TestWorkerFtes:
|
|||||||
assert worker.get_fte("b") == 50
|
assert worker.get_fte("b") == 50
|
||||||
assert total_shifts[worker.name] == 20
|
assert total_shifts[worker.name] == 20
|
||||||
|
|
||||||
class TestComplexWorkers:
|
def test_worker_requirement_and_force_block():
|
||||||
def test_worker_requirement_and_force_block(self):
|
|
||||||
Rota = generate_basic_rota(workers=10, weeks_to_rota=10)
|
Rota = generate_basic_rota(workers=10, weeks_to_rota=10)
|
||||||
|
|
||||||
wr = [
|
wr = [
|
||||||
@@ -608,33 +600,19 @@ class TestComplexWorkers:
|
|||||||
|
|
||||||
Rota.export_rota_to_html("test_worker_complex")
|
Rota.export_rota_to_html("test_worker_complex")
|
||||||
|
|
||||||
#total_shifts = Rota.get_workers_total_shifts()
|
|
||||||
#for worker in Rota.get_workers():
|
|
||||||
# match worker.name:
|
|
||||||
# case "worker1":
|
|
||||||
# assert worker.get_fte() == 100
|
|
||||||
# assert total_shifts[worker.name] == 30
|
|
||||||
# assert worker.get_fte("b") == 100
|
|
||||||
# case "worker2":
|
|
||||||
# assert worker.get_fte() == 100
|
|
||||||
# assert worker.get_fte("b") == 50
|
|
||||||
# assert total_shifts[worker.name] == 20
|
|
||||||
#total_shifts = Rota.get_workers_total_shifts()
|
|
||||||
assert Rota.results.solver.status == "ok"
|
assert Rota.results.solver.status == "ok"
|
||||||
for worker in Rota.get_workers():
|
for worker in Rota.get_workers():
|
||||||
shift_string = Rota.get_worker_shift_list_string(worker)
|
shift_string = Rota.get_worker_shift_list_string(worker)
|
||||||
assert shift_string.count("cccc") == shift_string.count("c") / 4
|
assert shift_string.count("cccc") == shift_string.count("c") / 4
|
||||||
assert shift_string.count("ddd") == shift_string.count("d") / 3
|
assert shift_string.count("ddd") == shift_string.count("d") / 3
|
||||||
|
|
||||||
def test_split_shift(self):
|
def test_split_shift():
|
||||||
Rota = generate_basic_rota(workers=11, weeks_to_rota=22)
|
Rota = generate_basic_rota(workers=11, weeks_to_rota=22)
|
||||||
|
|
||||||
Rota.set_rota_constraint("max_shifts_per_week", 2)
|
Rota.set_rota_constraint("max_shifts_per_week", 2)
|
||||||
Rota.set_rota_constraint("max_weekend_frequency", 3)
|
Rota.set_rota_constraint("max_weekend_frequency", 3)
|
||||||
Rota.set_rota_constraint("max_shifts_per_month", 4)
|
Rota.set_rota_constraint("max_shifts_per_month", 4)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Rota.add_shifts(
|
Rota.add_shifts(
|
||||||
SingleShift(
|
SingleShift(
|
||||||
sites=("group1", "group2"),
|
sites=("group1", "group2"),
|
||||||
@@ -678,18 +656,14 @@ class TestComplexWorkers:
|
|||||||
Rota.export_rota_to_html("test_split")
|
Rota.export_rota_to_html("test_split")
|
||||||
assert Rota.results.solver.status == "ok"
|
assert Rota.results.solver.status == "ok"
|
||||||
|
|
||||||
|
def test_locums_basic():
|
||||||
class TestLocums:
|
|
||||||
def test_locums_basic(self):
|
|
||||||
Rota = generate_basic_rota(workers=2, weeks_to_rota=6)
|
Rota = generate_basic_rota(workers=2, weeks_to_rota=6)
|
||||||
|
|
||||||
la = []
|
la = []
|
||||||
for date in Rota.get_date_range(end_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
for date in Rota.get_date_range(end_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
||||||
#for date in Rota.get_date_range():
|
|
||||||
la.append(WorkRequests(date=date, shift="*"))
|
la.append(WorkRequests(date=date, shift="*"))
|
||||||
la2 = []
|
la2 = []
|
||||||
for date in Rota.get_date_range(start_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
for date in Rota.get_date_range(start_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
||||||
#for date in Rota.get_date_range():
|
|
||||||
la2.append(WorkRequests(date=date, shift="*"))
|
la2.append(WorkRequests(date=date, shift="*"))
|
||||||
|
|
||||||
Rota.add_workers(
|
Rota.add_workers(
|
||||||
@@ -731,7 +705,7 @@ class TestLocums:
|
|||||||
for worker in Rota.get_workers():
|
for worker in Rota.get_workers():
|
||||||
assert Rota.get_worker_shift_list(worker).count("a") == 4
|
assert Rota.get_worker_shift_list(worker).count("a") == 4
|
||||||
|
|
||||||
def test_locums_nwds(self):
|
def test_locums_nwds():
|
||||||
Rota = generate_basic_rota(workers=2, weeks_to_rota=6)
|
Rota = generate_basic_rota(workers=2, weeks_to_rota=6)
|
||||||
|
|
||||||
la = []
|
la = []
|
||||||
@@ -745,8 +719,6 @@ class TestLocums:
|
|||||||
[
|
[
|
||||||
Worker(name="worker03", site="group1", locum=False, locum_availability=la, locum_max_shifts=40, locum_max_shifts_per_week=1, nwds=[NonWorkingDays(day="Tue")]),
|
Worker(name="worker03", site="group1", locum=False, locum_availability=la, locum_max_shifts=40, locum_max_shifts_per_week=1, nwds=[NonWorkingDays(day="Tue")]),
|
||||||
Worker(name="worker04", site="group1", locum=False, locum_availability=la2, locum_max_shifts=40, locum_max_shifts_per_week=2, nwds=[NonWorkingDays(day="Wed"),NonWorkingDays(day="Thu")]),
|
Worker(name="worker04", site="group1", locum=False, locum_availability=la2, locum_max_shifts=40, locum_max_shifts_per_week=2, nwds=[NonWorkingDays(day="Wed"),NonWorkingDays(day="Thu")]),
|
||||||
#Worker(name="worker03", site="group1", locum=False, locum_availability=la, locum_max_shifts=40, locum_max_shifts_per_week=1, nwds=[NonWorkingDays(day="Mon"),NonWorkingDays(day="Tue")]),
|
|
||||||
#Worker(name="worker04", site="group1", locum=False, locum_availability=la2, locum_max_shifts=40, locum_max_shifts_per_week=2, nwds=[NonWorkingDays(day="Wed"),NonWorkingDays(day="Thu")]),
|
|
||||||
Worker(name="locum1", site="group1", locum=True),
|
Worker(name="locum1", site="group1", locum=True),
|
||||||
Worker(
|
Worker(
|
||||||
name="locum2", site="group1", locum=True
|
name="locum2", site="group1", locum=True
|
||||||
@@ -769,10 +741,8 @@ class TestLocums:
|
|||||||
]
|
]
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
#Rota.set_rota_constraint("distribute_locum_shifts", True)
|
|
||||||
Rota.set_rota_constraint("maximum_allowed_shift_diff", 0)
|
Rota.set_rota_constraint("maximum_allowed_shift_diff", 0)
|
||||||
Rota.set_rota_constraint("maximum_allowed_locum_shifts_per_worker", 4)
|
Rota.set_rota_constraint("maximum_allowed_locum_shifts_per_worker", 4)
|
||||||
#Rota.set_rota_constraint("minimum_allowed_locum_shifts_per_worker", 3)
|
|
||||||
|
|
||||||
Rota.build_and_solve()
|
Rota.build_and_solve()
|
||||||
|
|
||||||
@@ -787,15 +757,11 @@ class TestLocums:
|
|||||||
if worker.name in ("worker03", "worker04"):
|
if worker.name in ("worker03", "worker04"):
|
||||||
assert Rota.get_worker_shift_list(worker, include_locums=True).count("a") > 6
|
assert Rota.get_worker_shift_list(worker, include_locums=True).count("a") > 6
|
||||||
|
|
||||||
def test_locums_no_availablity(self):
|
def test_locums_no_availablity():
|
||||||
Rota = generate_basic_rota(workers=2, weeks_to_rota=5)
|
Rota = generate_basic_rota(workers=2, weeks_to_rota=5)
|
||||||
|
|
||||||
la = []
|
la = []
|
||||||
#for date in Rota.get_date_range(end_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
|
||||||
# la.append(WorkRequests(date=date, shift="*"))
|
|
||||||
la2 = []
|
la2 = []
|
||||||
#for date in Rota.get_date_range(start_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
|
||||||
# la2.append(WorkRequests(date=date, shift="*"))
|
|
||||||
|
|
||||||
Rota.add_workers(
|
Rota.add_workers(
|
||||||
[
|
[
|
||||||
@@ -828,22 +794,18 @@ class TestLocums:
|
|||||||
with pytest.raises(WarningTermination):
|
with pytest.raises(WarningTermination):
|
||||||
Rota.build_and_solve()
|
Rota.build_and_solve()
|
||||||
|
|
||||||
|
def test_locums():
|
||||||
|
|
||||||
def test_locums(self):
|
|
||||||
Rota = generate_basic_rota(workers=7, weeks_to_rota=10)
|
Rota = generate_basic_rota(workers=7, weeks_to_rota=10)
|
||||||
|
|
||||||
Rota.set_rota_constraint("max_shifts_per_week", 2)
|
Rota.set_rota_constraint("max_shifts_per_week", 2)
|
||||||
Rota.set_rota_constraint("max_weekend_frequency", 3)
|
Rota.set_rota_constraint("max_weekend_frequency", 3)
|
||||||
Rota.set_rota_constraint("max_shifts_per_month", 4)
|
Rota.set_rota_constraint("max_shifts_per_month", 4)
|
||||||
#Rota.set_rota_constraint("balance_shifts", False)
|
|
||||||
Rota.set_rota_constraint("distribute_locum_shifts", True)
|
Rota.set_rota_constraint("distribute_locum_shifts", True)
|
||||||
Rota.set_rota_constraint("maximum_allowed_shift_diff", 1)
|
Rota.set_rota_constraint("maximum_allowed_shift_diff", 1)
|
||||||
Rota.set_rota_constraint("maximum_allowed_locum_shifts_per_worker", 6)
|
Rota.set_rota_constraint("maximum_allowed_locum_shifts_per_worker", 6)
|
||||||
|
|
||||||
Rota.terminate_on_warning.remove("Worker/no valid shifts")
|
Rota.terminate_on_warning.remove("Worker/no valid shifts")
|
||||||
|
|
||||||
|
|
||||||
la = []
|
la = []
|
||||||
for date in Rota.get_date_range(end_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
for date in Rota.get_date_range(end_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
||||||
la.append(WorkRequests(date=date, shift="*"))
|
la.append(WorkRequests(date=date, shift="*"))
|
||||||
@@ -851,7 +813,6 @@ class TestLocums:
|
|||||||
for date in Rota.get_date_range(start_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
for date in Rota.get_date_range(start_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
||||||
la2.append(WorkRequests(date=date, shift="*"))
|
la2.append(WorkRequests(date=date, shift="*"))
|
||||||
|
|
||||||
|
|
||||||
Rota.add_workers(
|
Rota.add_workers(
|
||||||
[
|
[
|
||||||
Worker(name="worker08", site="group1", locum=False, locum_availability=la, locum_max_shifts=40, locum_max_shifts_per_week=1),
|
Worker(name="worker08", site="group1", locum=False, locum_availability=la, locum_max_shifts=40, locum_max_shifts_per_week=1),
|
||||||
@@ -860,19 +821,9 @@ class TestLocums:
|
|||||||
Worker(
|
Worker(
|
||||||
name="locum2", site="group1", locum=True
|
name="locum2", site="group1", locum=True
|
||||||
),
|
),
|
||||||
#Worker(
|
|
||||||
# name="extra1", site="locum", locum_availability=la,
|
|
||||||
# locum_max_shifts=40
|
|
||||||
#),
|
|
||||||
#Worker(
|
|
||||||
# name="extra2", site="locum", locum_availability=la,
|
|
||||||
# locum_max_shifts=4, locum_max_shifts_per_week=1
|
|
||||||
#),
|
|
||||||
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
Rota.add_shifts(
|
Rota.add_shifts(
|
||||||
SingleShift(
|
SingleShift(
|
||||||
sites=("group1", "group2"),
|
sites=("group1", "group2"),
|
||||||
|
|||||||
Reference in New Issue
Block a user