MCPcopy Create free account
hub / github.com/apache/thrift / test_TJSONProtocol_write

Method test_TJSONProtocol_write

lib/py/test/thrift_json.py:46–72  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

44 self.assertEqual(protocol.readString(), unicode_text)
45
46 def test_TJSONProtocol_write(self):
47 write_data = '{"software":"thrift","1":[23,1.2010000000000001,32767,2147483647,9223372036854775807],"base64":"aGVsbG8gdGhyaWZ0","bool":0}'
48
49 buff = TTransport.TMemoryBuffer()
50 transport = TTransport.TBufferedTransportFactory().getTransport(buff)
51 protocol = TJSONProtocol(transport)
52 protocol.writeJSONObjectStart()
53 protocol.writeJSONString("software")
54 protocol.writeJSONString("thrift")
55 protocol.writeJSONString("1")
56 protocol.writeJSONArrayStart()
57 protocol.writeJSONNumber(23)
58 protocol.writeDouble(1.201)
59 protocol.writeI16(32767)
60 protocol.writeI32(2147483647)
61 protocol.writeI64(9223372036854775807)
62 protocol.writeJSONArrayEnd()
63 protocol.writeJSONString("base64")
64 protocol.writeJSONBase64("hello thrift".encode('utf-8'))
65 protocol.writeJSONString("bool")
66 protocol.writeBool(0)
67 protocol.writeJSONObjectEnd()
68
69 transport.flush()
70 value = buff.getvalue()
71
72 self.assertEqual(write_data, value.decode('utf-8'))
73
74 def test_TJSONProtol_read(self):
75 expected = "{'software':'thrift','1':[23,1.2010000000000001,32767,2147483647,9223372036854775807],'base64':'hello thrift','bool':False}"

Callers

nothing calls this directly

Calls 15

writeJSONObjectStartMethod · 0.95
writeJSONStringMethod · 0.95
writeJSONArrayStartMethod · 0.95
writeDoubleMethod · 0.95
writeI16Method · 0.95
writeI32Method · 0.95
writeI64Method · 0.95
writeJSONArrayEndMethod · 0.95
writeJSONBase64Method · 0.95
writeBoolMethod · 0.95
writeJSONObjectEndMethod · 0.95
getvalueMethod · 0.95

Tested by

no test coverage detected