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