def test_error_out_of_range(self): field_list = ['0', '11', '0-10', '1-11'] for field in field_list: with self.subTest(field=field): parser = FieldParser(field, 1, 10) with self.assertRaises(FieldParseError): parser.parse_field()
def test_range(self): field_list = ['Mon-Fri', 'Mon-5', '1-Fri', '1-5'] for field in field_list: with self.subTest(field=field): parser = FieldParser(field, 0, 6, word_set=weekday_word_set()) result = parser.parse_field() self.assertFalse(result.is_any) self.assertEqual(result.value, [1, 2, 3, 4, 5])
def test_case_insensitive(self): match_list = ['sun', 'Sun', 'SUN'] mismatch_list = [ x for x in map(''.join, itertools.product('Ss', 'Uu', 'Nn')) if x not in match_list ] for field in match_list: with self.subTest(field=field): parser = FieldParser(field, 0, 6, word_set=weekday_word_set()) result = parser.parse_field() self.assertFalse(result.is_any) self.assertEqual(result.value, [0]) for field in mismatch_list: with self.subTest(field=field): parser = FieldParser(field, 0, 6, word_set=weekday_word_set()) with self.assertRaises(FieldParseError): parser.parse_field()
def test_multi_with_any(self): field_list = ['0,*', '*,0', '0-3,*', '*,0-3', '0/3,*', '*,0/3'] for field in field_list: with self.subTest(field=field): parser = FieldParser(field, 0, 10) result = parser.parse_field() self.assertTrue(result.is_any) self.assertEqual(result.value, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
def test_multi_uniq(self): parser = FieldParser('0,0,0', 0, 10) result = parser.parse_field() self.assertFalse(result.is_any) self.assertEqual(result.value, [0])
def test_multi(self): parser = FieldParser('0,1', 0, 1) result = parser.parse_field() self.assertFalse(result.is_any) self.assertEqual(result.value, [0, 1])
def test_step_range(self): parser = FieldParser('1-9/3', 0, 10) result = parser.parse_field() self.assertFalse(result.is_any) self.assertEqual(result.value, [1, 4, 7])
def test_step_begin(self): parser = FieldParser('1/3', 0, 10) result = parser.parse_field() self.assertFalse(result.is_any) self.assertEqual(result.value, [1, 4, 7, 10])
def test_single(self): parser = FieldParser('Jan', 1, 12, word_set=month_word_set()) result = parser.parse_field() self.assertFalse(result.is_any) self.assertEqual(result.value, [1])
def test_error_not_match(self): parser = FieldParser('0-1-2', 0, 10) with self.assertRaises(FieldParseError): parser.parse_field()
def test_error_not_match(self): parser = FieldParser('JanFeb', 1, 12, word_set=month_word_set()) with self.assertRaises(FieldParseError): parser.parse_field()
def test_single(self): parser = FieldParser('5', 0, 10) result = parser.parse_field() self.assertFalse(result.is_any) self.assertEqual(result.value, [5])
def test_mixin(self): parser = FieldParser('1,Feb', 1, 12, word_set=month_word_set()) result = parser.parse_field() self.assertEqual(result.value, [1, 2])
def test_step(self): parser = FieldParser('Apr-Dec/2', 1, 12, word_set=month_word_set()) result = parser.parse_field() self.assertFalse(result.is_any) self.assertEqual(result.value, [4, 6, 8, 10, 12])
def test_multi_step(self): parser = FieldParser('0/3,1/3', 0, 10) result = parser.parse_field() self.assertFalse(result.is_any) self.assertEqual(result.value, [0, 1, 3, 4, 6, 7, 9, 10])
def test_error_word_in_step(self): parser = FieldParser('*/Feb', 1, 12, word_set=month_word_set()) with self.assertRaises(FieldParseError): parser.parse_field()
def test_range(self): parser = FieldParser('2-6', 0, 10) result = parser.parse_field() self.assertFalse(result.is_any) self.assertEqual(result.value, [2, 3, 4, 5, 6])
def test_any(self): parser = FieldParser('*', 0, 10) result = parser.parse_field() self.assertTrue(result.is_any) self.assertEqual(result.value, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
def test_step_all(self): parser = FieldParser('*/3', 0, 10) result = parser.parse_field() self.assertFalse(result.is_any) self.assertEqual(result.value, [0, 3, 6, 9])
def test_error_step0(self): parser = FieldParser('*/0', 0, 10) with self.assertRaises(FieldParseError): parser.parse_field()
def test_error_invalid_range(self): parser = FieldParser('7-3', 0, 10) with self.assertRaises(FieldParseError): parser.parse_field()