source: pyyaml/trunk/tests/lib/test_errors.py @ 330

Revision 330, 1.9 KB checked in by xi, 5 years ago (diff)

Share data files between Py2 and Py3 test suites.

RevLine 
[47]1
[322]2import yaml, test_emitter
[47]3
[322]4def test_loader_error(error_filename, verbose=False):
5    try:
6        list(yaml.load_all(open(error_filename, 'rb')))
7    except yaml.YAMLError, exc:
8        if verbose:
9            print "%s:" % exc.__class__.__name__, exc
10    else:
11        raise AssertionError("expected an exception")
[141]12
[322]13test_loader_error.unittest = ['.loader-error']
[47]14
[322]15def test_loader_error_string(error_filename, verbose=False):
16    try:
17        list(yaml.load_all(open(error_filename, 'rb').read()))
18    except yaml.YAMLError, exc:
19        if verbose:
20            print "%s:" % exc.__class__.__name__, exc
21    else:
22        raise AssertionError("expected an exception")
[47]23
[322]24test_loader_error_string.unittest = ['.loader-error']
[47]25
[322]26def test_loader_error_single(error_filename, verbose=False):
27    try:
28        yaml.load(open(error_filename, 'rb').read())
29    except yaml.YAMLError, exc:
30        if verbose:
31            print "%s:" % exc.__class__.__name__, exc
32    else:
33        raise AssertionError("expected an exception")
[47]34
[322]35test_loader_error_single.unittest = ['.single-loader-error']
[258]36
[322]37def test_emitter_error(error_filename, verbose=False):
38    events = list(yaml.load(open(error_filename, 'rb'),
39                    Loader=test_emitter.EventsLoader))
40    try:
41        yaml.emit(events)
42    except yaml.YAMLError, exc:
43        if verbose:
44            print "%s:" % exc.__class__.__name__, exc
45    else:
46        raise AssertionError("expected an exception")
[141]47
[322]48test_emitter_error.unittest = ['.emitter-error']
[141]49
[322]50def test_dumper_error(error_filename, verbose=False):
51    code = open(error_filename, 'rb').read()
52    try:
[330]53        import yaml
54        from StringIO import StringIO
[322]55        exec code
56    except yaml.YAMLError, exc:
57        if verbose:
58            print "%s:" % exc.__class__.__name__, exc
59    else:
60        raise AssertionError("expected an exception")
[141]61
[322]62test_dumper_error.unittest = ['.dumper-error']
[141]63
[322]64if __name__ == '__main__':
65    import test_appliance
66    test_appliance.run(globals())
[47]67
Note: See TracBrowser for help on using the repository browser.