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

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

Some renaming.

Line 
1
2import test_appliance
3from yaml.reader import Reader, ReaderError
4
5import codecs
6
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:
17            return
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)))
24
25    def _testReaderStringErrors(self, test_name, stream_filename):
26        data = file(stream_filename, 'rb').read()
27        #self._load(data)
28        self.failUnlessRaises(ReaderError, lambda: self._load(data))
29
30    def _testReaderFileErrors(self, test_name, stream_filename):
31        data = file(stream_filename, 'rb')
32        #self._load(data)
33        self.failUnlessRaises(ReaderError, lambda: self._load(data))
34
35    def _load(self, data):
36        stream = Reader(data)
37        while stream.peek() != u'\0':
38            stream.forward()
39
40TestReaderErrors.add_tests('testReaderUnicodeErrors', '.stream-error')
41TestReaderErrors.add_tests('testReaderStringErrors', '.stream-error')
42TestReaderErrors.add_tests('testReaderFileErrors', '.stream-error')
43
44
Note: See TracBrowser for help on using the repository browser.