source: branches/pyyaml3000/tests/test_errors.py @ 52

Revision 52, 1.5 KB checked in by xi, 8 years ago (diff)

Cleanup error messages.

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