Exemplo n.º 1
0
    def test_from_datetime(self):
        """Conversion from python's datetime object."""

        tests = [
            (datetime(1970, 1, 1, 0, 0, 0, 0,
                      tz.gettz('UTC')), Timestamp(0, 0)),
            (datetime(1983, 3, 29, 15, 45, 0, 0,
                      tz.gettz('UTC')), Timestamp(417800721, 0)),
            (datetime(2017, 12, 5, 16, 33, 12, 196,
                      tz.gettz('UTC')), Timestamp(1512491629, 196000)),
        ]

        for t in tests:
            self.assertEqual(Timestamp.from_datetime(t[0]), t[1])
Exemplo n.º 2
0
    def test_from_datetime(self):
        """Conversion from python's datetime object."""
        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)

        tests = [
            (datetime(1970, 1, 1, 0, 0, 0, 0,
                      tz.gettz('UTC')), Timestamp(0, 0)),
            (datetime(1983, 3, 29, 15, 45, 0, 0,
                      tz.gettz('UTC')), Timestamp(417800721, 0)),
            (datetime(2017, 12, 5, 16, 33, 12, 196,
                      tz.gettz('UTC')), Timestamp(1512491629, 196000)),
        ]

        for t in tests:
            self.assertEqual(Timestamp.from_datetime(t[0]), t[1])