Ejemplo n.º 1
0
    def test_iaddsub(self):
        """This tests integer addition and subtraction on timestamps."""
        with mock.patch('__builtin__.__import__',
                        side_effect=import_mock("pyipputils.ipptimestamp",
                                                False)):
            reload(nmoscommon.timestamp)
            from nmoscommon.timestamp import Timestamp, TimeOffset, IPP_UTILS, TsValueError
            self.assertFalse(IPP_UTILS)

        ts = Timestamp(10, 0)
        ts += TimeOffset(1, 2)
        self.assertEqual(ts, Timestamp(11, 2))
        ts -= TimeOffset(1, 2)
        self.assertEqual(ts, Timestamp(10, 0))
        ts -= TimeOffset(100, 5)
        self.assertTrue(ts.is_null())
        ts = Timestamp(281474976710655, 999999999)
        ts += TimeOffset(0, 1)
        self.assertEqual(ts, Timestamp(281474976710655, 999999999))
        toff = TimeOffset(10, 0)
        toff -= TimeOffset(100, 0)
        self.assertEqual(toff, TimeOffset(90, 0, -1))
        toff = TimeOffset(10, 0)
        toff -= TimeOffset(0, 1)
        self.assertEqual(toff, TimeOffset(9, 999999999))
        toff = TimeOffset(10, 500000000)
        toff += TimeOffset(0, 500000000)
        self.assertEqual(toff, TimeOffset(11, 0))
        toff = TimeOffset(10, 500000000, -1)
        toff -= TimeOffset(0, 500000000)
        self.assertEqual(toff, TimeOffset(11, 0, -1))
        toff = TimeOffset(10, 0, -1)
        toff += TimeOffset(0, 500000000)
        self.assertEqual(toff, TimeOffset(9, 500000000, -1))
Ejemplo n.º 2
0
 def test_iaddsub(self):
     """This tests integer addition and subtraction on timestamps."""
     ts = Timestamp(10, 0)
     ts += TimeOffset(1, 2)
     self.assertEqual(ts, Timestamp(11, 2))
     ts -= TimeOffset(1, 2)
     self.assertEqual(ts, Timestamp(10, 0))
     ts -= TimeOffset(100, 5)
     self.assertTrue(ts.is_null())
     ts = Timestamp(281474976710655, 999999999)
     ts += TimeOffset(0, 1)
     self.assertEqual(ts, Timestamp(281474976710655, 999999999))
     toff = TimeOffset(10, 0)
     toff -= TimeOffset(100, 0)
     self.assertEqual(toff, TimeOffset(90, 0, -1))
     toff = TimeOffset(10, 0)
     toff -= TimeOffset(0, 1)
     self.assertEqual(toff, TimeOffset(9, 999999999))
     toff = TimeOffset(10, 500000000)
     toff += TimeOffset(0, 500000000)
     self.assertEqual(toff, TimeOffset(11, 0))
     toff = TimeOffset(10, 500000000, -1)
     toff -= TimeOffset(0, 500000000)
     self.assertEqual(toff, TimeOffset(11, 0, -1))
     toff = TimeOffset(10, 0, -1)
     toff += TimeOffset(0, 500000000)
     self.assertEqual(toff, TimeOffset(9, 500000000, -1))