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

Revision 136, 1.3 KB checked in by xi, 9 years ago (diff)

Major refactoring.

RevLine 
[47]1
2import test_appliance
3
[58]4from yaml import *
[47]5
6class TestErrors(test_appliance.TestAppliance):
7
8    def _testErrors(self, test_name, invalid_filename):
9        #self._load(invalid_filename)
10        self.failUnlessRaises(YAMLError, lambda: self._load(invalid_filename))
11
12    def _testStringErrors(self, test_name, invalid_filename):
13        #self._load_string(invalid_filename)
14        self.failUnlessRaises(YAMLError, lambda: self._load_string(invalid_filename))
15
16    def _load(self, filename):
[52]17        try:
[136]18            return list(load_all(file(filename, 'rb')))
[52]19        except YAMLError, exc:
20        #except ScannerError, exc:
21        #except ParserError, exc:
[53]22        #except ComposerError, exc:
[59]23        #except ConstructorError, exc:
[52]24            #print '.'*70
25            #print "%s:" % exc.__class__.__name__, exc
26            raise
[47]27
28    def _load_string(self, filename):
[52]29        try:
[136]30            return list(load_all(file(filename, 'rb').read()))
[59]31        except YAMLError, exc:
[52]32        #except ScannerError, exc:
33        #except ParserError, exc:
[53]34        #except ComposerError, exc:
[59]35        #except ConstructorError, exc:
36            #print '.'*70
37            #print "%s:" % filename
38            #print "%s:" % exc.__class__.__name__, exc
[52]39            raise
[47]40
41TestErrors.add_tests('testErrors', '.error-message')
42TestErrors.add_tests('testStringErrors', '.error-message')
43
Note: See TracBrowser for help on using the repository browser.