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

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

Share data files between Py2 and Py3 test suites.

Line 
1
2import yaml, canonical
3
4def test_canonical_scanner(canonical_filename, verbose=False):
5    data = open(canonical_filename, 'rb').read()
6    tokens = list(yaml.canonical_scan(data))
7    assert tokens, tokens
8    if verbose:
9        for token in tokens:
10            print(token)
11
12test_canonical_scanner.unittest = ['.canonical']
13
14def test_canonical_parser(canonical_filename, verbose=False):
15    data = open(canonical_filename, 'rb').read()
16    events = list(yaml.canonical_parse(data))
17    assert events, events
18    if verbose:
19        for event in events:
20            print(event)
21
22test_canonical_parser.unittest = ['.canonical']
23
24def test_canonical_error(data_filename, canonical_filename, verbose=False):
25    data = open(data_filename, 'rb').read()
26    try:
27        output = list(yaml.canonical_load_all(data))
28    except yaml.YAMLError as exc:
29        if verbose:
30            print(exc)
31    else:
32        raise AssertionError("expected an exception")
33
34test_canonical_error.unittest = ['.data', '.canonical']
35test_canonical_error.skip = ['.empty']
36
37if __name__ == '__main__':
38    import test_appliance
39    test_appliance.run(globals())
40
Note: See TracBrowser for help on using the repository browser.