def test_unpack_and_execute(): cmd = CmdHello("world") data = pickle.dumps(cmd) server = BaseServer(HOST, PORT) server.register_handle_function("CmdHello", hello) message_name, ret = server.unpack_and_execute(data) assert message_name == "CmdHello" assert ret == "hello world"
def test_base_server(): # server server = BaseServer(HOST, PORT) server.register_handle_function("CmdHello", hello) holder = {'hello': ""} def sayHello(): holder['hello'] = "world" server.register_start_function(sayHello) def server_thread(): server.run() t = threading.Thread(target=server_thread) t.start() sleep(4) # client try: ret = client.send_message((HOST, PORT), CmdHello("world")) assert ret == "hello world" client.sendonly_message((HOST, PORT), CmdHello("world")) finally: server.shutdown() assert holder["hello"] == "world"
def test_unregister_handle_function(): server = BaseServer(HOST, PORT) server.register_handle_function("helloworld", helloworld) assert server.handle_functions["helloworld"]() == "hello" server.unregister_handle_function("helloworld") assert server.handle_functions.has_key("helloworld") == False server.unregister_handle_function( "helloworld") # this should not raise exception
def test_base_server(): # server server = BaseServer(HOST, PORT) server.register_handle_function("CmdHello", hello) holder = {'hello': ""} def sayHello(): holder['hello'] = "world" server.register_start_function(sayHello) def server_thread(): server.run() t = threading.Thread(target = server_thread) t.start() sleep(4) # client try: ret = client.send_message((HOST, PORT), CmdHello("world")) assert ret == "hello world" client.sendonly_message((HOST, PORT), CmdHello("world")) finally: server.shutdown() assert holder["hello"] == "world"
def test_unregister_handle_function(): server = BaseServer(HOST, PORT) server.register_handle_function("helloworld", helloworld) assert server.handle_functions["helloworld"]() == "hello" server.unregister_handle_function("helloworld") assert server.handle_functions.has_key("helloworld") == False server.unregister_handle_function("helloworld") # this should not raise exception
def test_register_handle_funtion(): server = BaseServer(HOST, PORT) server.register_handle_function("helloworld", helloworld) assert server.handle_functions["helloworld"]() == "hello"