コード例 #1
0
    def test_ts_convert_tai_sec_nsec(self):
        """This tests that the conversion to and from TAI second:nanosecond pairs works as expected."""

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

        for t in tests_ts:
            ts = Timestamp.from_sec_nsec(t[0])
            self.assertTrue(isinstance(ts, Timestamp),
                            msg="Called with {} {} {}".format(
                                t[0], t[1], t[2]))
            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]))
コード例 #2
0
ファイル: test_json.py プロジェクト: nigelmegitt/nmos-common
PURE_JSON_STRING = '{"foo": "bar", "baz": ["boop", "beep"], "boggle": {"cat": "\\u732b", "kitten": "\\u5b50\\u732b"}, "numeric": 25, "boolean": true, "decimal": 0.44}'

NMOS_JSON_DATA = {
    "foo": "bar",
    "baz": ["boop", "beep"],
    "boggle": {
        "cat": u"\u732b",
        "kitten": u"\u5b50\u732b"
    },
    "numeric": 25,
    "boolean": True,
    "decimal": 0.44,
    "uuid": UUID("b8b4a34f-3293-11e8-89c0-acde48001122"),
    "rational": Fraction(30000, 1001),
    "timestamp": Timestamp.from_sec_nsec("417798915:0")
}

NMOS_JSON_STRING = '{"foo": "bar", "baz": ["boop", "beep"], "boggle": {"cat": "\\u732b", "kitten": "\\u5b50\\u732b"}, "numeric": 25, "boolean": true, "decimal": 0.44, "uuid": "b8b4a34f-3293-11e8-89c0-acde48001122", "rational": {"numerator": 30000, "denominator": 1001}, "timestamp": "417798915:0"}'


class TestJSON(unittest.TestCase):
    def test_dump_pure_json(self):
        fp = StringIO()

        nmos_json.dump(PURE_JSON_DATA, fp)

        decoded = json.loads(fp.getvalue())
        self.assertEqual(PURE_JSON_DATA, decoded)

    def test_dumps_pure_json(self):