def test_import_with_ipp(self): """This tests the import of the module and ensures that when the pyipputils module is installed it will defer to that module.""" with mock.patch('__builtin__.__import__', side_effect=import_mock("pyipputils.ipptimestamp", True)): reload(nmoscommon.timestamp) from nmoscommon.timestamp import IPP_UTILS, Timestamp self.assertTrue(IPP_UTILS) mock_imports[ "pyipputils.ipptimestamp"].ipptimestamp.ipp_ts_gettime.return_value = ( 1, 23, 17) self.assertEqual(Timestamp.get_time(), Timestamp(23, 17))
def test_get_time_pythonic(self): """This tests that the fallback pure python implementation of get_time works as expected.""" test_ts = [(1512489451.0, Timestamp(1512489451 + 37, 0)), (1512489451.1, Timestamp(1512489451 + 37, 100000000))] for t in test_ts: with mock.patch("time.time") as time: time.return_value = t[0] gottime = Timestamp.get_time(force_pure_python=True) self.assertEqual(gottime, t[1], msg="Times not equal, expected: %r, got %r" % (t[1], gottime))
def test_get_time_pythonic(self): """This tests that the fallback pure python implementation of get_time works as expected.""" 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) test_ts = [(1512489451.0, Timestamp(1512489451 + 37, 0)), (1512489451.1, Timestamp(1512489451 + 37, 100000000))] for t in test_ts: with mock.patch("time.time") as time: time.return_value = t[0] gottime = Timestamp.get_time() self.assertEqual(gottime, t[1], msg="Times not equal, expected: %r, got %r" % (t[1], gottime))