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

Revision 53, 1.8 KB checked in by xi, 8 years ago (diff)

Implement Composer and BaseResolver?.

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