示例#1
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)
示例#2
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()
示例#3
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, [])
示例#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])
示例#5
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()
示例#6
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)])
示例#7
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)])
示例#8
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, [])
示例#9
0
 def test_l(self):
     year = 2019
     last_weekday_list = {
             'sun': [27, 24, 31, 28, 26, 30, 28, 25, 29, 27, 24, 29],
             'mon': [28, 25, 25, 29, 27, 24, 29, 26, 30, 28, 25, 30],
             'tue': [29, 26, 26, 30, 28, 25, 30, 27, 24, 29, 26, 31],
             'wed': [30, 27, 27, 24, 29, 26, 31, 28, 25, 30, 27, 25],
             'thu': [31, 28, 28, 25, 30, 27, 25, 29, 26, 31, 28, 26],
             'fri': [25, 22, 29, 26, 31, 28, 26, 30, 27, 25, 29, 27],
             'sat': [26, 23, 30, 27, 25, 29, 27, 31, 28, 26, 30, 28]}
     for name, weekday in weekday_word_set().items():
         for month in range(1, 13):
             expected = last_weekday_list[name][month - 1]
             with self.subTest(
                     weekday=name,
                     year=year,
                     month=month):
                 self.assertEqual(
                         calendar.weekday(year, month, expected),
                         (weekday - 1) % 7)
                 self.assertEqual(
                         day_of_week_l(weekday, year, month),
                         expected)
示例#10
0
 def test_hash(self):
     year = 2019
     first_weekday_list = {
             'sun': [6, 3, 3, 7, 5, 2, 7, 4, 1, 6, 3, 1],
             'mon': [7, 4, 4, 1, 6, 3, 1, 5, 2, 7, 4, 2],
             'tue': [1, 5, 5, 2, 7, 4, 2, 6, 3, 1, 5, 3],
             'wed': [2, 6, 6, 3, 1, 5, 3, 7, 4, 2, 6, 4],
             'thu': [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5],
             'fri': [4, 1, 1, 5, 3, 7, 5, 2, 6, 4, 1, 6],
             'sat': [5, 2, 2, 6, 4, 1, 6, 3, 7, 5, 2, 7]}
     for (name, weekday), week_number in itertools.product(
             weekday_word_set().items(),
             range(1, 6)):
         for month in range(1, 13):
             expected = (
                     first_weekday_list[name][month - 1]
                     + 7 * (week_number - 1))
             lastday = calendar.monthrange(year, month)[1]
             if lastday < expected:
                 expected = None
             else:
                 self.assertEqual(
                         calendar.weekday(year, month, expected),
                         (weekday - 1) % 7)
             with self.subTest(
                     weekday=name,
                     week_number=week_number,
                     year=year,
                     month=month):
                 self.assertEqual(
                         day_of_week_hash(
                                 weekday,
                                 week_number,
                                 year,
                                 month),
                         expected)