def setUp(self): print() print("=== setup ===") import tempfile print("WrappedClass publishers:", WrappedClass.publishers) self.sockname = tempfile.mktemp() self.server = RPCHost() self.server.start() self.listener = RPCListener(self.sockname, "RPCTests", self.server) self.listener.start() self.remote = start_helper(self.sockname) self.remote.start() self.server.publish(WrappedLocalClass) self.server.subscribe(WrappedClass) print("=== setup done ===")
class RPCTests(TestCase): def setUp(self): print print "=== setup ===" import tempfile print "WrappedClass publishers:", WrappedClass.publishers self.sockname = tempfile.mktemp() self.server = RPCHost() self.server.start() self.listener = RPCListener(self.sockname, "RPCTests", self.server) self.listener.start() self.remote = start_helper(self.sockname) self.remote.start() self.server.publish(WrappedLocalClass) self.server.subscribe(WrappedClass) print "=== setup done ===" def tearDown(self): from datetime import datetime print print "=== teardown ===" print " teardown 1 %s" % datetime.now() self.server.finish() print " teardown 2 %s" % datetime.now() self.listener.finish() print " teardown 3 %s" % datetime.now() self.remote.finish() print "=== teardown done ===" def test_local(self): '''test_local: local calls on a RPCWrapper subclass work''' o = WrappedLocalClass("hello") print "test_local: WrappedLocal ctor returned" self.assertEqual(o.local, True) self.assertEqual(o.retarg(), "hello") o.setarg("goodbye") self.assertEqual(o.retarg(), "goodbye") print "test_local: ok" def test_remote(self): '''test_remote: calls on remote objects work''' print "About to create WrappedClass" o = WrappedClass(123.45) self.assertNotEqual(o.rpcid, None) try: self.assertEqual(o.retarg(), 123.45) o.setarg(dict(x=1, y=2)) self.assertEqual(o.retarg(), dict(x=1, y=2)) except RPCWrapper.MethodFailed, e: print '-------------------------' print e.traceback print '-------------------------' assert 0
def main(): socketpath = sys.argv[1] remote_host = RPCHost() remote_host.publish(WrappedClass) remote_host.publish(ReverseClass) remote_host.start() remote_conn = RPCRemote(socketpath, "RPCTests_remote", remote_host) remote_conn.connect() try: QuittableThread.wait_for_all() except Exception, e: print "wait_for_all caught error"
class RPCTests(TestCase): def setUp(self): print() print("=== setup ===") import tempfile print("WrappedClass publishers:", WrappedClass.publishers) self.sockname = tempfile.mktemp() self.server = RPCHost() self.server.start() self.listener = RPCListener(self.sockname, "RPCTests", self.server) self.listener.start() self.remote = start_helper(self.sockname) self.remote.start() self.server.publish(WrappedLocalClass) self.server.subscribe(WrappedClass) print("=== setup done ===") def tearDown(self): from datetime import datetime print() print("=== teardown ===") print(" teardown 1 %s" % datetime.now()) self.server.finish() print(" teardown 2 %s" % datetime.now()) self.listener.finish() print(" teardown 3 %s" % datetime.now()) self.remote.finish() print("=== teardown done ===") def test_local(self): '''test_local: local calls on a RPCWrapper subclass work''' o = WrappedLocalClass("hello") print("test_local: WrappedLocal ctor returned") self.assertEqual(o.local, True) self.assertEqual(o.retarg(), "hello") o.setarg("goodbye") self.assertEqual(o.retarg(), "goodbye") print("test_local: ok") def test_remote(self): '''test_remote: calls on remote objects work''' print("About to create WrappedClass") o = WrappedClass(123.45) self.assertNotEqual(o.rpcid, None) try: self.assertEqual(o.retarg(), 123.45) o.setarg(dict(x=1, y=2)) self.assertEqual(o.retarg(), dict(x=1, y=2)) except RPCWrapper.MethodFailed as e: print('-------------------------') print(e.traceback) print('-------------------------') assert 0 def test_badmethod(self): '''test_badmethod: failed method should raise MethodFailed''' failed = 0 try: o = WrappedClass('foo') o.error_method() except RPCWrapper.MethodFailed as e: failed = 1 print(e.traceback) self.assertEqual(failed, 1) print("test_badmethod: ok")