source: pyyaml/trunk/tests3/test_reader.py @ 328

Revision 328, 957 bytes checked in by xi, 6 years ago (diff)

Added basic support for Python 3 (Thanks idadesub(at)users(dot)sourceforge(dot)net).

Line 
1
2import yaml.reader
3
4def _run_reader(data, verbose):
5    try:
6        stream = yaml.reader.Reader(data)
7        while stream.peek() != '\0':
8            stream.forward()
9    except yaml.reader.ReaderError as exc:
10        if verbose:
11            print(exc)
12    else:
13        raise AssertionError("expected an exception")
14
15def test_stream_error(error_filename, verbose=False):
16    _run_reader(open(error_filename, 'rb'), verbose)
17    _run_reader(open(error_filename, 'rb').read(), verbose)
18    for encoding in ['utf-8', 'utf-16-le', 'utf-16-be']:
19        try:
20            data = open(error_filename, 'rb').read().decode(encoding)
21            break
22        except UnicodeDecodeError:
23            pass
24    else:
25        return
26    _run_reader(data, verbose)
27    _run_reader(open(error_filename, encoding=encoding), verbose)
28
29test_stream_error.unittest = ['.stream-error']
30
31if __name__ == '__main__':
32    import test_appliance
33    test_appliance.run(globals())
34
Note: See TracBrowser for help on using the repository browser.