source: pyyaml/trunk/tests/test_reader.py @ 322

Revision 322, 978 bytes checked in by xi, 6 years ago (diff)

Refactored the test suite; updated include and library paths in setup.cfg.

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