Exemplo n.º 1
0
def run_core_test(args: argparse.Namespace) -> None:
    """Run core tests."""
    from rasa.model_testing import (
        test_core_models_in_directory,
        test_core,
        test_core_models,
    )
    from rasa.core.test import FAILED_STORIES_FILE

    stories = rasa.cli.utils.get_validated_path(args.stories, "stories",
                                                DEFAULT_DATA_PATH)

    output = args.out or DEFAULT_RESULTS_PATH
    args.errors = not args.no_errors

    rasa.shared.utils.io.create_directory(output)

    if isinstance(args.model, list) and len(args.model) == 1:
        args.model = args.model[0]

    if args.model is None:
        rasa.shared.utils.cli.print_error(
            "No model provided. Please make sure to specify the model to test with '--model'."
        )
        return

    if isinstance(args.model, str):
        model_path = rasa.cli.utils.get_validated_path(args.model, "model",
                                                       DEFAULT_MODELS_PATH)

        if args.evaluate_model_directory:
            test_core_models_in_directory(args.model,
                                          stories,
                                          output,
                                          use_conversation_test_files=args.e2e)
        else:
            test_core(
                model=model_path,
                stories=stories,
                output=output,
                additional_arguments=vars(args),
                use_conversation_test_files=args.e2e,
            )

    else:
        test_core_models(args.model,
                         stories,
                         output,
                         use_conversation_test_files=args.e2e)

    rasa.shared.utils.cli.print_info(
        f"Failed stories written to '{os.path.join(output, FAILED_STORIES_FILE)}'"
    )
Exemplo n.º 2
0
def test_e2e_warning_if_no_nlu_model(monkeypatch: MonkeyPatch,
                                     trained_core_model: Text,
                                     capsys: CaptureFixture):
    from rasa.model_testing import test_core

    # Patching is bit more complicated as we have a module `train` and function
    # with the same name 😬
    monkeypatch.setattr(sys.modules["rasa.core.test"], "test",
                        asyncio.coroutine(lambda *_, **__: True))

    test_core(trained_core_model, additional_arguments={"e2e": True})

    assert "No NLU model found. Using default" in capsys.readouterr().out
Exemplo n.º 3
0
def test(
    model: "Text",
    stories: "Text",
    nlu_data: "Text",
    output: "Text" = rasa.shared.constants.DEFAULT_RESULTS_PATH,
    additional_arguments: "Optional[Dict]" = None,
) -> None:
    """Test a Rasa model against a set of test data.

    Args:
        model: model to test
        stories: path to the dialogue test data
        nlu_data: path to the NLU test data
        output: path to folder where all output will be stored
        additional_arguments: additional arguments for the test call
    """
    from rasa.model_testing import test_core
    from rasa.model_testing import test_nlu

    if additional_arguments is None:
        additional_arguments = {}

    test_core(model, stories, output, additional_arguments)
    test_nlu(model, nlu_data, output, additional_arguments)