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