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()
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)
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()
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])
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])
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, [])
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, [])