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

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

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

RevLine 
[47]1
2import test_appliance
[141]3import test_emitter
[47]4
[141]5import StringIO
6
[58]7from yaml import *
[47]8
9class TestErrors(test_appliance.TestAppliance):
10
[140]11    def _testLoaderErrors(self, test_name, invalid_filename):
[47]12        #self._load(invalid_filename)
13        self.failUnlessRaises(YAMLError, lambda: self._load(invalid_filename))
14
[140]15    def _testLoaderStringErrors(self, test_name, invalid_filename):
[47]16        #self._load_string(invalid_filename)
17        self.failUnlessRaises(YAMLError, lambda: self._load_string(invalid_filename))
18
[258]19    def _testLoaderSingleErrors(self, test_name, invalid_filename):
[260]20        #self._load_single(invalid_filename)
[258]21        self.failUnlessRaises(YAMLError, lambda: self._load_single(invalid_filename))
22
[141]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)
[146]43        except YAMLError, exc:
[141]44            #print '.'*70
45            #print "%s:" % exc.__class__.__name__, exc
46            raise
47
[47]48    def _load(self, filename):
[52]49        try:
[136]50            return list(load_all(file(filename, 'rb')))
[52]51        except YAMLError, exc:
52        #except ScannerError, exc:
53        #except ParserError, exc:
[53]54        #except ComposerError, exc:
[59]55        #except ConstructorError, exc:
[52]56            #print '.'*70
57            #print "%s:" % exc.__class__.__name__, exc
58            raise
[47]59
60    def _load_string(self, filename):
[52]61        try:
[136]62            return list(load_all(file(filename, 'rb').read()))
[59]63        except YAMLError, exc:
[52]64        #except ScannerError, exc:
65        #except ParserError, exc:
[53]66        #except ComposerError, exc:
[59]67        #except ConstructorError, exc:
68            #print '.'*70
69            #print "%s:" % filename
70            #print "%s:" % exc.__class__.__name__, exc
[52]71            raise
[47]72
[258]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
[140]86TestErrors.add_tests('testLoaderErrors', '.loader-error')
87TestErrors.add_tests('testLoaderStringErrors', '.loader-error')
[258]88TestErrors.add_tests('testLoaderSingleErrors', '.single-loader-error')
[141]89TestErrors.add_tests('testEmitterErrors', '.emitter-error')
90TestErrors.add_tests('testDumperErrors', '.dumper-error')
[47]91
Note: See TracBrowser for help on using the repository browser.