def test_parse_groups(self): self.assertEqual(crontab_parser().parse('1,2,3,4'), set([1, 2, 3, 4])) self.assertEqual(crontab_parser().parse('0,15,30,45'), set([0, 15, 30, 45])) self.assertEqual(crontab_parser(min_=1).parse('1,2,3,4'), set([1, 2, 3, 4]))
def test_parse_groups(self): self.assertEqual(crontab_parser().parse('1,2,3,4'), {1, 2, 3, 4}) self.assertEqual(crontab_parser().parse('0,15,30,45'), {0, 15, 30, 45}) self.assertEqual(crontab_parser(min_=1).parse('1,2,3,4'), {1, 2, 3, 4})
def test_parse_range(self): self.assertEqual(crontab_parser(60).parse('1-10'), set(range(1, 10 + 1))) self.assertEqual(crontab_parser(24).parse('0-20'), set(range(0, 20 + 1))) self.assertEqual(crontab_parser().parse('2-10'), set(range(2, 10 + 1)))
def check_cron(crontab): cron_errors = [] # Validate Minute try: crontab_parser(60).parse(crontab['minute']) except (ValueError, ParseException): cron_errors.append("Error in Value: Minute") # Validate Hour try: crontab_parser(24).parse(crontab['hour']) except (ValueError, ParseException): cron_errors.append("Error in Value: Hour") # Validate Day of Week try: crontab_parser(7).parse(crontab['day_of_week']) except (ValueError, ParseException): cron_errors.append("Error in Value: Day of Week") # Validate Day of Month try: crontab_parser(31,1).parse(crontab['day_of_month']) except (ValueError, ParseException): cron_errors.append("Error in Value: Day of Month") # Validate Month of Year try: crontab_parser(12,1).parse(crontab['month_of_year']) except (ValueError, ParseException): cron_errors.append("Error in Value: Month of Year") return cron_errors
def test_parse_steps(self): self.assertEqual(crontab_parser(8).parse('*/2'), set([0, 2, 4, 6])) self.assertEqual(crontab_parser().parse('*/2'), set(i * 2 for i in xrange(30))) self.assertEqual(crontab_parser().parse('*/3'), set(i * 3 for i in xrange(20)))
def test_parse_composite(self): self.assertEqual(crontab_parser(8).parse('*/2'), set([0, 2, 4, 6])) self.assertEqual(crontab_parser().parse('2-9/5'), set([5])) self.assertEqual(crontab_parser().parse('2-10/5'), set([5, 10])) self.assertEqual(crontab_parser().parse('2-11/5,3'), set([3, 5, 10])) self.assertEqual(crontab_parser().parse('2-4/3,*/5,0-21/4'), set([0, 3, 4, 5, 8, 10, 12, 15, 16, 20, 25, 30, 35, 40, 45, 50, 55]))
def test_parse_star(self): self.assertEqual(crontab_parser(24).parse('*'), set(range(24))) self.assertEqual(crontab_parser(60).parse('*'), set(range(60))) self.assertEqual(crontab_parser(7).parse('*'), set(range(7))) self.assertEqual(crontab_parser(31, 1).parse('*'), set(range(1, 31 + 1))) self.assertEqual(crontab_parser(12, 1).parse('*'), set(range(1, 12 + 1)))
def test_parse_steps(self): self.assertEqual(crontab_parser(8).parse("*/2"), set([0, 2, 4, 6])) self.assertEqual(crontab_parser().parse("*/2"), set(i * 2 for i in xrange(30))) self.assertEqual(crontab_parser().parse("*/3"), set(i * 3 for i in xrange(20))) self.assertEqual(crontab_parser(8, 1).parse("*/2"), set([1, 3, 5, 7])) self.assertEqual(crontab_parser(min_=1).parse("*/2"), set(i * 2 + 1 for i in xrange(30))) self.assertEqual(crontab_parser(min_=1).parse("*/3"), set(i * 3 + 1 for i in xrange(20)))
def test_parse_composite(self): self.assertEqual(crontab_parser(8).parse("*/2"), set([0, 2, 4, 6])) self.assertEqual(crontab_parser().parse("2-9/5"), set([2, 7])) self.assertEqual(crontab_parser().parse("2-10/5"), set([2, 7])) self.assertEqual(crontab_parser().parse("2-11/5,3"), set([2, 3, 7])) self.assertEqual( crontab_parser().parse("2-4/3,*/5,0-21/4"), set([0, 2, 4, 5, 8, 10, 12, 15, 16, 20, 25, 30, 35, 40, 45, 50, 55]), ) self.assertEqual(crontab_parser().parse("1-9/2"), set([1, 3, 5, 7, 9]))
def test_parse_steps(self): assert crontab_parser(8).parse('*/2') == {0, 2, 4, 6} assert crontab_parser().parse('*/2') == {i * 2 for i in range(30)} assert crontab_parser().parse('*/3') == {i * 3 for i in range(20)} assert crontab_parser(8, 1).parse('*/2') == {1, 3, 5, 7} assert crontab_parser(min_=1).parse('*/2') == { i * 2 + 1 for i in range(30) } assert crontab_parser(min_=1).parse('*/3') == { i * 3 + 1 for i in range(20) }
def test_parse_steps(self): self.assertEqual(crontab_parser(8).parse('*/2'), {0, 2, 4, 6}) self.assertEqual(crontab_parser().parse('*/2'), {i * 2 for i in range(30)}) self.assertEqual(crontab_parser().parse('*/3'), {i * 3 for i in range(20)}) self.assertEqual(crontab_parser(8, 1).parse('*/2'), {1, 3, 5, 7}) self.assertEqual(crontab_parser(min_=1).parse('*/2'), {i * 2 + 1 for i in range(30)}) self.assertEqual(crontab_parser(min_=1).parse('*/3'), {i * 3 + 1 for i in range(20)})
def test_parse_range_wraps(self): self.assertEqual(crontab_parser(12).parse('11-1'), set([11, 0, 1])) self.assertEqual(crontab_parser(60, 1).parse('2-1'), set(range(1, 60 + 1)))
def test_parse_errors_on_negative_number(self): with pytest.raises(ParseException): crontab_parser(60).parse('-20')
def test_parse_range(self): assert crontab_parser(60).parse('1-10') == set(range(1, 10 + 1)) assert crontab_parser(24).parse('0-20') == set(range(0, 20 + 1)) assert crontab_parser().parse('2-10') == set(range(2, 10 + 1)) assert crontab_parser(60, 1).parse('1-10') == set(range(1, 10 + 1))
def test_parse_composite(self): self.assertEqual(crontab_parser(8).parse('*/2'), set([0, 2, 4, 6])) self.assertEqual(crontab_parser().parse('2-9/5'), set([2, 7])) self.assertEqual(crontab_parser().parse('2-10/5'), set([2, 7])) self.assertEqual(crontab_parser().parse('2-11/5,3'), set([2, 3, 7])) self.assertEqual(crontab_parser().parse('2-4/3,*/5,0-21/4'), set([0, 2, 4, 5, 8, 10, 12, 15, 16, 20, 25, 30, 35, 40, 45, 50, 55])) self.assertEqual(crontab_parser().parse('1-9/2'), set([1, 3, 5, 7, 9])) self.assertEqual(crontab_parser(8, 1).parse('*/2'), set([1, 3, 5, 7])) self.assertEqual(crontab_parser(min_=1).parse('2-9/5'), set([2, 7])) self.assertEqual(crontab_parser(min_=1).parse('2-10/5'), set([2, 7])) self.assertEqual(crontab_parser(min_=1).parse('2-11/5,3'), set([2, 3, 7])) self.assertEqual(crontab_parser(min_=1).parse('2-4/3,*/5,1-21/4'), set([1, 2, 5, 6, 9, 11, 13, 16, 17, 21, 26, 31, 36, 41, 46, 51, 56])) self.assertEqual(crontab_parser(min_=1).parse('1-9/2'), set([1, 3, 5, 7, 9]))
def test_parse_errors_on_lt_min(self): crontab_parser(min_=1).parse('1') with self.assertRaises(ValueError): crontab_parser(12, 1).parse('0') with self.assertRaises(ValueError): crontab_parser(24, 1).parse('12-0')
def test_parse_star(self): self.assertEquals(crontab_parser(24).parse('*'), set(range(24))) self.assertEquals(crontab_parser(60).parse('*'), set(range(60))) self.assertEquals(crontab_parser(7).parse('*'), set(range(7)))
def test_parse_errors_on_lt_min(self): crontab_parser(min_=1).parse('1') with pytest.raises(ValueError): crontab_parser(12, 1).parse('0') with pytest.raises(ValueError): crontab_parser(24, 1).parse('12-0')
def test_range_steps_not_enough(self): with self.assertRaises(crontab_parser.ParseException): crontab_parser(24)._range_steps([1])
def test_parse_composite(self): assert crontab_parser(8).parse('*/2') == {0, 2, 4, 6} assert crontab_parser().parse('2-9/5') == {2, 7} assert crontab_parser().parse('2-10/5') == {2, 7} assert crontab_parser(min_=1).parse('55-5/3') == {55, 58, 1, 4} assert crontab_parser().parse('2-11/5,3') == {2, 3, 7} assert crontab_parser().parse('2-4/3,*/5,0-21/4') == { 0, 2, 4, 5, 8, 10, 12, 15, 16, 20, 25, 30, 35, 40, 45, 50, 55, } assert crontab_parser().parse('1-9/2') == {1, 3, 5, 7, 9} assert crontab_parser(8, 1).parse('*/2') == {1, 3, 5, 7} assert crontab_parser(min_=1).parse('2-9/5') == {2, 7} assert crontab_parser(min_=1).parse('2-10/5') == {2, 7} assert crontab_parser(min_=1).parse('2-11/5,3') == {2, 3, 7} assert crontab_parser(min_=1).parse('2-4/3,*/5,1-21/4') == { 1, 2, 5, 6, 9, 11, 13, 16, 17, 21, 26, 31, 36, 41, 46, 51, 56, } assert crontab_parser(min_=1).parse('1-9/2') == {1, 3, 5, 7, 9}
def test_parse_groups(self): self.assertEqual(crontab_parser().parse("1,2,3,4"), set([1, 2, 3, 4])) self.assertEqual(crontab_parser().parse("0,15,30,45"), set([0, 15, 30, 45]))
def test_parse_errors_on_empty_group(self): with self.assertRaises(ParseException): crontab_parser(60).parse('1,,2')
def test_parse_errors_on_empty_string(self): with self.assertRaises(ParseException): crontab_parser(60).parse('')
def test_parse_range_wraps(self): assert crontab_parser(12).parse('11-1') == {11, 0, 1} assert crontab_parser(60, 1).parse('2-1') == set(range(1, 60 + 1))
def test_parse_errors_on_empty_string(self): with pytest.raises(ParseException): crontab_parser(60).parse('')
def test_parse_groups(self): assert crontab_parser().parse('1,2,3,4') == {1, 2, 3, 4} assert crontab_parser().parse('0,15,30,45') == {0, 15, 30, 45} assert crontab_parser(min_=1).parse('1,2,3,4') == {1, 2, 3, 4}
def test_parse_errors_on_gt_max(self): crontab_parser(1).parse('0') with pytest.raises(ValueError): crontab_parser(1).parse('1') with pytest.raises(ValueError): crontab_parser(60).parse('61-0')
def test_parse_errors_on_gt_max(self): crontab_parser(1).parse('0') with self.assertRaises(ValueError): crontab_parser(1).parse('1') with self.assertRaises(ValueError): crontab_parser(60).parse('61-0')
def test_parse_errors_on_empty_steps(self): with self.assertRaises(ParseException): crontab_parser(60).parse('*/')
def test_parse_errors_on_empty_steps(self): self.assertRaises(ParseException, crontab_parser(60).parse, '*/')
def test_parse_groups(self): self.assertEqual(crontab_parser().parse('1,2,3,4'), set([1, 2, 3, 4])) self.assertEqual(crontab_parser().parse('0,15,30,45'), set([0, 15, 30, 45]))
def test_parse_star(self): assert crontab_parser(24).parse('*') == set(range(24)) assert crontab_parser(60).parse('*') == set(range(60)) assert crontab_parser(7).parse('*') == set(range(7)) assert crontab_parser(31, 1).parse('*') == set(range(1, 31 + 1)) assert crontab_parser(12, 1).parse('*') == set(range(1, 12 + 1))
def test_parse_range(self): self.assertEqual(crontab_parser(60).parse("1-10"), set(range(1, 10 + 1))) self.assertEqual(crontab_parser(24).parse("0-20"), set(range(0, 20 + 1))) self.assertEqual(crontab_parser().parse("2-10"), set(range(2, 10 + 1))) self.assertEqual(crontab_parser(60, 1).parse("1-10"), set(range(1, 10 + 1)))
def test_parse_errors_on_empty_steps(self): with pytest.raises(ParseException): crontab_parser(60).parse('*/')
def test_parse_errors_on_gt_max(self): crontab_parser(1).parse("0") with self.assertRaises(ValueError): crontab_parser(1).parse("1") with self.assertRaises(ValueError): crontab_parser(60).parse("61-0")
def test_parse_errors_on_negative_number(self): with self.assertRaises(ParseException): crontab_parser(60).parse('-20')
def test_parse_star(self): self.assertEqual(crontab_parser(24).parse('*'), set(range(24))) self.assertEqual(crontab_parser(60).parse('*'), set(range(60))) self.assertEqual(crontab_parser(7).parse('*'), set(range(7)))