source: branches/pyyaml3000/tests/test_reader.py @ 46

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

Some renaming.

RevLine 
[45]1
2import test_appliance
[46]3from yaml.reader import Reader, ReaderError
[45]4
[46]5import codecs
[45]6
[46]7class TestReaderErrors(test_appliance.TestAppliance):
8
9    def _testReaderUnicodeErrors(self, test_name, stream_filename):
10        for encoding in ['utf-8', 'utf-16-le', 'utf-16-be']:
11            try:
12                data = unicode(file(stream_filename, 'rb').read(), encoding)
13                break
14            except:
15                pass
16        else:
[45]17            return
[46]18        #self._load(data)
19        self.failUnlessRaises(ReaderError,
20                lambda: self._load(data))
21        #self._load(codecs.open(stream_filename, encoding=encoding))
22        self.failUnlessRaises(ReaderError,
23                lambda: self._load(codecs.open(stream_filename, encoding=encoding)))
[45]24
[46]25    def _testReaderStringErrors(self, test_name, stream_filename):
[45]26        data = file(stream_filename, 'rb').read()
[46]27        #self._load(data)
28        self.failUnlessRaises(ReaderError, lambda: self._load(data))
[45]29
[46]30    def _testReaderFileErrors(self, test_name, stream_filename):
[45]31        data = file(stream_filename, 'rb')
[46]32        #self._load(data)
33        self.failUnlessRaises(ReaderError, lambda: self._load(data))
[45]34
[46]35    def _load(self, data):
36        stream = Reader(data)
[45]37        while stream.peek() != u'\0':
38            stream.forward()
39
[46]40TestReaderErrors.add_tests('testReaderUnicodeErrors', '.stream-error')
41TestReaderErrors.add_tests('testReaderStringErrors', '.stream-error')
42TestReaderErrors.add_tests('testReaderFileErrors', '.stream-error')
[45]43
44
Note: See TracBrowser for help on using the repository browser.