@@ -104,7 +104,7 @@ def test_expand_and_restore(self):
104104class TestConvertJSON (unittest .TestCase ):
105105
106106 def test_convert_expand (self ):
107- fin = io .StringIO ( '{"a":{"b":3}}\n {"a":{"c":4}}\n ' )
107+ fin = io .BytesIO ( u '{"a":{"b":3}}\n {"a":{"c":4}}\n '. encode ( 'utf-8' ) )
108108 fout = io .BytesIO ()
109109
110110 convert_json (fin , fout , expand )
@@ -114,8 +114,19 @@ def test_convert_expand(self):
114114 fin .close ()
115115 fout .close ()
116116
117+ def test_convert_with_unicode (self ):
118+ fin = io .BytesIO (u'{"河流":{"长度":3}}\n {"河流":{"名字":"长江"}}\n ' .encode ('utf-8' ))
119+ fout = io .BytesIO ()
120+
121+ convert_json (fin , fout , expand )
122+
123+ self .assertEqual (u'{"河流.长度": 3}\n {"河流.名字": "长江"}\n ' .encode ('utf-8' ), fout .getvalue ())
124+
125+ fin .close ()
126+ fout .close ()
127+
117128 def test_convert_restore (self ):
118- fin = io .StringIO ( '{"a.b": 3}\n {"a.c": 4}\n ' )
129+ fin = io .BytesIO ( u '{"a.b": 3}\n {"a.c": 4}\n '. encode ( 'utf-8' ) )
119130 fout = io .BytesIO ()
120131
121132 convert_json (fin , fout , restore )
@@ -126,7 +137,7 @@ def test_convert_restore(self):
126137 fout .close ()
127138
128139 def test_convert_expand_json_array (self ):
129- fin = io .StringIO ( '[{"a":{"b":3}},{"a":{"c":4}}]' )
140+ fin = io .BytesIO ( u '[{"a":{"b":3}},{"a":{"c":4}}]'. encode ( 'utf-8' ) )
130141 fout = io .BytesIO ()
131142
132143 convert_json (fin , fout , expand , json_array = True )
0 commit comments