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

Revision 146, 2.3 KB checked in by xi, 9 years ago (diff)

Fix !!python/name for Python 2.3. Clear the yaml module namespace.

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
[141]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))
23
24    def _testDumperErrors(self, test_name, invalid_filename):
25        code = file(invalid_filename, 'rb').read()
26        self.failUnlessRaises(YAMLError, lambda: self._dump(code))
27
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
35
36    def _emit(self, events):
37        try:
38            emit(events)
[146]39        except YAMLError, exc:
[141]40            #print '.'*70
41            #print "%s:" % exc.__class__.__name__, exc
42            raise
43
[47]44    def _load(self, filename):
[52]45        try:
[136]46            return list(load_all(file(filename, 'rb')))
[52]47        except YAMLError, exc:
48        #except ScannerError, exc:
49        #except ParserError, exc:
[53]50        #except ComposerError, exc:
[59]51        #except ConstructorError, exc:
[52]52            #print '.'*70
53            #print "%s:" % exc.__class__.__name__, exc
54            raise
[47]55
56    def _load_string(self, filename):
[52]57        try:
[136]58            return list(load_all(file(filename, 'rb').read()))
[59]59        except YAMLError, exc:
[52]60        #except ScannerError, exc:
61        #except ParserError, exc:
[53]62        #except ComposerError, exc:
[59]63        #except ConstructorError, exc:
64            #print '.'*70
65            #print "%s:" % filename
66            #print "%s:" % exc.__class__.__name__, exc
[52]67            raise
[47]68
[140]69TestErrors.add_tests('testLoaderErrors', '.loader-error')
70TestErrors.add_tests('testLoaderStringErrors', '.loader-error')
[141]71TestErrors.add_tests('testEmitterErrors', '.emitter-error')
72TestErrors.add_tests('testDumperErrors', '.dumper-error')
[47]73
Note: See TracBrowser for help on using the repository browser.