Beispiel #1
0
    def testSingleIntegerArg(self):
        rpcserver = rpc.rpcserver(0)
        rpcserver.add_handler("echo", lambda o: o)

        _start_new_thread(rpcserver.serve_forever)
        try:
            rpcclient = rpc.rpcclient(rpcserver.port)
            self.assertRaises(Exception, rpcclient.flaterror, (18,))
        finally:
            rpcserver.shutdown()
            rpcserver.close()
Beispiel #2
0
    def testExceptionOnHandlerFlattening(self):
        rpcserver = rpc.rpcserver(0)
        rpcserver.add_handler("flaterror", lambda o: object())

        _start_new_thread(rpcserver.serve_forever)
        try:
            rpcclient = rpc.rpcclient(rpcserver.port)
            self.assertRaises(Exception, rpcclient.flaterror, ("Hello",))
        finally:
            rpcserver.shutdown()
            rpcserver.close()
Beispiel #3
0
    def testBasic(self):
        rpcserver = rpc.rpcserver(0)
        rpcserver.add_handler("cat", catTwoStrings)

        _start_new_thread(rpcserver.serve_forever)
        try:
            rpcclient = rpc.rpcclient(rpcserver.port)
            result = rpcclient.cat("Hello, ", "World!")
            self.assertEqual("Hello, World!", result)
        finally:
            rpcserver.shutdown()
            rpcserver.close()
Beispiel #4
0
    def testMultipleHandlers(self):
        rpcserver = rpc.rpcserver(0)
        rpcserver.add_handler("cat", lambda s1, s2: s1 + s2)
        rpcserver.add_handler("len", lambda s1, s2: len(s1 + s2))

        _start_new_thread(rpcserver.serve_forever)
        try:
            rpcclient = rpc.rpcclient(rpcserver.port)
            result = rpcclient.cat("Hello, ", "World!")
            self.assertEqual("Hello, World!", result)
            result = rpcclient.len("Hello, ", "World!")
            self.assertEqual(len("Hello, World!"), result)
        finally:
            rpcserver.shutdown()
            rpcserver.close()
 def setUp(self):
     self.rpcserver = rpc.rpcserver(0)
     self.rpcserver.add_handler("cat", lambda s1, s2: s1 + s2)
     _start_new_thread(self.rpcserver.serve_forever)
     self.rpcclient = rpc.rpcclient(self.rpcserver.port)
Beispiel #6
0
 def testConnectionTimesOutQuicklyEnough(self):
     rpcclient = rpc.rpcclient(PORT)
     t = threading.Thread(target=self.assertRaises, args=(Exception, rpcclient.doesnotexist, ("Hello",)))
     t.start()
     t.join(2.0)
     self.assertFalse(t.isAlive())