Beispiel #1
0
def test_help_mock_func_disp():
    # Set up mock objects
    mock_hallo = Hallo()
    mock_func_disp = FunctionDispatcher(set(), mock_hallo)
    mock_hallo.function_dispatcher = mock_func_disp
    mock_func_disp.load_function(None, FunctionMock)
    mock_func_disp.load_function(None, FunctionMockNoDoc)
    mock_func_disp.load_function(None, Help)
    mock_server = ServerMock(mock_hallo)
    mock_server.name = "test_serv1"
    mock_user = mock_server.get_user_by_address("test_user1".lower(), "test_user1")
    # Test things
    mock_func_disp.dispatch(EventMessage(mock_server, None, mock_user, "help"))
    data = mock_server.get_send_data(1, mock_user, EventMessage)
    assert "error" not in data[0].text.lower()
    assert "list of available functions:" in data[0].text.lower()
    assert "function mock" in data[0].text.lower()
    assert "function no doc" in data[0].text.lower()
def test_init():
    # Create some basic stuff
    test_modules = {"euler"}
    test_hallo = Hallo()
    # Create function dispatcher
    fd = FunctionDispatcher(test_modules, test_hallo)
    test_hallo.function_dispatcher = fd
    try:
        # Check basic class variable setting
        assert (fd.hallo == test_hallo
                ), "Hallo object was not set correctly in FunctionDispatcher."
        assert (
            fd.module_list == test_modules
        ), "Module list was not imported correctly by FunctionDispatcher."
        # Check that module reloading has done things
        assert len(fd.function_dict) == len(
            test_modules), "Modules were not loaded to function dictionary."
        assert len(fd.function_names
                   ) != 0, "Functions were not added to function_names"
    finally:
        fd.close()
        test_hallo.close()