summaryrefslogtreecommitdiff
path: root/tests3/test_canonical.py
blob: a3b1153445381ef4b7951e894d59f3f9d86b0e14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

import yaml, canonical

def test_canonical_scanner(canonical_filename, verbose=False):
    data = open(canonical_filename, 'rb').read()
    tokens = list(yaml.canonical_scan(data))
    assert tokens, tokens
    if verbose:
        for token in tokens:
            print(token)

test_canonical_scanner.unittest = ['.canonical']

def test_canonical_parser(canonical_filename, verbose=False):
    data = open(canonical_filename, 'rb').read()
    events = list(yaml.canonical_parse(data))
    assert events, events
    if verbose:
        for event in events:
            print(event)

test_canonical_parser.unittest = ['.canonical']

def test_canonical_error(data_filename, canonical_filename, verbose=False):
    data = open(data_filename, 'rb').read()
    try:
        output = list(yaml.canonical_load_all(data))
    except yaml.YAMLError as exc:
        if verbose:
            print(exc)
    else:
        raise AssertionError("expected an exception")

test_canonical_error.unittest = ['.data', '.canonical']
test_canonical_error.skip = ['.empty']

if __name__ == '__main__':
    import test_appliance
    test_appliance.run(globals())