Beispiel #1
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)
Beispiel #2
0
 def test_adding_and_subtracting_with_monthdeltas(self):
     self.assertEqual(MonthDelta(4) + MonthDelta(2), MonthDelta(6))
     self.assertEqual(MonthDelta(4) - MonthDelta(2), MonthDelta(2))
     with self.assertRaises(TypeError):
         MonthDelta(4) - 8
     with self.assertRaises(TypeError):
         8 - MonthDelta(4)
Beispiel #3
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))
Beispiel #4
0
 def test_scaling_and_division(self):
     self.assertEqual(MonthDelta(4) * 2, MonthDelta(8))
     self.assertEqual(2 * MonthDelta(4), MonthDelta(8))
     self.assertEqual(MonthDelta(4) / 2, MonthDelta(2))
     self.assertEqual(MonthDelta(4) / MonthDelta(2), 2)
     self.assertEqual(MonthDelta(18) // 12, MonthDelta(1))
     self.assertEqual(MonthDelta(18) // MonthDelta(12), 1)
     self.assertEqual(MonthDelta(18) % MonthDelta(12), 6)
     self.assertEqual(MonthDelta(18) % 12, MonthDelta(6))
     self.assertEqual(-MonthDelta(18), MonthDelta(-18))
     with self.assertRaises(TypeError):
         MonthDelta(4) * "a"
     with self.assertRaises(TypeError):
         MonthDelta(4) * 2.0
     with self.assertRaises(TypeError):
         MonthDelta(4) / 2.0
     with self.assertRaises(TypeError):
         MonthDelta(4) * MonthDelta(2)
     with self.assertRaises(TypeError):
         MonthDelta(4) % 0.5
Beispiel #5
0
 def test_adding_month_delta_to_unknown_value(self):
     with self.assertRaises(TypeError):
         MonthDelta(4) + 8
     with self.assertRaises(TypeError):
         8 + MonthDelta(4)
Beispiel #6
0
 def test_equality(self):
     self.assertEqual(MonthDelta(12), MonthDelta(12))
     self.assertNotEqual(MonthDelta(11), MonthDelta(12))
     self.assertIs(MonthDelta(12) != MonthDelta(12), False)
     self.assertIs(MonthDelta(11) == MonthDelta(12), False)
     self.assertIs(MonthDelta(0) == timedelta(0), False)
     self.assertIs(MonthDelta(0) == 0, False)
     self.assertIs(MonthDelta(6) == 6, False)
Beispiel #7
0
 def test_initializer(self):
     four_months = MonthDelta(4)
     self.assertEqual(four_months.months, 4)