Exemple #1
0
def test_parser_parse_populates_internal_dict():
    parser = CronParser("1 2 3 4 5", "command")
    parser.parse()

    assert parser._parsed_values == {
        "minute": {1},
        "hour": {2},
        "day of month": {3},
        "month": {4},
        "day of week": {5},
    }
Exemple #2
0
def test_parser_parse_replaces_first_instance_of_month_strings_with_number_representation(monkeypatch):
    monkeypatch.setattr(cronus.parser, "parse_section", mock.Mock())

    parser = CronParser("1 2 3 JANJAN 5", "command")
    parser.parse()

    assert cronus.parser.parse_section.call_args_list == [
        mock.call("1", 0, 59),
        mock.call("2", 0, 23),
        mock.call("3", 0, 30, True),
        mock.call("1JAN", 0, 11, True),
        mock.call("5", 0, 6),
    ]
Exemple #3
0
def test_parser_parse_parses_correct_sections(monkeypatch):
    monkeypatch.setattr(cronus.parser, "parse_section", mock.Mock())

    parser = CronParser("1 2 3 4 5", "command")
    parser.parse()

    assert cronus.parser.parse_section.call_args_list == [
        mock.call("1", 0, 59),
        mock.call("2", 0, 23),
        mock.call("3", 0, 30, True),
        mock.call("4", 0, 11, True),
        mock.call("5", 0, 6),
    ]
Exemple #4
0
def test_parser_render_with_wrapped_range():
    mock_stdout = io.StringIO()

    parser = CronParser("*/15 0 20-3/2 * 1-5", "/usr/bin/find")
    parser.parse()
    with mock.patch("sys.stdout", mock_stdout):
        parser.render()

    assert mock_stdout.getvalue().split("\n")[:-1] == [
        "minute          0 15 30 45",
        "hour            0",
        "day of month    1 3 21 23 25 27 29 31",
        "month           1 2 3 4 5 6 7 8 9 10 11 12",
        "day of week     1 2 3 4 5",
        "command         /usr/bin/find",
    ]
Exemple #5
0
def test_parser_render_example_with_strings():
    mock_stdout = io.StringIO()

    parser = CronParser("*/15 0 1,15 * MON-FRI", "/usr/bin/find")
    parser.parse()
    with mock.patch("sys.stdout", mock_stdout):
        parser.render()

    assert mock_stdout.getvalue().split("\n")[:-1] == [
        "minute          0 15 30 45",
        "hour            0",
        "day of month    1 15",
        "month           1 2 3 4 5 6 7 8 9 10 11 12",
        "day of week     1 2 3 4 5",
        "command         /usr/bin/find",
    ]
Exemple #6
0
def test_parser_render():
    mock_stdout = io.StringIO()

    parser = CronParser("1 2 3 4 5", "command")
    parser.parse()
    with mock.patch("sys.stdout", mock_stdout):
        parser.render()

    assert mock_stdout.getvalue().split("\n")[:-1] == [
        "minute          1",
        "hour            2",
        "day of month    3",
        "month           4",
        "day of week     5",
        "command         command",
    ]
Exemple #7
0
def test_parser_parse_with_invalid_strings_raises_syntax_error():
    parser = CronParser("*/15 0 1,15 * MONMON", "/usr/bin/find")
    with pytest.raises(SyntaxError) as exc:
        parser.parse()

    assert str(exc.value) == "Invalid range"
Exemple #8
0
def test_parser_parse_raises_on_invalid_crontab(monkeypatch):
    parser = CronParser("1 2 3 4 5 6", "command")
    with pytest.raises(SyntaxError) as exc:
        parser.parse()

    assert str(exc.value) == "Invalid crontab"