1 2import yaml, test_emitter 3 4def test_loader_error(error_filename, verbose=False): 5 try: 6 with open(error_filename, 'rb') as file: 7 list(yaml.load_all(file, yaml.FullLoader)) 8 except yaml.YAMLError as exc: 9 if verbose: 10 print("%s:" % exc.__class__.__name__, exc) 11 else: 12 raise AssertionError("expected an exception") 13 14test_loader_error.unittest = ['.loader-error'] 15 16def test_loader_error_string(error_filename, verbose=False): 17 try: 18 with open(error_filename, 'rb') as file: 19 list(yaml.load_all(file.read(), yaml.FullLoader)) 20 except yaml.YAMLError as exc: 21 if verbose: 22 print("%s:" % exc.__class__.__name__, exc) 23 else: 24 raise AssertionError("expected an exception") 25 26test_loader_error_string.unittest = ['.loader-error'] 27 28def test_loader_error_single(error_filename, verbose=False): 29 try: 30 with open(error_filename, 'rb') as file: 31 yaml.load(file.read(), yaml.FullLoader) 32 except yaml.YAMLError as exc: 33 if verbose: 34 print("%s:" % exc.__class__.__name__, exc) 35 else: 36 raise AssertionError("expected an exception") 37 38test_loader_error_single.unittest = ['.single-loader-error'] 39 40def test_emitter_error(error_filename, verbose=False): 41 with open(error_filename, 'rb') as file: 42 events = list(yaml.load(file, Loader=test_emitter.EventsLoader)) 43 try: 44 yaml.emit(events) 45 except yaml.YAMLError as exc: 46 if verbose: 47 print("%s:" % exc.__class__.__name__, exc) 48 else: 49 raise AssertionError("expected an exception") 50 51test_emitter_error.unittest = ['.emitter-error'] 52 53def test_dumper_error(error_filename, verbose=False): 54 with open(error_filename, 'rb') as file: 55 code = file.read() 56 try: 57 import yaml 58 from io import StringIO 59 exec(code) 60 except yaml.YAMLError as exc: 61 if verbose: 62 print("%s:" % exc.__class__.__name__, exc) 63 else: 64 raise AssertionError("expected an exception") 65 66test_dumper_error.unittest = ['.dumper-error'] 67 68if __name__ == '__main__': 69 import test_appliance 70 test_appliance.run(globals()) 71 72