Ejemplo n.º 1
0
 def test_error_not_question_only(self):
     field_list = ['?,*', '1,?', '?,L,10W']
     for field in field_list:
         with self.subTest(field=field):
             parser = FieldParser(field, 1, 31)
             with self.assertRaises(FieldParseError):
                 parser.parse_day_field()
Ejemplo n.º 2
0
 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()
Ejemplo n.º 3
0
 def test_error_not_question_only(self):
     field_list = ['?,*', '1,?', '?,SatL,Mon#1']
     for field in field_list:
         with self.subTest(field=field):
             parser = FieldParser(field, 0, 6, word_set=weekday_word_set())
             with self.assertRaises(FieldParseError):
                 parser.parse_weekday_field()
Ejemplo n.º 4
0
 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])
Ejemplo n.º 5
0
 def test_standard(self):
     parser = FieldParser('Sun,Sat', 0, 6, word_set=weekday_word_set())
     result = parser.parse_weekday_field()
     self.assertFalse(result.is_any)
     self.assertFalse(result.is_blank)
     self.assertEqual(result.value, [0, 6])
     self.assertEqual(result.last, [])
     self.assertEqual(result.hash, [])
Ejemplo n.º 6
0
 def test_not_standard(self):
     parser = FieldParser('*/5,L,7W,14W,21W,28W', 1, 31)
     result = parser.parse_day_field()
     self.assertFalse(result.is_any)
     self.assertFalse(result.is_blank)
     self.assertEqual(result.value, [1, 6, 11, 16, 21, 26, 31])
     self.assertTrue(result.last)
     self.assertEqual(result.w, [7, 14, 21, 28])
Ejemplo n.º 7
0
 def test_w(self):
     parser = FieldParser('20W,10W,20W', 1, 31)
     result = parser.parse_day_field()
     self.assertFalse(result.is_any)
     self.assertFalse(result.is_blank)
     self.assertEqual(result.value, [])
     self.assertFalse(result.last)
     self.assertEqual(result.w, [10, 20])
Ejemplo n.º 8
0
 def test_l(self):
     parser = FieldParser('L', 1, 31)
     result = parser.parse_day_field()
     self.assertFalse(result.is_any)
     self.assertFalse(result.is_blank)
     self.assertEqual(result.value, [])
     self.assertTrue(result.last)
     self.assertEqual(result.w, [])
Ejemplo n.º 9
0
 def test_standard(self):
     parser = FieldParser('*/10', 1, 31)
     result = parser.parse_day_field()
     self.assertFalse(result.is_any)
     self.assertFalse(result.is_blank)
     self.assertEqual(result.value, [1, 11, 21, 31])
     self.assertFalse(result.last)
     self.assertEqual(result.w, [])
Ejemplo n.º 10
0
 def test_last(self):
     parser = FieldParser('5L,1L,5L,3L', 0, 6)
     result = parser.parse_weekday_field()
     self.assertFalse(result.is_any)
     self.assertFalse(result.is_blank)
     self.assertEqual(result.value, [])
     self.assertEqual(result.last, [1, 3, 5])
     self.assertEqual(result.hash, [])
Ejemplo n.º 11
0
 def test_hash(self):
     parser = FieldParser('0#1,2#3,4#5,6#1,2#3,1#2,3#4', 0, 6)
     result = parser.parse_weekday_field()
     self.assertFalse(result.is_any)
     self.assertFalse(result.is_blank)
     self.assertEqual(result.value, [])
     self.assertEqual(result.last, [])
     self.assertEqual(result.hash, [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5),
                                    (6, 1)])
Ejemplo n.º 12
0
 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])
Ejemplo n.º 13
0
 def test_w_range(self):
     for w in range(0, 40):
         with self.subTest(w=w):
             parser = FieldParser('{0}W'.format(w), 1, 31)
             if 1 <= w <= 31:
                 result = parser.parse_day_field()
                 self.assertEqual(result.w, [w])
             else:
                 with self.assertRaises(FieldParseError):
                     parser.parse_day_field()
Ejemplo n.º 14
0
 def test_not_standard(self):
     parser = FieldParser('Mon,Wed,Thu,Tue#2,Tue#4,FriL',
                          0,
                          6,
                          word_set=weekday_word_set())
     result = parser.parse_weekday_field()
     self.assertFalse(result.is_any)
     self.assertFalse(result.is_blank)
     self.assertEqual(result.value, [1, 3, 4])
     self.assertEqual(result.last, [5])
     self.assertEqual(result.hash, [(2, 2), (2, 4)])
Ejemplo n.º 15
0
 def test_hash_with_word_set(self):
     parser = FieldParser('Sat#4,SAT#2,sat#4',
                          0,
                          6,
                          word_set=weekday_word_set())
     result = parser.parse_weekday_field()
     self.assertFalse(result.is_any)
     self.assertFalse(result.is_blank)
     self.assertEqual(result.value, [])
     self.assertEqual(result.last, [])
     self.assertEqual(result.hash, [(6, 2), (6, 4)])
Ejemplo n.º 16
0
 def test_last_with_word_set(self):
     parser = FieldParser('FriL,MONL,friL',
                          0,
                          6,
                          word_set=weekday_word_set())
     result = parser.parse_weekday_field()
     self.assertFalse(result.is_any)
     self.assertFalse(result.is_blank)
     self.assertEqual(result.value, [])
     self.assertEqual(result.last, [1, 5])
     self.assertEqual(result.hash, [])
Ejemplo n.º 17
0
 def test_last_range(self):
     for weekday in range(0, 10):
         with self.subTest(weekday=weekday):
             parser = FieldParser('{0}L'.format(weekday), 0, 6)
             if 0 <= weekday <= 6:
                 result = parser.parse_weekday_field()
                 self.assertFalse(result.is_any)
                 self.assertFalse(result.is_blank)
                 self.assertEqual(result.value, [])
                 self.assertEqual(result.last, [weekday])
                 self.assertEqual(result.hash, [])
             else:
                 with self.assertRaises(FieldParseError):
                     parser.parse_weekday_field()
Ejemplo n.º 18
0
 def test_error_non_standard(self):
     field_list = ['?', 'L', '10W']
     for field in field_list:
         non_standard_parser = FieldParser(field, 1, 31)
         non_standard_parser.parse_day_field(non_standard=True)
         standard_parser = FieldParser(field, 1, 31)
         with self.assertRaises(FieldParseError):
             standard_parser.parse_day_field(non_standard=False)
Ejemplo n.º 19
0
 def test_hash_range(self):
     for weekday, week_number in itertools.product(range(0, 10),
                                                   range(0, 10)):
         with self.subTest(weekday=weekday, week_number=week_number):
             parser = FieldParser('{0}#{1}'.format(weekday, week_number), 0,
                                  6)
             if 0 <= weekday <= 6 and 1 <= week_number <= 5:
                 result = parser.parse_weekday_field()
                 self.assertFalse(result.is_any)
                 self.assertFalse(result.is_blank)
                 self.assertEqual(result.value, [])
                 self.assertEqual(result.last, [])
                 self.assertEqual(result.hash, [(weekday, week_number)])
             else:
                 with self.assertRaises(FieldParseError):
                     parser.parse_weekday_field()
Ejemplo n.º 20
0
 def test_error_non_standard(self):
     field_list = ['?', 'FriL', 'Sat#2']
     for field in field_list:
         non_standard_parser = FieldParser(field,
                                           0,
                                           6,
                                           word_set=weekday_word_set())
         non_standard_parser.parse_weekday_field(non_standard=True)
         standard_parser = FieldParser(field,
                                       0,
                                       6,
                                       word_set=weekday_word_set())
         with self.assertRaises(FieldParseError):
             standard_parser.parse_weekday_field(non_standard=False)
Ejemplo n.º 21
0
 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()
Ejemplo n.º 22
0
 def test_error_not_use_slash(self):
     parser = FieldParser('*/2', 0, 6)
     with self.assertRaises(FieldParseError):
         parser.parse_weekday_field(use_slash=False)
Ejemplo n.º 23
0
 def test_error_step0(self):
     parser = FieldParser('*/0', 0, 10)
     with self.assertRaises(FieldParseError):
         parser.parse_field()
Ejemplo n.º 24
0
 def test_error_not_match(self):
     parser = FieldParser('0-1-2', 0, 10)
     with self.assertRaises(FieldParseError):
         parser.parse_field()
Ejemplo n.º 25
0
 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])
Ejemplo n.º 26
0
 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])
Ejemplo n.º 27
0
 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])
Ejemplo n.º 28
0
 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])
Ejemplo n.º 29
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])
Ejemplo n.º 30
0
 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])