def test_string_stream(self):
instance = StringStreamField().create()
with self.assertRaises(StreamNotAvailableException):
instance.write(six.u('hello'))
with self.assertRaises(StreamNotAvailableException):
instance.read()
class DummyStream(object):
def __init__(self):
self.buffer = six.u('')
def read(self, n=-1):
if n == -1:
n = len(self.buffer)
result = self.buffer[:n]
self.buffer = self.buffer[n:]
return result
def write(self, data):
self.buffer += data
instance.set_real_stream(DummyStream())
with self.assertRaises(InvalidValueException):
instance.write(six.b('hello'))
instance.write(six.u('hello'))
self.assertEqual(instance.read(), six.u('hello'))
评论列表
文章目录