Working on the scanner.
[pyyaml/python3.git] / tests / test_reader.py
blob1bfae1a24e92cdc0a270f1fe1d23fa6343e16cd6
2 import test_appliance
3 from yaml.reader import Reader, ReaderError
5 import codecs
7 class TestReaderErrors(test_appliance.TestAppliance):
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)))
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))
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))
35 def _load(self, data):
36 stream = Reader(data)
37 while stream.peek() != u'\0':
38 stream.forward()
40 TestReaderErrors.add_tests('testReaderUnicodeErrors', '.stream-error')
41 TestReaderErrors.add_tests('testReaderStringErrors', '.stream-error')
42 TestReaderErrors.add_tests('testReaderFileErrors', '.stream-error')