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

Revision 140, 1.4 KB checked in by xi, 9 years ago (diff)

Rename error-message to loader-error and add new examples.

Line 
1
2import test_appliance
3
4from yaml import *
5
6class TestErrors(test_appliance.TestAppliance):
7
8    def _testLoaderErrors(self, test_name, invalid_filename):
9        #self._load(invalid_filename)
10        self.failUnlessRaises(YAMLError, lambda: self._load(invalid_filename))
11
12    def _testLoaderStringErrors(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):
17        try:
18            return list(load_all(file(filename, 'rb')))
19        except YAMLError, exc:
20        #except ScannerError, exc:
21        #except ParserError, exc:
22        #except ComposerError, exc:
23        #except ConstructorError, exc:
24            #print '.'*70
25            #print "%s:" % exc.__class__.__name__, exc
26            raise
27
28    def _load_string(self, filename):
29        try:
30            return list(load_all(file(filename, 'rb').read()))
31        except YAMLError, exc:
32        #except ScannerError, exc:
33        #except ParserError, exc:
34        #except ComposerError, exc:
35        #except ConstructorError, exc:
36            #print '.'*70
37            #print "%s:" % filename
38            #print "%s:" % exc.__class__.__name__, exc
39            raise
40
41TestErrors.add_tests('testLoaderErrors', '.loader-error')
42TestErrors.add_tests('testLoaderStringErrors', '.loader-error')
43
Note: See TracBrowser for help on using the repository browser.