Ejemplo n.º 1
0
def test_crontab_hourly():
    job = CronJob()
    job.set_crontab('@hourly')
    dt = datetime(2000, 1, 1, 1, 0, 1)
    assert job.is_runnable(dt) is True
    dt = datetime(2000, 1, 1, 0, 1, 1)
    assert job.is_runnable(dt) is False
Ejemplo n.º 2
0
def test_runnig_in_target_time_with_crontab():
    job = CronJob()
    job.set_crontab('25 * * * *')
    dt = datetime(2000, 1, 1, 1, 25, 1)
    assert job.is_runnable(dt) is True
    dt = datetime(2000, 1, 1, 0, 26, 1)
    assert job.is_runnable(dt) is False
Ejemplo n.º 3
0
def test_not_run_in_target_time():
    job = CronJob()
    job.trigger_format = '%H'
    job.trigger_time = '01'
    dt = datetime(2000, 1, 1, 1, 1, 1)
    assert job.is_runnable(dt) is True
    dt = datetime(2000, 1, 1, 0, 1, 1)
    assert job.is_runnable(dt) is False
Ejemplo n.º 4
0
def test_for_display():
    job = CronJob()
    job.set_triggers('%H', '01')
    assert str(job) == 'CronJob(trigger=[%H->01])'
    job = CronJob()
    assert str(job) == 'CronJob(trigger=[])'
    job = CronJob()
    job.set_crontab('25 * * * *')
    assert str(job) == 'CronJob(crontab=[25 * * * *])'
Ejemplo n.º 5
0
def test_polled_once(capsys):
    job1 = CronJob()
    job1.set_action('stub.print_datetime')
    job1.set_triggers('%H', '00')
    job2 = CronJob()
    job2.set_action('stub.print_datetime')
    job2.set_triggers('%H', '01')

    plugin = MockedImpl()
    plugin._crontab = [job1, job2, ]
    with freeze_time('2016-01-01 00:00:01'):
        plugin.poll_crontab()
        out, err = capsys.readouterr()
        assert out == '2016-01-01'
Ejemplo n.º 6
0
def test_for_display():
    job = CronJob()
    job.set_triggers('%H', '01')
    assert str(job) == 'CronJob(trigger=[%H->01])'
    job = CronJob()
    assert str(job) == 'CronJob(trigger=[])'
    job = CronJob()
    job.set_crontab('25 * * * *')
    assert str(job) == 'CronJob(crontab=[25 * * * *])'
Ejemplo n.º 7
0
def test_set_triggers():
    job = CronJob()
    job.set_triggers('%H', '01')
    dt = datetime(2000, 1, 1, 1, 1, 1)
    assert job.is_runnable(dt) is True
    dt = datetime(2000, 1, 1, 0, 1, 1)
    assert job.is_runnable(dt) is False
    for keys in (
        (None, '1'),
        ('1', None),
    ):
        with pytest.raises(ValueError):
            job.set_triggers(*keys)
Ejemplo n.º 8
0
def test_crontab_hourly():
    job = CronJob()
    job.set_crontab('@hourly')
    dt = datetime(2000, 1, 1, 1, 0, 1)
    assert job.is_runnable(dt) is True
    dt = datetime(2000, 1, 1, 0, 1, 1)
    assert job.is_runnable(dt) is False
Ejemplo n.º 9
0
def test_runnig_in_target_time_with_crontab():
    job = CronJob()
    job.set_crontab('25 * * * *')
    dt = datetime(2000, 1, 1, 1, 25, 1)
    assert job.is_runnable(dt) is True
    dt = datetime(2000, 1, 1, 0, 26, 1)
    assert job.is_runnable(dt) is False
Ejemplo n.º 10
0
def test_not_run_in_target_time():
    job = CronJob()
    job.trigger_format = '%H'
    job.trigger_time = '01'
    dt = datetime(2000, 1, 1, 1, 1, 1)
    assert job.is_runnable(dt) is True
    dt = datetime(2000, 1, 1, 0, 1, 1)
    assert job.is_runnable(dt) is False
Ejemplo n.º 11
0
def test_set_triggers():
    job = CronJob()
    job.set_triggers('%H', '01')
    dt = datetime(2000, 1, 1, 1, 1, 1)
    assert job.is_runnable(dt) is True
    dt = datetime(2000, 1, 1, 0, 1, 1)
    assert job.is_runnable(dt) is False
    for keys in (
        (None, '1'),
        ('1', None),
    ):
        with pytest.raises(ValueError):
            job.set_triggers(*keys)
Ejemplo n.º 12
0
def test_set_action_not_func():
    with pytest.raises(AttributeError):
        job = CronJob()
        job.set_action('stub.echo_hello_not')
Ejemplo n.º 13
0
def test_crontab():
    job = CronJob()
    job.set_crontab('25 * * * *')
    assert isinstance(job._crontab, CronTab)
    assert job._crontab.test(datetime(2001, 1, 1, 0, 25)) is True
Ejemplo n.º 14
0
def test_crontab():
    job = CronJob()
    job.set_crontab('25 * * * *')
    assert isinstance(job._crontab, CronTab)
    assert job._crontab.test(datetime(2001, 1, 1, 0, 25)) is True
Ejemplo n.º 15
0
def test_polled_once(capsys):
    job1 = CronJob()
    job1.set_action('stub.print_datetime')
    job1.set_triggers('%H', '00')
    job2 = CronJob()
    job2.set_action('stub.print_datetime')
    job2.set_triggers('%H', '01')

    plugin = MockedImpl()
    plugin._crontab = [
        job1,
        job2,
    ]
    with freeze_time('2016-01-01 00:00:01'):
        plugin.poll_crontab()
        out, err = capsys.readouterr()
        assert out == '2016-01-01'
Ejemplo n.º 16
0
def test_do_action():
    job = CronJob()
    job.set_action('stub.echo_datetime')
    dt = datetime(2000, 1, 1, 1, 1, 1)
    assert job.do_action(None, dt) == '2000-01-01'
Ejemplo n.º 17
0
def test_set_action():
    job = CronJob()
    job.set_action('stub.echo_hello')
    assert isinstance(job.action, types.FunctionType)
Ejemplo n.º 18
0
def test_set_action():
    job = CronJob()
    job.set_action('stub.echo_hello')
    assert isinstance(job.action, types.FunctionType)
Ejemplo n.º 19
0
def test_set_action_not_func():
    with pytest.raises(AttributeError):
        job = CronJob()
        job.set_action('stub.echo_hello_not')
Ejemplo n.º 20
0
def test_do_action():
    job = CronJob()
    job.set_action('stub.echo_datetime')
    dt = datetime(2000, 1, 1, 1, 1, 1)
    assert job.do_action(None, dt) == '2000-01-01'
Ejemplo n.º 21
0
def test_do_action_with_arg():
    job = CronJob()
    job.set_action('stub.echo_datetime_with_head', 'sample')
    dt = datetime(2000, 1, 1, 1, 1, 1)
    assert job.do_action(None, dt) == 'sample2000-01-01'
Ejemplo n.º 22
0
def test_do_action_with_arg():
    job = CronJob()
    job.set_action('stub.echo_datetime_with_head', 'sample')
    dt = datetime(2000, 1, 1, 1, 1, 1)
    assert job.do_action(None, dt) == 'sample2000-01-01'