|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +from datetime import timedelta |
| 4 | +from pendulum import PendulumInterval |
| 5 | + |
| 6 | +from .. import AbstractTestCase |
| 7 | + |
| 8 | + |
| 9 | +class AddSubTestCase(AbstractTestCase): |
| 10 | + |
| 11 | + def test_add_interval(self): |
| 12 | + p1 = PendulumInterval(days=23, seconds=32) |
| 13 | + p2 = PendulumInterval(days=12, seconds=30) |
| 14 | + |
| 15 | + p = p1 + p2 |
| 16 | + self.assertInterval(p, 5, 0, 0, 1, 2) |
| 17 | + |
| 18 | + def test_add_timedelta(self): |
| 19 | + p1 = PendulumInterval(days=23, seconds=32) |
| 20 | + p2 = timedelta(days=12, seconds=30) |
| 21 | + |
| 22 | + p = p1 + p2 |
| 23 | + self.assertInterval(p, 5, 0, 0, 1, 2) |
| 24 | + |
| 25 | + def test_add_unsupported(self): |
| 26 | + p = PendulumInterval(days=23, seconds=32) |
| 27 | + self.assertEqual(NotImplemented, p.__add__(5)) |
| 28 | + |
| 29 | + def test_sub_interval(self): |
| 30 | + p1 = PendulumInterval(days=23, seconds=32) |
| 31 | + p2 = PendulumInterval(days=12, seconds=28) |
| 32 | + |
| 33 | + p = p1 - p2 |
| 34 | + self.assertInterval(p, 1, 4, 0, 0, 4) |
| 35 | + |
| 36 | + def test_sub_timedelta(self): |
| 37 | + p1 = PendulumInterval(days=23, seconds=32) |
| 38 | + p2 = timedelta(days=12, seconds=28) |
| 39 | + |
| 40 | + p = p1 - p2 |
| 41 | + self.assertInterval(p, 1, 4, 0, 0, 4) |
| 42 | + |
| 43 | + def test_sub_unsupported(self): |
| 44 | + p = PendulumInterval(days=23, seconds=32) |
| 45 | + self.assertEqual(NotImplemented, p.__sub__(5)) |
| 46 | + |
| 47 | + def test_neg(self): |
| 48 | + p = PendulumInterval(days=23, seconds=32) |
| 49 | + self.assertInterval(-p, -4, -5, 0, 0, -28) |
0 commit comments