Пример #1
0
def test_parsing_invalid_output():
    with pytest.raises(InvalidInputs):
        parse_args([
            "--config",
            "tests/test_files/invalid_evaluation_cli/config.json",
            "--history",
            "tests/test_files/invalid_evaluation_cli/history.json",
            "--output",
            "tests/test_files/invalid_evaluation_cli/output.json",
            "--evaluate",
        ])
Пример #2
0
def test_parsing_output():
    inputs = parse_args([
        "--config",
        "tests/test_files/cli/config.json",
        "--history",
        "tests/test_files/cli/history.json",
        "--output",
        "tests/test_files/cli/output.json",
        "--evaluate",
    ])

    assert inputs.output_path == "tests/test_files/cli/output.json"
    assert inputs.output == [
        AssignedShift(
            person=Person("Admiral Ackbar"),
            day=date(2019, 11, 29),
            name="ops",
            shift_type=ShiftType.STANDARD,
        ),
        AssignedShift(
            person=Person("Admiral Ackbar"),
            day=date(2019, 11, 30),
            name="ops",
            shift_type=ShiftType.STANDARD,
        ),
        AssignedShift(
            person=Person("Admiral Ackbar"),
            day=date(2019, 12, 1),
            name="ops",
            shift_type=ShiftType.SPECIAL_A,
        ),
    ]
Пример #3
0
def main() -> None:
    inputs = parse_args()
    configure_logging(inputs.verbose)
    config = Config.build(
        people=inputs.people,
        max_shifts_per_person=inputs.max_shifts_per_person,
        shifts_by_day=inputs.shifts_by_day,
        history=inputs.history,
    )

    if inputs.evaluate:
        evaluation_mode(inputs, config)
    else:
        solving_mode(inputs, config)
Пример #4
0
def test_solution_when_all_constraints_cannot_be_satisfied():
    config_file_path = "tests/test_files/no_solution/config.json"
    history_file_path = "tests/test_files/no_solution/history.json"
    inputs = parse_args(
        ["--config", config_file_path, "--history", history_file_path])

    config = Config.build(
        people=inputs.people,
        max_shifts_per_person=inputs.max_shifts_per_person,
        shifts_by_day=inputs.shifts_by_day,
        history=inputs.history,
    )
    solution = solve(
        config=config,
        objective=inputs.objective,
        constraints=inputs.constraints,
    )
    assert len(list(solution)) == 2
Пример #5
0
def test_parsing_inputs():
    inputs = parse_args([
        "--config",
        "tests/test_files/cli/config.json",
        "--history",
        "tests/test_files/cli/history.json",
    ])

    assert set(inputs.people) == {
        Person(name="Admiral Ackbar"),
        Person(name="Mon Mothma"),
    }
    assert inputs.shifts_by_day == {
        date(2019, 11, 29): [
            Shift(day=date(2019, 11, 29),
                  name="ops",
                  shift_type=ShiftType.STANDARD)
        ],
        date(2019, 11, 30): [
            Shift(day=date(2019, 11, 30),
                  name="ops",
                  shift_type=ShiftType.STANDARD)
        ],
        date(2019, 12, 1): [
            Shift(day=date(2019, 12, 1),
                  name="ops",
                  shift_type=ShiftType.SPECIAL_A)
        ],
    }
    assert inputs.constraints == [
        EachPersonWorksAtMostXShiftsPerAssignmentPeriod(priority=0, x=1),
        ThereShouldBeAtLeastXDaysBetweenOps(priority=1, x=4),
        RespectPersonRestrictionsPerShiftType(
            priority=2,
            forbidden_by_shift_type={"special_a": ["Admiral Ackbar"]}),
        RespectPersonRestrictionsPerDay(
            priority=3,
            name="Holidays",
            restrictions={"Admiral Ackbar": ["2019-11-01"]}),
    ]
    assert inputs.history.past_shifts == (
        AssignedShift(
            person=Person("Admiral Ackbar"),
            day=date(2019, 11, 28),
            name="ops",
            shift_type=ShiftType.SPECIAL_A,
        ),
        AssignedShift(
            person=Person("Admiral Ackbar"),
            day=date(2019, 11, 27),
            name="ops",
            shift_type=ShiftType.SPECIAL_B,
        ),
        AssignedShift(
            person=Person("Admiral Ackbar"),
            day=date(2019, 11, 26),
            name="ops",
            shift_type=ShiftType.STANDARD,
        ),
        AssignedShift(
            person=Person("Mon Mothma"),
            day=date(2019, 11, 25),
            name="ops",
            shift_type=ShiftType.STANDARD,
        ),
        AssignedShift(
            person=Person("Mon Mothma"),
            day=date(2019, 11, 24),
            name="ops",
            shift_type=ShiftType.STANDARD,
        ),
        AssignedShift(
            person=Person("Admiral Ackbar"),
            day=date(2019, 11, 23),
            name="ops",
            shift_type=ShiftType.STANDARD,
        ),
    )
    assert inputs.output_path is None
    assert inputs.output is None