source: branches/pyyaml3000/tests/test_stream.py @ 45

Revision 45, 1.1 KB checked in by xi, 9 years ago (diff)

Stream and Marker are cleaned up.

RevLine 
[45]1
2import test_appliance
3from yaml.stream import Stream, StreamError
4
5class TestStreamErrors(test_appliance.TestAppliance):
6
7    def _testStreamUnicodeErrors(self, test_name, stream_filename):
8        try:
9            data = unicode(file(stream_filename, 'rb').read(), 'utf-8')
10        except:
11            return
12        self.failUnlessRaises(StreamError, lambda: self._load(stream_filename, data))
13
14    def _testStreamStringErrors(self, test_name, stream_filename):
15        data = file(stream_filename, 'rb').read()
16        self.failUnlessRaises(StreamError, lambda: self._load(stream_filename, data))
17
18    def _testStreamFileErrors(self, test_name, stream_filename):
19        data = file(stream_filename, 'rb')
20        self.failUnlessRaises(StreamError, lambda: self._load(stream_filename, data))
21
22    def _load(self, stream_filename, data):
23        stream = Stream(stream_filename, data)
24        while stream.peek() != u'\0':
25            stream.forward()
26
27TestStreamErrors.add_tests('testStreamUnicodeErrors', '.stream-error')
28TestStreamErrors.add_tests('testStreamStringErrors', '.stream-error')
29TestStreamErrors.add_tests('testStreamFileErrors', '.stream-error')
30
31
Note: See TracBrowser for help on using the repository browser.