def test_next_cron_random(max_previous, kwargs, expected): for i in range(100): previous = expected - timedelta(seconds=0.9 + random() * max_previous) v = next_cron(previous, **kwargs) diff = v - previous if diff > timedelta(seconds=1): print(f'previous: {previous}, expected: {expected}, diff: {v - previous}') assert v == expected
def test_next_cron_invalid(): with pytest.raises(ValueError): next_cron(datetime(2001, 1, 1, 0, 0, 0), weekday='monday')
def test_next_cron(previous, expected, kwargs): start = datetime.now() assert next_cron(previous, **kwargs) == expected diff = datetime.now() - start print(f'{diff.total_seconds() * 1000:0.3f}ms')