Beispiel #1
0
    def test_convert_sec_frac(self):
        """This tests that the conversion to and from TAI seconds with fractional parts works as expected."""

        tests_ts = [("0.0", TimeOffset(0, 0), "0.0"),
                    ("0.1", TimeOffset(0, 1000000000 // 10), "0.1"),
                    ("-0.1", TimeOffset(0, 1000000000 // 10, -1), "-0.1"),
                    ("5", TimeOffset(5, 0), "5.0"),
                    ("5.1", TimeOffset(5, 1000000000 // 10), "5.1"),
                    ("-5.1", TimeOffset(5, 1000000000 // 10, -1), "-5.1"),
                    ("5.10000000", TimeOffset(5, 1000000000 // 10), "5.1"),
                    ("5.123456789", TimeOffset(5, 123456789), "5.123456789"),
                    ("5.000000001", TimeOffset(5, 1), "5.000000001"),
                    ("5.0000000001", TimeOffset(5, 0), "5.0")]

        for t in tests_ts:
            ts = TimeOffset.from_sec_frac(t[0])
            self.assertEqual(ts,
                             t[1],
                             msg="Called with {} {} {}".format(
                                 t[0], t[1], t[2]))
            ts_str = ts.to_sec_frac()
            self.assertEqual(ts_str,
                             t[2],
                             msg="Called with {} {} {}".format(
                                 t[0], t[1], t[2]))
Beispiel #2
0
    def test_from_sec_frac(self):
        """This tests that timeoffsets can be instantiated from fractional second values."""
        tests_ts = [
            (TimeOffset.from_sec_frac("1.000000001"), TimeOffset(1, 1)),
            (TimeOffset.from_sec_frac("-1.000000001"), TimeOffset(1,
                                                                  1,
                                                                  sign=-1)),
            (TimeOffset.from_sec_frac("1.000001POTATO"), TimeOffset(1, 1000)),
            (TimeOffset.from_sec_frac("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_frac(*params)