Changeset 334 for pyyaml/trunk/tests
- Timestamp:
- 12/30/08 08:30:52 (3 years ago)
- Location:
- pyyaml/trunk/tests
- Files:
-
- 3 modified
- 4 copied
-
data/invalid-base64-data-2.loader-error (copied) (copied from pyyaml/trunk/tests/data/invalid-base64-data.loader-error) (1 diff)
-
data/invalid-python-bytes-2-py3.loader-error (copied) (copied from pyyaml/trunk/tests/data/invalid-base64-data.loader-error) (1 diff)
-
data/invalid-python-bytes-py3.loader-error (copied) (copied from pyyaml/trunk/tests/data/invalid-base64-data.loader-error) (1 diff)
-
lib/test_input_output.py (modified) (1 diff)
-
lib3/test_input_output.py (copied) (copied from pyyaml/trunk/tests/lib/test_input_output.py) (5 diffs)
-
lib3/test_yaml.py (modified) (1 diff)
-
lib3/test_yaml_ext.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
pyyaml/trunk/tests/data/invalid-base64-data-2.loader-error
r140 r334 1 1 --- !!binary 2 binary data encoded in base64 should be here.2 ЎвПОÑМÑе ЎаММÑе в base64 -
pyyaml/trunk/tests/data/invalid-python-bytes-2-py3.loader-error
r140 r334 1 --- !! binary2 binary data encoded in base64 should be here.1 --- !!python/bytes 2 ЎвПОÑМÑе ЎаММÑе в base64 -
pyyaml/trunk/tests/data/invalid-python-bytes-py3.loader-error
r140 r334 1 --- !! binary1 --- !!python/bytes 2 2 binary data encoded in base64 should be here. -
pyyaml/trunk/tests/lib/test_input_output.py
r333 r334 54 54 data = open(unicode_filename, 'rb').read().decode('utf-8') 55 55 value = ' '.join(data.split()) 56 for encoding in [None, 'utf-8', 'utf-16-be', 'utf-16-le']:57 for allow_unicode in [False, True]:58 data1 = yaml.dump(value, allow_unicode=allow_unicode)56 for allow_unicode in [False, True]: 57 data1 = yaml.dump(value, allow_unicode=allow_unicode) 58 for encoding in [None, 'utf-8', 'utf-16-be', 'utf-16-le']: 59 59 stream = StringIO.StringIO() 60 60 yaml.dump(value, _unicode_open(stream, 'utf-8'), encoding=encoding, allow_unicode=allow_unicode) -
pyyaml/trunk/tests/lib3/test_input_output.py
r333 r334 1 1 2 2 import yaml 3 import codecs, StringIO 4 5 def _unicode_open(file, encoding, errors='strict'): 6 info = codecs.lookup(encoding) 7 srw = codecs.StreamReaderWriter(file, info.streamreader, info.streamwriter, errors) 8 srw.encoding = encoding 9 return srw 3 import codecs, io 10 4 11 5 def test_unicode_input(unicode_filename, verbose=False): 12 6 data = open(unicode_filename, 'rb').read().decode('utf-8') 13 7 value = ' '.join(data.split()) 14 output = yaml.load( _unicode_open(StringIO.StringIO(data.encode('utf-8')), 'utf-8'))8 output = yaml.load(data) 15 9 assert output == value, (output, value) 16 for input in [data, data.encode('utf-8'), 10 output = yaml.load(io.StringIO(data)) 11 assert output == value, (output, value) 12 for input in [data.encode('utf-8'), 17 13 codecs.BOM_UTF8+data.encode('utf-8'), 18 14 codecs.BOM_UTF16_BE+data.encode('utf-16-be'), 19 15 codecs.BOM_UTF16_LE+data.encode('utf-16-le')]: 20 16 if verbose: 21 print "INPUT:", repr(input[:10]), "..."17 print("INPUT:", repr(input[:10]), "...") 22 18 output = yaml.load(input) 23 19 assert output == value, (output, value) 24 output = yaml.load( StringIO.StringIO(input))20 output = yaml.load(io.BytesIO(input)) 25 21 assert output == value, (output, value) 26 22 … … 33 29 codecs.BOM_UTF8+data.encode('utf-16-be'), 34 30 codecs.BOM_UTF16_BE+data.encode('utf-16-le'), 35 codecs.BOM_UTF16_LE+data.encode('utf-8')+ '!']:31 codecs.BOM_UTF16_LE+data.encode('utf-8')+b'!']: 36 32 try: 37 33 yaml.load(input) 38 except yaml.YAMLError ,exc:34 except yaml.YAMLError as exc: 39 35 if verbose: 40 print exc36 print(exc) 41 37 else: 42 38 raise AssertionError("expected an exception") 43 39 try: 44 yaml.load( StringIO.StringIO(input))45 except yaml.YAMLError ,exc:40 yaml.load(io.BytesIO(input)) 41 except yaml.YAMLError as exc: 46 42 if verbose: 47 print exc43 print(exc) 48 44 else: 49 45 raise AssertionError("expected an exception") … … 54 50 data = open(unicode_filename, 'rb').read().decode('utf-8') 55 51 value = ' '.join(data.split()) 56 for encoding in [None, 'utf-8', 'utf-16-be', 'utf-16-le']:57 for allow_unicode in [False, True]:58 data1 = yaml.dump(value, allow_unicode=allow_unicode)59 stream = StringIO.StringIO()60 yaml.dump(value, _unicode_open(stream, 'utf-8'), encoding=encoding, allow_unicode=allow_unicode)52 for allow_unicode in [False, True]: 53 data1 = yaml.dump(value, allow_unicode=allow_unicode) 54 for encoding in [None, 'utf-8', 'utf-16-be', 'utf-16-le']: 55 stream = io.StringIO() 56 yaml.dump(value, stream, encoding=encoding, allow_unicode=allow_unicode) 61 57 data2 = stream.getvalue() 62 58 data3 = yaml.dump(value, encoding=encoding, allow_unicode=allow_unicode) 63 stream = StringIO.StringIO() 64 yaml.dump(value, stream, encoding=encoding, allow_unicode=allow_unicode) 65 data4 = stream.getvalue() 59 stream = io.BytesIO() 60 if encoding is None: 61 try: 62 yaml.dump(value, stream, encoding=encoding, allow_unicode=allow_unicode) 63 except TypeError as exc: 64 if verbose: 65 print(exc) 66 data4 = None 67 else: 68 raise AssertionError("expected an exception") 69 else: 70 yaml.dump(value, stream, encoding=encoding, allow_unicode=allow_unicode) 71 data4 = stream.getvalue() 72 if verbose: 73 print("BYTES:", data4[:50]) 74 data4 = data4.decode(encoding) 66 75 for copy in [data1, data2, data3, data4]: 76 if copy is None: 77 continue 78 assert isinstance(copy, str) 67 79 if allow_unicode: 68 80 try: 69 81 copy[4:].encode('ascii') 70 except (UnicodeDecodeError, UnicodeEncodeError),exc:82 except UnicodeEncodeError as exc: 71 83 if verbose: 72 print exc84 print(exc) 73 85 else: 74 86 raise AssertionError("expected an exception") … … 76 88 copy[4:].encode('ascii') 77 89 assert isinstance(data1, str), (type(data1), encoding) 78 data1.decode('utf-8')79 90 assert isinstance(data2, str), (type(data2), encoding) 80 data2.decode('utf-8')81 if encoding is None:82 assert isinstance(data3, unicode), (type(data3), encoding)83 assert isinstance(data4, unicode), (type(data4), encoding)84 else:85 assert isinstance(data3, str), (type(data3), encoding)86 data3.decode(encoding)87 assert isinstance(data4, str), (type(data4), encoding)88 data4.decode(encoding)89 91 90 92 test_unicode_output.unittest = ['.unicode'] … … 95 97 input = data 96 98 if encoding is not None: 97 input = ( u'\ufeff'+input).encode(encoding)99 input = ('\ufeff'+input).encode(encoding) 98 100 output1 = yaml.emit(yaml.parse(input), allow_unicode=True) 99 stream = StringIO.StringIO() 100 yaml.emit(yaml.parse(input), _unicode_open(stream, 'utf-8'), 101 allow_unicode=True) 101 if encoding is None: 102 stream = io.StringIO() 103 else: 104 stream = io.BytesIO() 105 yaml.emit(yaml.parse(input), stream, allow_unicode=True) 102 106 output2 = stream.getvalue() 107 assert isinstance(output1, str), (type(output1), encoding) 103 108 if encoding is None: 104 assert isinstance(output 1, unicode), (type(output1), encoding)109 assert isinstance(output2, str), (type(output1), encoding) 105 110 else: 106 assert isinstance(output1, str), (type(output1), encoding) 107 output1.decode(encoding) 108 assert isinstance(output2, str), (type(output2), encoding) 109 output2.decode('utf-8') 111 assert isinstance(output2, bytes), (type(output1), encoding) 112 output2.decode(encoding) 110 113 111 114 test_unicode_transfer.unittest = ['.unicode'] -
pyyaml/trunk/tests/lib3/test_yaml.py
r330 r334 11 11 from test_representer import * 12 12 from test_recursive import * 13 from test_input_output import * 13 14 14 15 if __name__ == '__main__': -
pyyaml/trunk/tests/lib3/test_yaml_ext.py
r331 r334 262 262 263 263 import test_tokens, test_structure, test_errors, test_resolver, test_constructor, \ 264 test_emitter, test_representer, test_recursive 264 test_emitter, test_representer, test_recursive, test_input_output 265 265 wrap_ext([test_tokens, test_structure, test_errors, test_resolver, test_constructor, 266 test_emitter, test_representer, test_recursive ])266 test_emitter, test_representer, test_recursive, test_input_output]) 267 267 268 268 if __name__ == '__main__':
