2018-07-04 19:55:14 +00:00
|
|
|
|
2018-11-01 20:15:16 +00:00
|
|
|
import pickle
|
2018-07-04 19:55:14 +00:00
|
|
|
import unittest2
|
|
|
|
|
|
|
|
import mitogen.core
|
|
|
|
from mitogen.core import b
|
|
|
|
|
2018-11-01 20:15:16 +00:00
|
|
|
import testlib
|
|
|
|
|
2018-07-04 19:55:14 +00:00
|
|
|
|
2019-03-10 20:00:50 +00:00
|
|
|
class PickleTest(testlib.RouterMixin, testlib.TestCase):
|
2018-11-01 20:15:16 +00:00
|
|
|
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):
|
2019-01-23 12:44:08 +00:00
|
|
|
c = self.router.local()
|
2018-11-01 20:15:16 +00:00
|
|
|
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):
|
2019-01-23 12:44:08 +00:00
|
|
|
c = self.router.local()
|
2018-11-01 20:15:16 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2018-07-04 19:55:14 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest2.main()
|