Пример #1
0
    def test_from_sec_nsec(self):
        """This tests that time offsets can be created from second:nanosecond pairs."""
        tests_ts = [
            (TimeOffset.from_sec_nsec("1:1"), TimeOffset(1, 1)),
            (TimeOffset.from_sec_nsec("-1:1"), TimeOffset(1, 1, sign=-1)),
            (TimeOffset.from_sec_nsec("1"), TimeOffset(1, 0)),
        ]

        for t in tests_ts:
            self.assertEqual(t[0], t[1])

        bad_params = [
            ("0:0:1", ),
        ]

        for params in bad_params:
            with self.assertRaises(TsValueError):
                TimeOffset.from_sec_nsec(*params)
Пример #2
0
    def test_convert_sec_nsec(self):
        """This tests that the conversion to and from TAI second:nanosecond pairs works as expected."""

        tests_ts = [("0:0", TimeOffset(0, 0), "0:0"),
                    ("0:1", TimeOffset(0, 1), "0:1"),
                    ("-0:1", TimeOffset(0, 1, -1), "-0:1"),
                    ("5", TimeOffset(5, 0), "5:0"),
                    ("5:1", TimeOffset(5, 1), "5:1"),
                    ("-5:1", TimeOffset(5, 1, -1), "-5:1"),
                    ("5:999999999", TimeOffset(5, 999999999), "5:999999999")]

        for t in tests_ts:
            ts = TimeOffset.from_sec_nsec(t[0])
            self.assertEqual(ts,
                             t[1],
                             msg="Called with {} {} {}".format(
                                 t[0], t[1], t[2]))
            ts_str = ts.to_sec_nsec()
            self.assertEqual(ts_str,
                             t[2],
                             msg="Called with {} {} {}".format(
                                 t[0], t[1], t[2]))