Changeset 366 for pyyaml/trunk/tests
- Timestamp:
- 08/31/09 04:47:05 (3 years ago)
- Location:
- pyyaml/trunk/tests
- Files:
-
- 2 modified
-
lib/test_input_output.py (modified) (2 diffs)
-
lib3/test_input_output.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pyyaml/trunk/tests/lib/test_input_output.py
r335 r366 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 try: 102 stream = StringIO.StringIO() 103 yaml.dump(data, stream, allow_unicode=True) 104 data1 = stream.getvalue() 105 stream = open(filename, 'wb') 106 yaml.dump(data, stream, allow_unicode=True) 107 stream.close() 108 data2 = open(filename, 'rb').read() 109 stream = open(filename, 'wb') 110 yaml.dump(data, stream, encoding='utf-16-le', allow_unicode=True) 111 stream.close() 112 data3 = open(filename, 'rb').read().decode('utf-16-le')[1:].encode('utf-8') 113 stream = _unicode_open(open(filename, 'wb'), 'utf-8') 114 yaml.dump(data, stream, allow_unicode=True) 115 stream.close() 116 data4 = open(filename, 'rb').read() 117 assert data1 == data2, (data1, data2) 118 assert data1 == data3, (data1, data3) 119 assert data1 == data4, (data1, data4) 120 finally: 121 if os.path.exists(filename): 122 os.unlink(filename) 123 124 test_file_output.unittest = ['.unicode'] 125 98 126 def test_unicode_transfer(unicode_filename, verbose=False): 99 127 data = open(unicode_filename, 'rb').read().decode('utf-8') -
pyyaml/trunk/tests/lib3/test_input_output.py
r336 r366 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 try: 101 stream = io.StringIO() 102 yaml.dump(data, stream, allow_unicode=True) 103 data1 = stream.getvalue() 104 stream = io.BytesIO() 105 yaml.dump(data, stream, encoding='utf-16-le', allow_unicode=True) 106 data2 = stream.getvalue().decode('utf-16-le')[1:] 107 stream = open(filename, 'w', encoding='utf-16-le') 108 yaml.dump(data, stream, allow_unicode=True) 109 stream.close() 110 data3 = open(filename, 'r', encoding='utf-16-le').read() 111 stream = open(filename, 'wb') 112 yaml.dump(data, stream, encoding='utf-8', allow_unicode=True) 113 stream.close() 114 data4 = open(filename, 'r', encoding='utf-8').read() 115 assert data1 == data2, (data1, data2) 116 assert data1 == data3, (data1, data3) 117 assert data1 == data4, (data1, data4) 118 finally: 119 if os.path.exists(filename): 120 os.unlink(filename) 121 122 test_file_output.unittest = ['.unicode'] 123 97 124 def test_unicode_transfer(unicode_filename, verbose=False): 98 125 data = open(unicode_filename, 'rb').read().decode('utf-8')
