Example #1
0
 def test_formatting(self):
     python2_eol = Month(2020, 1)
     leap_month = Month(2000, 2)
     self.assertEqual("{:%Y-%m}".format(python2_eol), "2020-01")
     with set_locale('C'):
         self.assertEqual("{0:%b %Y}".format(leap_month), "Feb 2000")
         self.assertEqual("{:%b %Y}".format(python2_eol), "Jan 2020")
Example #2
0
 def test_first_method(self):
     python2_eol = Month(2020, 1)
     eol_date = python2_eol.first()
     self.assertEqual(eol_date.year, 2020)
     self.assertEqual(eol_date.month, 1)
     self.assertEqual(eol_date.day, 1)
     self.assertEqual(str(eol_date), '2020-01-01')
     self.assertEqual(str(eol_date - timedelta(days=1)), '2019-12-31')
Example #3
0
 def test_month_arithmetic_with_other_types(self):
     python2_eol = Month(2020, 1)
     python2_release = Month(2000, 10)
     python2_lifetime = python2_eol - python2_release
     with self.assertRaises(TypeError):
         python2_eol + python2_release
     with self.assertRaises(TypeError):
         python2_eol * python2_release
     with self.assertRaises(TypeError):
         python2_eol * python2_lifetime
     with self.assertRaises(TypeError):
         python2_lifetime - python2_eol
     with self.assertRaises(TypeError):
         python2_eol - date(1999, 12, 1)
Example #4
0
 def test_ordering(self):
     python2_eol = Month(2020, 1)
     pycon_2019 = Month(2019, 5)
     self.assertLess(pycon_2019, python2_eol)
     self.assertGreater(python2_eol, pycon_2019)
     self.assertLessEqual(pycon_2019, python2_eol)
     self.assertGreaterEqual(python2_eol, pycon_2019)
     self.assertFalse(pycon_2019 > python2_eol)
     self.assertFalse(pycon_2019 >= python2_eol)
     self.assertFalse(python2_eol < pycon_2019)
     self.assertFalse(python2_eol <= pycon_2019)
     with self.assertRaises(TypeError):
         python2_eol < (2021, 12)  # tuples aren't months
     with self.assertRaises(TypeError):
         python2_eol >= (2021, 12)  # tuples aren't months
     with self.assertRaises(TypeError):
         (2021, 12) < python2_eol  # tuples aren't months
Example #5
0
 def test_month_arithmetic_with_month_deltas(self):
     python2_eol = Month(2020, 1)
     python2_release = Month(2000, 10)
     python2_lifetime = MonthDelta(231)
     self.assertEqual(python2_eol + MonthDelta(4), Month(2020, 5))
     self.assertEqual(MonthDelta(13) + python2_eol, Month(2021, 2))
     self.assertEqual(python2_eol - MonthDelta(4), Month(2019, 9))
     self.assertEqual(python2_eol - MonthDelta(13), Month(2018, 12))
     self.assertEqual(python2_release + python2_lifetime, python2_eol)
Example #6
0
 def test_equality(self):
     python2_eol = Month(2020, 1)
     self.assertEqual(python2_eol, Month(2020, 1))
     self.assertNotEqual(python2_eol, Month(2020, 2))
     self.assertNotEqual(python2_eol, Month(2019, 1))
     self.assertFalse(python2_eol != Month(2020, 1))
     self.assertFalse(python2_eol == Month(2020, 2))
     self.assertNotEqual(python2_eol, date(2020, 1, 1))
     self.assertNotEqual(python2_eol, (2020, 1))
     self.assertNotEqual((2020, 1), python2_eol)  # tuples aren't months
Example #7
0
 def test_month_subtracting_months(self):
     python2_eol = Month(2020, 1)
     python2_release = Month(2000, 10)
     python2_lifetime = python2_eol - python2_release
     self.assertEqual(python2_lifetime, MonthDelta(20 * 12 - 9))
Example #8
0
 def test_memory_efficient(self):
     python2_eol = Month(2020, 1)
     with self.assertRaises(Exception):
         python2_eol.__dict__
Example #9
0
 def test_from_date(self):
     python2_eol = Month.from_date(date(2020, 1, 1))
     self.assertEqual(python2_eol, Month(2020, 1))
     leap_month = Month.from_date(date(2000, 2, 29))
     self.assertEqual(leap_month, Month(2000, 2))
Example #10
0
 def test_string_representations(self):
     python2_eol = Month(2020, 1)
     self.assertEqual(str(python2_eol), "2020-01")
     new_month = eval(repr(python2_eol))
     self.assertEqual(new_month.year, python2_eol.year)
     self.assertEqual(new_month.month, python2_eol.month)
Example #11
0
 def test_human_readable_representation(self):
     month = Month(2019, 1)
     self.assertEqual(str(month), '2019-01')
Example #12
0
 def test_machine_readable_representation(self):
     month = Month(2019, 1)
     self.assertEqual(repr(month), 'Month(year=2019, month=1)')
Example #13
0
 def test_initialization(self):
     month = Month(2019, 1)
     self.assertEqual(month.year, 2019)
     self.assertEqual(month.month, 1)