Changeset 368 for pyyaml/tags/3.09/tests/lib3/test_input_output.py
- Timestamp:
- 08/31/09 05:13:59 (4 years ago)
- File:
-
- 1 edited
-
pyyaml/tags/3.09/tests/lib3/test_input_output.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pyyaml/tags/3.09/tests/lib3/test_input_output.py
r336 r368 1 1 2 2 import yaml 3 import codecs, io 3 import codecs, io, tempfile, os, os.path 4 4 5 5 def test_unicode_input(unicode_filename, verbose=False): … … 95 95 test_unicode_output.unittest = ['.unicode'] 96 96 97 def test_file_output(unicode_filename, verbose=False): 98 data = open(unicode_filename, 'rb').read().decode('utf-8') 99 handle, filename = tempfile.mkstemp() 100 os.close(handle) 101 try: 102 stream = io.StringIO() 103 yaml.dump(data, stream, allow_unicode=True) 104 data1 = stream.getvalue() 105 stream = io.BytesIO() 106 yaml.dump(data, stream, encoding='utf-16-le', allow_unicode=True) 107 data2 = stream.getvalue().decode('utf-16-le')[1:] 108 stream = open(filename, 'w', encoding='utf-16-le') 109 yaml.dump(data, stream, allow_unicode=True) 110 stream.close() 111 data3 = open(filename, 'r', encoding='utf-16-le').read() 112 stream = open(filename, 'wb') 113 yaml.dump(data, stream, encoding='utf-8', allow_unicode=True) 114 stream.close() 115 data4 = open(filename, 'r', encoding='utf-8').read() 116 assert data1 == data2, (data1, data2) 117 assert data1 == data3, (data1, data3) 118 assert data1 == data4, (data1, data4) 119 finally: 120 if os.path.exists(filename): 121 os.unlink(filename) 122 123 test_file_output.unittest = ['.unicode'] 124 97 125 def test_unicode_transfer(unicode_filename, verbose=False): 98 126 data = open(unicode_filename, 'rb').read().decode('utf-8')
Note: See TracChangeset
for help on using the changeset viewer.
