Exemple #1
0
    def test_invalid_str(self):
        """This tests that invalid strings fed into from_str raise exceptions."""

        tests_ts = [
            "a", "2015-02-17T12:53:48.5", "2015-02T12:53:48.5",
            "2015-02-17T12:53.5", "12:53:48.5"
        ]

        for t in tests_ts:
            try:
                Timestamp.from_str(t)
                self.assertTrue(False)
            except:
                pass
Exemple #2
0
    def test_invalid_str(self):
        """This tests that invalid strings fed into from_str raise exceptions."""
        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_ts = [
            "a", "2015-02-17T12:53:48.5", "2015-02T12:53:48.5",
            "2015-02-17T12:53.5", "12:53:48.5"
        ]

        for t in tests_ts:
            try:
                Timestamp.from_str(t)
                self.assertTrue(False)
            except:
                pass
Exemple #3
0
    def test_from_str(self):
        """Conversion from string formats."""

        tests = [
            ("2015-01-23T12:34:56F00 30000/1001 UTC-05:00 TAI-35",
             Timestamp(1422034531, 17100000)),
            ("2015-01-23T12:34:56.0Z", Timestamp(1422016531, 0)),
            ("now", Timestamp(0, 0)),
        ]

        for t in tests:
            with mock.patch("time.time", return_value=0.0):
                self.assertEqual(
                    Timestamp.from_str(t[0], force_pure_python=True), t[1])
Exemple #4
0
    def test_convert_str(self):
        """This tests that various string formats can be converted to timestamps."""

        tests_ts = [
            ("1:2", Timestamp(1, 2)), ("1.2", Timestamp(1, 200000000)),
            ("1", Timestamp(1, 0)),
            ("2015-02-17T12:53:48.5Z", Timestamp(1424177663, 500000000)),
            ("2015-02-17T12:53:48.000102003Z", Timestamp(1424177663, 102003))
        ]

        for t in tests_ts:
            ts = Timestamp.from_str(t[0])
            self.assertTrue(isinstance(ts, Timestamp))
            self.assertEqual(ts, t[1])
Exemple #5
0
    def test_from_str(self):
        """Conversion from string formats."""
        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 = [
            ("2015-01-23T12:34:56F00 30000/1001 UTC-05:00 TAI-35",
             Timestamp(1422034531, 17100000)),
            ("2015-01-23T12:34:56.0Z", Timestamp(1422016531, 0)),
            ("now", Timestamp(0, 0)),
        ]

        for t in tests:
            with mock.patch("time.time", return_value=0.0):
                self.assertEqual(Timestamp.from_str(t[0]), t[1])
Exemple #6
0
    def test_convert_str(self):
        """This tests that various string formats can be converted to 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)

        tests_ts = [
            ("1:2", Timestamp(1, 2)), ("1.2", Timestamp(1, 200000000)),
            ("1", Timestamp(1, 0)),
            ("2015-02-17T12:53:48.5Z", Timestamp(1424177663, 500000000)),
            ("2015-02-17T12:53:48.000102003Z", Timestamp(1424177663, 102003))
        ]

        for t in tests_ts:
            ts = Timestamp.from_str(t[0])
            self.assertTrue(isinstance(ts, Timestamp))
            self.assertEqual(ts, t[1])
Exemple #7
0
def parse_resp_timestamps(resp):
    return {
        k: Timestamp.from_str(v).to_sec_nsec() if k in V2_0_TS_KEYS else v
        for k, v in resp.iteritems()
    }