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')))
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")))
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')))
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')))
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")))