3 from yaml
.reader
import Reader
, ReaderError
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']:
12 data
= unicode(file(stream_filename
, 'rb').read(), encoding
)
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()
28 self
.failUnlessRaises(ReaderError
, lambda: self
._load
(data
))
30 def _testReaderFileErrors(self
, test_name
, stream_filename
):
31 data
= file(stream_filename
, 'rb')
33 self
.failUnlessRaises(ReaderError
, lambda: self
._load
(data
))
35 def _load(self
, data
):
37 while stream
.peek() != u
'\0':
40 TestReaderErrors
.add_tests('testReaderUnicodeErrors', '.stream-error')
41 TestReaderErrors
.add_tests('testReaderStringErrors', '.stream-error')
42 TestReaderErrors
.add_tests('testReaderFileErrors', '.stream-error')