Beispiel #1
0
 def test_special_cases(self):
     # The years 1976, 1998, 2020, and 2043 have a 14th cycle in the year.
     for value in ('7614', '9814', '2014', '4314'):
         with self.subTest(value):
             try:
                 AIRAC(value)
             except Exception:
                 self.fail('Unexpected failure while parsing identifier.')
Beispiel #2
0
 def test_alternate_construction(self):
     identifier, year, ordinal, effective = '1906', 19, 6, datetime(2019, 5, 23, tzinfo=timezone.utc)
     values = ('1906', 1558569600, 1558569600.0, date(2019, 5, 23), datetime(2019, 5, 23, tzinfo=timezone.utc))
     for value in values:
         with self.subTest(value):
             a = AIRAC(value)
             self.assertEqual(a.year, year)
             self.assertEqual(a.ordinal, ordinal)
             self.assertEqual(a.effective, effective)
             self.assertEqual(a.identifier, identifier)
Beispiel #3
0
 def _test_constructor_error(self, *values, exception=None):
     for value in values:
         with self.subTest(value):
             with self.assertRaisesRegex(exception, f'^Invalid AIRAC identifier: {re.escape(repr(value))}$'):
                 AIRAC(value)
Beispiel #4
0
 def test_floored_to_effective(self):
     for day in range(23, 31):
         value = datetime(2019, 5, day, tzinfo=timezone.utc)
         with self.subTest(value):
             self.assertEqual(AIRAC(value).timestamp, 1558569600)
Beispiel #5
0
 def test_ordering(self):
     self.assertEqual(AIRAC('1913'), AIRAC('1913'))
     self.assertNotEqual(AIRAC('1913'), AIRAC('2001'))
     self.assertLess(AIRAC('1913'), AIRAC('2001'))
     self.assertLessEqual(AIRAC('1913'), AIRAC('1913'))
     self.assertGreater(AIRAC('2002'), AIRAC('2001'))
     self.assertGreaterEqual(AIRAC('2002'), AIRAC('2002'))
     self.assertIs(AIRAC('1913').__eq__(None), NotImplemented)
     self.assertIs(AIRAC('1913').__ne__(None), NotImplemented)
     self.assertIs(AIRAC('1913').__lt__(None), NotImplemented)
     self.assertIs(AIRAC('1913').__le__(None), NotImplemented)
     self.assertIs(AIRAC('1913').__gt__(None), NotImplemented)
     self.assertIs(AIRAC('1913').__ge__(None), NotImplemented)
Beispiel #6
0
 def test_repr(self):
     self.assertEqual(repr(AIRAC('1913')), "AIRAC('1913')")
Beispiel #7
0
 def test_str(self):
     obj = AIRAC('1913')
     self.assertEqual(str(obj), '1913')
     self.assertEqual(str(obj), obj.identifier)
Beispiel #8
0
 def test_immutable(self):
     with self.assertRaisesRegex(TypeError, r'^AIRAC objects are immutable\.$'):
         AIRAC('1913').timestamp = 0
Beispiel #9
0
 def test_lower_limit(self):
     with self.assertRaisesRegex(ValueError, r'^AIRAC identifiers were not defined before 1964-01-16\.$'):
         AIRAC(AIRAC.BASE - 1)