Fix invalid output of single-quoted scalars in cases when a single
[pyyaml/python3.git] / tests / test_errors.py
blob2a496603dcbd904cf0745c35bd637206ee95ab4b
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 _testEmitterErrors(self, test_name, invalid_filename):
20 events = list(load(file(invalid_filename, 'rb').read(),
21 Loader=test_emitter.EventsLoader))
22 self.failUnlessRaises(YAMLError, lambda: self._emit(events))
24 def _testDumperErrors(self, test_name, invalid_filename):
25 code = file(invalid_filename, 'rb').read()
26 self.failUnlessRaises(YAMLError, lambda: self._dump(code))
28 def _dump(self, code):
29 try:
30 exec code
31 except YAMLError, exc:
32 #print '.'*70
33 #print "%s:" % exc.__class__.__name__, exc
34 raise
36 def _emit(self, events):
37 try:
38 emit(events)
39 except YAMLError, exc:
40 #print '.'*70
41 #print "%s:" % exc.__class__.__name__, exc
42 raise
44 def _load(self, filename):
45 try:
46 return list(load_all(file(filename, 'rb')))
47 except YAMLError, exc:
48 #except ScannerError, exc:
49 #except ParserError, exc:
50 #except ComposerError, exc:
51 #except ConstructorError, exc:
52 #print '.'*70
53 #print "%s:" % exc.__class__.__name__, exc
54 raise
56 def _load_string(self, filename):
57 try:
58 return list(load_all(file(filename, 'rb').read()))
59 except YAMLError, exc:
60 #except ScannerError, exc:
61 #except ParserError, exc:
62 #except ComposerError, exc:
63 #except ConstructorError, exc:
64 #print '.'*70
65 #print "%s:" % filename
66 #print "%s:" % exc.__class__.__name__, exc
67 raise
69 TestErrors.add_tests('testLoaderErrors', '.loader-error')
70 TestErrors.add_tests('testLoaderStringErrors', '.loader-error')
71 TestErrors.add_tests('testEmitterErrors', '.emitter-error')
72 TestErrors.add_tests('testDumperErrors', '.dumper-error')