Beispiel #1
0
async def test_next_moment_ok_latest_day():
    for m, d in enumerate(DAYS[:11], 1):
        assert next_moment(cron_parser('0 0 1 * *'), datetime(year=YEAR, month=m, day=d)
            ) == datetime(year=YEAR, month=m + 1, day=1)

    assert next_moment(cron_parser('0 0 1 * *'), datetime(year=YEAR, month=12, day=31)
        ) == datetime(year=YEAR + 1, month=1, day=1)
Beispiel #2
0
async def test_CRONTask_call_ok():
    task = CRONTask(agent=MagicMock(), handler=Handler(),
        cron=cron_parser('* * * * *'), timeout=1)
    assert 'CRONTask' in str(task)
    assert 0 < task.start_after < 60

    await task.call()
    task.handler.assert_called()

    task = CRONTask(agent=MagicMock(), handler=Handler(),
        cron=cron_parser('* * * * *'), timeout=1)
    assert int(task.start_after) == int(task.period)
Beispiel #3
0
async def test_cron_parser_ok():
    assert cron_parser('10,20 * * * *').minutes == [10, 20]
    assert cron_parser('15-20 * * * *').minutes == [15, 16, 17, 18, 19, 20]
    assert cron_parser('15-45/5 * * * *').minutes == [15, 20, 25, 30, 35, 40, 45]
    assert cron_parser('*/15 * * * *').minutes == [0, 15, 30, 45]
    assert cron_parser('* */3 * * *').hours == [0, 3, 6, 9, 12, 15, 18, 21]
    assert cron_parser('* * 6-20/5 * *').days == [10, 15, 20]
    assert cron_parser('* * 6-19/5 * *').days == [10, 15]
    assert cron_parser('* * * */3 *').months == [3, 6, 9, 12]
Beispiel #4
0
async def test_next_moment_ok_range_with_steps():
    now = datetime(year=YEAR, month=5, day=15, hour=16, minute=17, second=1)
    assert next_moment(cron_parser('5-20/5 * * * *'), now) == datetime(
        year=now.year, month=now.month, day=now.day, hour=now.hour, minute=20)
Beispiel #5
0
async def test_next_moment_ok_list():
    now = datetime(year=YEAR, month=5, day=15, hour=16, minute=17, second=1)
    assert next_moment(cron_parser('10,20 * * * *'), now) == datetime(
        year=now.year, month=now.month, day=now.day, hour=now.hour, minute=20)
Beispiel #6
0
async def test_next_moment_ok_every_minute():
    now = datetime(year=YEAR, month=5, day=15, hour=16, minute=17, second=18)

    with pytest.raises(ValueError):
        while True:
            now = next_moment(cron_parser('* * * * *'), now) + timedelta(microseconds=1)
Beispiel #7
0
async def test_next_moment_fail():
    with pytest.raises(ValueError):
        assert next_moment(cron_parser('0 0 2 31 *'), datetime.now())
Beispiel #8
0
async def test_next_moment_ok_month_last():
    now = datetime(year=YEAR, month=12, day=31, hour=16, minute=17)
    assert next_moment(cron_parser('0 0 * * *'), now) == datetime(
        year=now.year + 1, month=1, day=1, hour=0, minute=0)
Beispiel #9
0
async def test_next_moment_ok_year():
    now = datetime(year=YEAR, month=5, day=15, hour=16, minute=17)
    assert next_moment(cron_parser(f'0 0 1 {now.month - 1} *'), now) == datetime(
        year=now.year + 1, month=now.month - 1, day=1, hour=0, minute=0)
Beispiel #10
0
async def test_next_moment_ok_week():
    n = datetime(year=YEAR, month=5, day=15, hour=16, minute=17)
    assert next_moment(cron_parser(f'0 0 * * {n.weekday()}'), n - timedelta(days=1)) == datetime(
        year=n.year, month=n.month, day=n.day, hour=0, minute=0)
Beispiel #11
0
async def test_next_moment_ok_day():
    now = datetime(year=YEAR, month=5, day=15, hour=16, minute=17)
    assert next_moment(cron_parser(f'0 {now.hour - 1} * * *'), now) == datetime(
        year=now.year, month=now.month, day=now.day + 1, hour=now.hour - 1, minute=0)
Beispiel #12
0
async def test_next_moment_ok_hour_last():
    now = datetime(year=YEAR, month=5, day=15, hour=23, minute=17)
    assert next_moment(cron_parser('0 * * * *'), now) == datetime(
        year=now.year, month=now.month, day=now.day + 1, hour=0, minute=0)
Beispiel #13
0
async def test_next_moment_ok_minute_last():
    now = datetime(year=YEAR, month=5, day=15, hour=16, minute=59, second=1)
    assert next_moment(cron_parser('* * * * *'), now) == datetime(
        year=now.year, month=now.month, day=now.day, hour=now.hour + 1, minute=0)
Beispiel #14
0
async def test_next_moment_ok_minute():
    now = datetime(year=YEAR, month=5, day=15, hour=16, minute=17)
    assert next_moment(cron_parser('* * * * *'), now) == datetime(
        year=now.year, month=now.month, day=now.day, hour=now.hour, minute=now.minute)