You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.0 KiB
Python
73 lines
2.0 KiB
Python
7 years ago
|
|
||
|
import cStringIO
|
||
|
|
||
|
import unittest2
|
||
|
|
||
|
import mitogen.core
|
||
|
|
||
|
|
||
|
class BlobTest(unittest2.TestCase):
|
||
|
klass = mitogen.core.Blob
|
||
|
|
||
|
def make(self):
|
||
|
return self.klass('x' * 128)
|
||
|
|
||
|
def test_repr(self):
|
||
|
blob = self.make()
|
||
|
self.assertEquals('[blob: 128 bytes]', repr(blob))
|
||
|
|
||
|
def test_decays_on_constructor(self):
|
||
|
blob = self.make()
|
||
|
self.assertEquals('x'*128, mitogen.core.BytesType(blob))
|
||
|
|
||
|
def test_decays_on_write(self):
|
||
|
blob = self.make()
|
||
|
io = cStringIO.StringIO()
|
||
|
io.write(blob)
|
||
|
self.assertEquals(128, io.tell())
|
||
|
self.assertEquals('x'*128, io.getvalue())
|
||
|
|
||
|
def test_message_roundtrip(self):
|
||
|
blob = self.make()
|
||
|
msg = mitogen.core.Message.pickled(blob)
|
||
|
blob2 = msg.unpickle()
|
||
|
self.assertEquals(type(blob), type(blob2))
|
||
|
self.assertEquals(repr(blob), repr(blob2))
|
||
|
self.assertEquals(mitogen.core.BytesType(blob),
|
||
|
mitogen.core.BytesType(blob2))
|
||
|
|
||
|
|
||
|
class SecretTest(unittest2.TestCase):
|
||
|
klass = mitogen.core.Secret
|
||
|
|
||
|
def make(self):
|
||
|
return self.klass('password')
|
||
|
|
||
|
def test_repr(self):
|
||
|
secret = self.make()
|
||
|
self.assertEquals('[secret]', repr(secret))
|
||
|
|
||
|
def test_decays_on_constructor(self):
|
||
|
secret = self.make()
|
||
|
self.assertEquals('password', mitogen.core.UnicodeType(secret))
|
||
|
|
||
|
def test_decays_on_write(self):
|
||
|
secret = self.make()
|
||
|
io = cStringIO.StringIO()
|
||
|
io.write(secret)
|
||
|
self.assertEquals(8, io.tell())
|
||
|
self.assertEquals('password', io.getvalue())
|
||
|
|
||
|
def test_message_roundtrip(self):
|
||
|
secret = self.make()
|
||
|
msg = mitogen.core.Message.pickled(secret)
|
||
|
secret2 = msg.unpickle()
|
||
|
self.assertEquals(type(secret), type(secret2))
|
||
|
self.assertEquals(repr(secret), repr(secret2))
|
||
|
self.assertEquals(mitogen.core.BytesType(secret),
|
||
|
mitogen.core.BytesType(secret2))
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
unittest2.main()
|