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

Revision 322, 1.9 KB checked in by xi, 6 years ago (diff)

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

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:
53        import yaml, StringIO
54        exec code
55    except yaml.YAMLError, exc:
56        if verbose:
57            print "%s:" % exc.__class__.__name__, exc
58    else:
59        raise AssertionError("expected an exception")
[141]60
[322]61test_dumper_error.unittest = ['.dumper-error']
[141]62
[322]63if __name__ == '__main__':
64    import test_appliance
65    test_appliance.run(globals())
[47]66
Note: See TracBrowser for help on using the repository browser.