source: pyyaml/trunk/tests/test_errors.py @ 260

Revision 260, 3.0 KB checked in by xi, 6 years ago (diff)

A single dot is not a float value (fixes #62).

Line 
1
2import test_appliance
3import test_emitter
4
5import StringIO
6
7from yaml import *
8
9class TestErrors(test_appliance.TestAppliance):
10
11    def _testLoaderErrors(self, test_name, invalid_filename):
12        #self._load(invalid_filename)
13        self.failUnlessRaises(YAMLError, lambda: self._load(invalid_filename))
14
15    def _testLoaderStringErrors(self, test_name, invalid_filename):
16        #self._load_string(invalid_filename)
17        self.failUnlessRaises(YAMLError, lambda: self._load_string(invalid_filename))
18
19    def _testLoaderSingleErrors(self, test_name, invalid_filename):
20        #self._load_single(invalid_filename)
21        self.failUnlessRaises(YAMLError, lambda: self._load_single(invalid_filename))
22
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))
27
28    def _testDumperErrors(self, test_name, invalid_filename):
29        code = file(invalid_filename, 'rb').read()
30        self.failUnlessRaises(YAMLError, lambda: self._dump(code))
31
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
39
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
47
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
59
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
72
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
85
86TestErrors.add_tests('testLoaderErrors', '.loader-error')
87TestErrors.add_tests('testLoaderStringErrors', '.loader-error')
88TestErrors.add_tests('testLoaderSingleErrors', '.single-loader-error')
89TestErrors.add_tests('testEmitterErrors', '.emitter-error')
90TestErrors.add_tests('testDumperErrors', '.dumper-error')
91
Note: See TracBrowser for help on using the repository browser.