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

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

Ready for the initial release.

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:
18            reader = Reader(file(filename, 'rb'))
19            scanner = Scanner(reader)
20            parser = Parser(scanner)
[53]21            composer = Composer(parser)
22            resolver = Resolver(composer)
[58]23            constructor = Constructor(resolver)
24            return list(constructor)
[52]25        except YAMLError, exc:
26        #except ScannerError, exc:
27        #except ParserError, exc:
[53]28        #except ComposerError, exc:
[52]29            #print '.'*70
30            #print "%s:" % exc.__class__.__name__, exc
31            raise
[47]32
33    def _load_string(self, filename):
[52]34        try:
35            reader = Reader(file(filename, 'rb').read())
36            scanner = Scanner(reader)
37            parser = Parser(scanner)
[53]38            composer = Composer(parser)
39            resolver = Resolver(composer)
[58]40            constructor = Constructor(resolver)
41            return list(constructor)
42        #except YAMLError, exc:
[52]43        #except ScannerError, exc:
44        #except ParserError, exc:
[53]45        #except ComposerError, exc:
[58]46        except ConstructorError, exc:
47            print '.'*70
48            print "%s:" % filename
49            print "%s:" % exc.__class__.__name__, exc
[52]50            raise
[47]51
52TestErrors.add_tests('testErrors', '.error-message')
53TestErrors.add_tests('testStringErrors', '.error-message')
54
Note: See TracBrowser for help on using the repository browser.