source: pyyaml/trunk/tests/lib3/test_reader.py @ 330

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

Share data files between Py2 and Py3 test suites.

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