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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
import ruyaml as yaml
YAML = yaml.YAML
import warnings
# Skipped because we have no idea where the "error_filename"
# fixture is supposed to come from
import pytest
import test_emitter
import ruyaml as yaml
pytestmark = pytest.mark.skip
warnings.simplefilter('ignore', yaml.error.UnsafeLoaderWarning)
def test_loader_error(error_filename, verbose=False):
yaml = YAML(typ='safe', pure=True)
try:
with open(error_filename, 'rb') as fp0:
list(yaml.load_all(fp0))
except yaml.YAMLError as exc:
if verbose:
print('%s:' % exc.__class__.__name__, exc)
else:
raise AssertionError('expected an exception')
test_loader_error.unittest = ['.loader-error']
def test_loader_error_string(error_filename, verbose=False):
yaml = YAML(typ='safe', pure=True)
try:
with open(error_filename, 'rb') as fp0:
list(yaml.load_all(fp0.read()))
except yaml.YAMLError as exc:
if verbose:
print('%s:' % exc.__class__.__name__, exc)
else:
raise AssertionError('expected an exception')
test_loader_error_string.unittest = ['.loader-error']
def test_loader_error_single(error_filename, verbose=False):
yaml = YAML(typ='safe', pure=True)
try:
with open(error_filename, 'rb') as fp0:
yaml.load(fp0.read())
except yaml.YAMLError as exc:
if verbose:
print('%s:' % exc.__class__.__name__, exc)
else:
raise AssertionError('expected an exception')
test_loader_error_single.unittest = ['.single-loader-error']
def test_emitter_error(error_filename, verbose=False):
yaml = YAML(typ='safe', pure=True)
with open(error_filename, 'rb') as fp0:
events = list(yaml.load(fp0, Loader=test_emitter.EventsLoader))
try:
yaml.emit(events)
except yaml.YAMLError as exc:
if verbose:
print('%s:' % exc.__class__.__name__, exc)
else:
raise AssertionError('expected an exception')
test_emitter_error.unittest = ['.emitter-error']
def test_dumper_error(error_filename, verbose=False):
yaml = YAML(typ='safe', pure=True)
with open(error_filename, 'rb') as fp0:
code = fp0.read()
try:
import yaml
exec(code)
except yaml.YAMLError as exc:
if verbose:
print('%s:' % exc.__class__.__name__, exc)
else:
raise AssertionError('expected an exception')
test_dumper_error.unittest = ['.dumper-error']
if __name__ == '__main__':
import test_appliance
test_appliance.run(globals())
|