2
from __future__ import with_statement
from sikuli.Sikuli import *

import os
import unittest
import this
import xmlrpclib
import SimpleXMLRPCServer, SocketServer, threading

class SimpleThreadedXMLRPCServer(SocketServer.ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer):
    pass

class ABC(object):
    def A(self):
      ...........
    def B(self):
      ...........
    def C(self):
      ...........     


class XYZ(unittest.TestCase,ABC):
    def setUp(self):
         print "Inside setup"
         pass      
    def tearDown(self):
         print "Inside tearDown" 
         pass
    def test_1(self):
        self.A()
        self.B()
        self.C()


    def D(self):    
        print "Inside D"
        return True    


suite = unittest.TestLoader().loadTestsFromTestCase(XYZ)

class ServerThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.server = SimpleThreadedXMLRPCServer(("x.x.x.1", 8000))
        #self.server.register_instance() #How to Register an instance of XYZ here.
    def run(self):
        self.server.serve_forever()

server = ServerThread()
server.start()

所以我的问题是如何在XYZ这里注册一个实例。在上面的注释行中,以便可以从 XMLRPC 客户端调用它,例如:

client = xmlrpclib.ServerProxy("http://x.x.x.2:8000")
handraise = client.D() #Or any other possible way

我知道它可以使用,register_function(D)但我希望整个班级XYZ都可以使用register_instance().

4

1 回答 1

0

理论上这应该有效:

self.server.register_instance(XYZ())    # but it throwed some runTest Error for me

无论如何,在 register_instance 内的类名中显式地将方法名称作为 arg 传递,例如:

self.server.register_instance(XYZ("D"))

对我来说按预期工作。
从 xmlrpc 客户端,调用 D() 如下:

handraise = client.D()
于 2013-04-18T09:22:47.730 回答