Example #1
0
def test_python_commands():
    cmd = lambda x: x
    entry = tab.parse_entry('* * * * *', cmd, 123)
    assert entry.command[0] == cmd
    assert entry() == 123
    tab.parse_entry('* * * * * ls')()
    entry = tab.parse_entry('* * * * * grep') # Should fail.
    assert_raises(tab.CronTabError, entry)
    assert_raises(tab.CronTabError, tab.parse_entry, '* * * * *')
    assert_raises(tab.CronTabError, tab.parse_entry, '* * * * * cmd', cmd)
Example #2
0
def test_iter_field():
    entry = tab.parse_entry('* * * * * cmd')
    assert list(entry.iter_field(tab.MINUTE)) == list(range(60))
    assert list(entry.iter_field(tab.HOUR)) == list(range(24))
    assert list(entry.iter_field(tab.DOM)) == list(range(1, 32))
    assert list(entry.iter_field(tab.MONTH)) == list(range(1, 13))
    assert list(entry.iter_field(tab.DOW)) == list(range(8))
    entry = tab.parse_entry('*/17 4-9 2-27/8 MAY-AUG MON-FRI cmd')
    assert list(entry.iter_field(tab.MINUTE)) == list(range(0, 60, 17))
    assert list(entry.iter_field(tab.HOUR)) == list(range(4, 10))
    assert list(entry.iter_field(tab.DOM)) == list(range(2, 28, 8))
    assert list(entry.iter_field(tab.MONTH)) == list(range(5, 9))
    assert list(entry.iter_field(tab.DOW)) == list(range(1, 6))
def test_iter_field():
    entry = tab.parse_entry('* * * * * cmd')
    assert list(entry.iter_field(tab.MINUTE)) == list(range(60))
    assert list(entry.iter_field(tab.HOUR))   == list(range(24))
    assert list(entry.iter_field(tab.DOM))    == list(range(1, 32))
    assert list(entry.iter_field(tab.MONTH))  == list(range(1, 13))
    assert list(entry.iter_field(tab.DOW))    == list(range(8))
    entry = tab.parse_entry('*/17 4-9 2-27/8 MAY-AUG MON-FRI cmd')
    assert list(entry.iter_field(tab.MINUTE)) == list(range(0, 60, 17))
    assert list(entry.iter_field(tab.HOUR))   == list(range(4, 10))
    assert list(entry.iter_field(tab.DOM))    == list(range(2, 28, 8))
    assert list(entry.iter_field(tab.MONTH))  == list(range(5, 9))
    assert list(entry.iter_field(tab.DOW))    == list(range(1, 6))
Example #4
0
def test_hourly():
    entry = tab.parse_entry('@hourly cmd')
    assert entry.fields[0] == [True] + [False for i in range(59)]
    assert entry.fields[1] == [True for i in range(24)]
    assert entry.fields[2] == [True for i in range(31)]
    assert entry.fields[3] == [True for i in range(12)]
    assert entry.fields[4] == [True for i in range(8)]
    assert entry.command == 'cmd'
    assert entry.dom_or_dow_star
    assert not entry.when_reboot
Example #5
0
def test_parse_entry_generic():
    entry = tab.parse_entry('* * * * * cmd')
    assert entry.fields[0] == [True for i in range(60)]
    assert entry.fields[1] == [True for i in range(24)]
    assert entry.fields[2] == [True for i in range(31)]
    assert entry.fields[3] == [True for i in range(12)]
    assert entry.fields[4] == [True for i in range(8)]
    assert entry.command == 'cmd'
    assert entry.dom_or_dow_star
    assert not entry.when_reboot
Example #6
0
def test_daily():
    for token in ('@daily', '@midnight'):
        entry = tab.parse_entry(token + ' cmd')
        assert entry.fields[0] == [True] + [False for i in range(59)]
        assert entry.fields[1] == [True] + [False for i in range(23)]
        assert entry.fields[2] == [True for i in range(31)]
        assert entry.fields[3] == [True for i in range(12)]
        assert entry.fields[4] == [True for i in range(8)]
        assert entry.command == 'cmd'
        assert entry.dom_or_dow_star
        assert not entry.when_reboot
Example #7
0
def test_yearly():
    for token in ('@yearly', '@annually'):
        entry = tab.parse_entry(token + ' cmd')
        assert entry.fields[0] == [True] + [False for i in range(59)]
        assert entry.fields[1] == [True] + [False for i in range(23)]
        assert entry.fields[2] == [True] + [False for i in range(30)]
        assert entry.fields[3] == [True] + [False for i in range(11)]
        assert entry.fields[4] == [True for i in range(8)]
        assert entry.command == 'cmd'
        assert entry.dom_or_dow_star
        assert not entry.when_reboot
Example #8
0
def test_reboot():
    entry = tab.parse_entry('@reboot cmd')
    assert entry.fields is None
    assert entry.when_reboot
    assert entry.when_reboot