Beispiel #1
0
    def test_safe_to_json(self):

        self.assertEqual(u'adj12321nv', Parser.safe_to_json(u'adj12321nv'))

        self.assertEqual(u'5.2', Parser.safe_to_json(5.2))

        class Special(object):
            bal = 5.3
            test = 'stuffing'

            def __init__(self):
                self.newval = 'cherries'

        self.assertEqual({'newval': 'cherries'}, Parser.safe_to_json(Special()))
Beispiel #2
0
    def test_safe_to_json(self):
        class Example:
            x = 1
            y = 2

        result = Parser.safe_to_json(Example)
        self.assertEqual(result, {'x': 1, 'y': 2})

        result = Parser.safe_to_json("Example1")
        self.assertEqual(result, "Example1")

        result = Parser.safe_to_json(bytes("Example", "utf-8"))
        self.assertEqual(result, "Example")
        result = Parser.safe_to_json(1)
        self.assertEqual(result, "1")