示例#1
0
    def test_json_stream_simpleobj(self):

        sessionId = 'some_id'
        for obj in (1, {'a': 2}, 'b', {'sessionId': sessionId}):
            stream = utils.JSONStream(obj)
            self.assertEqual(obj, json.loads(stream.read(100).decode('latin1')))
            self.assertEqual(0, len(stream.read(100).decode('latin1')))
示例#2
0
    def test_json_stream_simpleobj(self):

        sessionId = "some_id"
        for obj in (1, {"a": 2}, "b", {"sessionId": sessionId}):
            stream = utils.JSONStream(obj)
            self.assertEqual(obj,
                             json.loads(stream.read(100).decode("latin1")))
            self.assertEqual(0, len(stream.read(100).decode("latin1")))
示例#3
0
    def test_json_stream_sequences(self):

        ref = [1, 2, 3]
        objects_list = [1, 2, 3]
        objects_tuple = (1, 2, 3)

        def objects_gen():
            yield 1;
            yield 2;
            yield 3

        for objects in (objects_list, objects_tuple, objects_gen()):
            stream = utils.JSONStream(objects)
            self.assertSequenceEqual(ref, json.loads(stream.read(100).decode('latin1')))
            self.assertEqual(0, len(stream.read(100).decode('latin1')))
示例#4
0
 def test_json_stream_simple_sequence(self):
     for s in ([0], [{}], ['a'], [{'oid': 'A', 'type': 'plain'}]):
         stream = utils.JSONStream(s)
         self.assertEqual(s, json.loads(stream.read(100).decode('utf8')))
示例#5
0
 def test_json_stream_simple_sequence(self):
     for s in ([0], [{}], ["a"], [{"oid": "A", "type": "plain"}]):
         stream = utils.JSONStream(s)
         self.assertEqual(s, json.loads(stream.read(100).decode("utf8")))