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.
38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
7 years ago
|
|
||
6 years ago
|
import pickle
|
||
7 years ago
|
import unittest2
|
||
|
|
||
|
import mitogen.core
|
||
|
from mitogen.core import b
|
||
|
|
||
6 years ago
|
import testlib
|
||
|
|
||
7 years ago
|
|
||
6 years ago
|
class PickleTest(testlib.RouterMixin, testlib.TestCase):
|
||
6 years ago
|
klass = mitogen.core.Context
|
||
|
|
||
|
# Ensure Context can be round-tripped by regular pickle in addition to
|
||
|
# Mitogen's hacked pickle. Users may try to call pickle on a Context in
|
||
|
# strange circumstances, and it's often used to glue pieces of an app
|
||
|
# together (e.g. Ansible).
|
||
|
|
||
|
def test_mitogen_roundtrip(self):
|
||
6 years ago
|
c = self.router.local()
|
||
6 years ago
|
r = mitogen.core.Receiver(self.router)
|
||
|
r.to_sender().send(c)
|
||
|
c2 = r.get().unpickle()
|
||
|
self.assertEquals(None, c2.router)
|
||
|
self.assertEquals(c.context_id, c2.context_id)
|
||
|
self.assertEquals(c.name, c2.name)
|
||
|
|
||
|
def test_vanilla_roundtrip(self):
|
||
6 years ago
|
c = self.router.local()
|
||
6 years ago
|
c2 = pickle.loads(pickle.dumps(c))
|
||
|
self.assertEquals(None, c2.router)
|
||
|
self.assertEquals(c.context_id, c2.context_id)
|
||
|
self.assertEquals(c.name, c2.name)
|
||
|
|
||
|
|
||
7 years ago
|
if __name__ == '__main__':
|
||
|
unittest2.main()
|