Phongphan Phuttha | 7f01e2a | 2015-11-06 15:46:50 +0700 | [diff] [blame] | 1 | from thrift import Thrift |
| 2 | from thrift.protocol.TJSONProtocol import TJSONProtocol |
| 3 | from thrift.transport import TTransport |
| 4 | |
| 5 | import sys |
| 6 | import unittest |
| 7 | |
| 8 | # |
| 9 | # In order to run the test under Windows. We need to create symbolic link |
| 10 | # name 'thrift' to '../src' folder by using: |
| 11 | # |
| 12 | # mklink /D thrift ..\src |
| 13 | # |
| 14 | |
| 15 | class TestJSONString(unittest.TestCase): |
| 16 | |
| 17 | def test_escaped_unicode_string(self): |
Phongphan Phuttha | 369d62e | 2015-11-09 02:05:09 +0700 | [diff] [blame] | 18 | unicode_json = b'"hello \\u0e01\\u0e02\\u0e03\\ud835\\udcab\\udb40\\udc70 unicode"' |
| 19 | unicode_text = u'hello \u0e01\u0e02\u0e03\U0001D4AB\U000E0070 unicode' |
Phongphan Phuttha | 7f01e2a | 2015-11-06 15:46:50 +0700 | [diff] [blame] | 20 | |
| 21 | buf = TTransport.TMemoryBuffer(unicode_json) |
| 22 | transport = TTransport.TBufferedTransportFactory().getTransport(buf) |
| 23 | protocol = TJSONProtocol(transport) |
| 24 | |
| 25 | if sys.version_info[0] == 2: |
| 26 | unicode_text = unicode_text.encode('utf8') |
| 27 | self.assertEqual(protocol.readString(), unicode_text) |
| 28 | |
| 29 | if __name__ == '__main__': |
| 30 | unittest.main() |
| 31 | |