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)
def test_single_out_of_range_minute_field(): assert_raises(ValueError, tab.parse_field, '60', tab.MINUTE)
def test_mistakes(): assert_raises(tab.CronTabError, tab.parse_entry, '@hourly') assert_raises(tab.CronTabError, tab.parse_entry, '* * * * cmd')
def test_asserts_bits_match(): assert_bits_match([True, False, True, False], [0, 2]) assert_raises(AssertionError, assert_bits_match, [True, False, True, False], [0, 1])
def test_badly_formatted_fields(): assert_raises(ValueError, tab.parse_field, '', tab.MINUTE) assert_raises(ValueError, tab.parse_field, '0-', tab.MINUTE) assert_raises(ValueError, tab.parse_field, '-59', tab.MINUTE) assert_raises(ValueError, tab.parse_field, '*/', tab.MINUTE) assert_raises(ValueError, tab.parse_field, '/2', tab.MINUTE) assert_raises(ValueError, tab.parse_field, '1,', tab.MINUTE) assert_raises(ValueError, tab.parse_field, ',1', tab.MINUTE) assert_raises(ValueError, tab.parse_field, '1,,1', tab.MINUTE)
def test_out_of_range_errors(): assert_raises(ValueError, tab.parse_field, '60', tab.MINUTE) assert_raises(ValueError, tab.parse_field, '0-60', tab.MINUTE) assert_raises(ValueError, tab.parse_field, '24', tab.HOUR) assert_raises(ValueError, tab.parse_field, '0-24', tab.HOUR) assert_raises(ValueError, tab.parse_field, '0', tab.DOM) assert_raises(ValueError, tab.parse_field, '32', tab.DOM) assert_raises(ValueError, tab.parse_field, '0-31', tab.DOM) assert_raises(ValueError, tab.parse_field, '1-32', tab.DOM) assert_raises(ValueError, tab.parse_field, '0', tab.MONTH) assert_raises(ValueError, tab.parse_field, '13', tab.MONTH) assert_raises(ValueError, tab.parse_field, 'jan-13', tab.MONTH) assert_raises(ValueError, tab.parse_field, '0-dec', tab.MONTH) assert_raises(ValueError, tab.parse_field, '8', tab.DOW) assert_raises(ValueError, tab.parse_field, 'sun-8', tab.DOW) # Enforce start < stop. assert_raises(ValueError, tab.parse_field, '1-1', tab.MINUTE) # However it's okay to do it with sunday to sunday. tab.parse_field('7-0', tab.DOW) tab.parse_field('sun-sun', tab.DOW)