A single dot is not a float value (fixes #62).
[pyyaml/python3.git] / tests / test_errors.py
blob7d6e0d269847fd4bd0c3a98f0536cb5bed570245
2 import test_appliance
3 import test_emitter
5 import StringIO
7 from yaml import *
9 class TestErrors(test_appliance.TestAppliance):
11 def _testLoaderErrors(self, test_name, invalid_filename):
12 #self._load(invalid_filename)
13 self.failUnlessRaises(YAMLError, lambda: self._load(invalid_filename))
15 def _testLoaderStringErrors(self, test_name, invalid_filename):
16 #self._load_string(invalid_filename)
17 self.failUnlessRaises(YAMLError, lambda: self._load_string(invalid_filename))
19 def _testLoaderSingleErrors(self, test_name, invalid_filename):
20 #self._load_single(invalid_filename)
21 self.failUnlessRaises(YAMLError, lambda: self._load_single(invalid_filename))
23 def _testEmitterErrors(self, test_name, invalid_filename):
24 events = list(load(file(invalid_filename, 'rb').read(),
25 Loader=test_emitter.EventsLoader))
26 self.failUnlessRaises(YAMLError, lambda: self._emit(events))
28 def _testDumperErrors(self, test_name, invalid_filename):
29 code = file(invalid_filename, 'rb').read()
30 self.failUnlessRaises(YAMLError, lambda: self._dump(code))
32 def _dump(self, code):
33 try:
34 exec code
35 except YAMLError, exc:
36 #print '.'*70
37 #print "%s:" % exc.__class__.__name__, exc
38 raise
40 def _emit(self, events):
41 try:
42 emit(events)
43 except YAMLError, exc:
44 #print '.'*70
45 #print "%s:" % exc.__class__.__name__, exc
46 raise
48 def _load(self, filename):
49 try:
50 return list(load_all(file(filename, 'rb')))
51 except YAMLError, exc:
52 #except ScannerError, exc:
53 #except ParserError, exc:
54 #except ComposerError, exc:
55 #except ConstructorError, exc:
56 #print '.'*70
57 #print "%s:" % exc.__class__.__name__, exc
58 raise
60 def _load_string(self, filename):
61 try:
62 return list(load_all(file(filename, 'rb').read()))
63 except YAMLError, exc:
64 #except ScannerError, exc:
65 #except ParserError, exc:
66 #except ComposerError, exc:
67 #except ConstructorError, exc:
68 #print '.'*70
69 #print "%s:" % filename
70 #print "%s:" % exc.__class__.__name__, exc
71 raise
73 def _load_single(self, filename):
74 try:
75 return load(file(filename, 'rb').read())
76 except YAMLError, exc:
77 #except ScannerError, exc:
78 #except ParserError, exc:
79 #except ComposerError, exc:
80 #except ConstructorError, exc:
81 #print '.'*70
82 #print "%s:" % filename
83 #print "%s:" % exc.__class__.__name__, exc
84 raise
86 TestErrors.add_tests('testLoaderErrors', '.loader-error')
87 TestErrors.add_tests('testLoaderStringErrors', '.loader-error')
88 TestErrors.add_tests('testLoaderSingleErrors', '.single-loader-error')
89 TestErrors.add_tests('testEmitterErrors', '.emitter-error')
90 TestErrors.add_tests('testDumperErrors', '.dumper-error')