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

Revision 330, 2.0 KB checked in by xi, 6 years ago (diff)

Share data files between Py2 and Py3 test suites.

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