Esempio n. 1
0
def test_dump_config(
    tmp_path: Path,
    input_file: Text,
    expected_file: Text,
    capsys: CaptureFixture,
    autoconfig_keys: Set[Text],
):
    config_file = str(tmp_path / "config.yml")
    shutil.copyfile(str(CONFIG_FOLDER / input_file), config_file)
    old_config = rasa.shared.utils.io.read_model_configuration(config_file)
    DefaultV1Recipe.auto_configure(config_file, old_config)
    new_config = rasa.shared.utils.io.read_model_configuration(config_file)

    expected = rasa.shared.utils.io.read_model_configuration(CONFIG_FOLDER /
                                                             expected_file)

    assert new_config == expected

    captured = capsys.readouterr()
    assert "does not exist or is empty" not in captured.out

    for k in CONFIG_AUTOCONFIGURABLE_KEYS:
        if k in autoconfig_keys:
            assert k in captured.out
        else:
            assert k not in captured.out
Esempio n. 2
0
def test_importer_with_invalid_model_config(tmp_path: Path):
    invalid = {"version": "2.0", "policies": ["name"]}
    config_file = tmp_path / "config.yml"
    rasa.shared.utils.io.write_yaml(invalid, config_file)

    with pytest.raises(YamlValidationException):
        importer = TrainingDataImporter.load_from_config(str(config_file))
        DefaultV1Recipe.auto_configure(
            importer.get_config_file_for_auto_config(),
            importer.get_config(),
            TrainingType.END_TO_END,
        )
def test_no_warnings_with_default_project(tmp_path: Path):
    rasa.utils.common.copy_directory(Path("rasa/cli/initial_project"),
                                     tmp_path)

    importer = TrainingDataImporter.load_from_config(
        config_path=str(tmp_path / "config.yml"),
        domain_path=str(tmp_path / "domain.yml"),
        training_data_paths=[str(tmp_path / "data")],
    )

    config, _missing_keys, _configured_keys = DefaultV1Recipe.auto_configure(
        importer.get_config_file_for_auto_config(),
        importer.get_config(),
        TrainingType.END_TO_END,
    )
    graph_config = DefaultV1Recipe().graph_config_for_recipe(
        config, cli_parameters={}, training_type=TrainingType.END_TO_END)
    validator = DefaultV1RecipeValidator(graph_config.train_schema)

    with pytest.warns(
            UserWarning,
            match="Slot auto-fill has been removed in 3.0") as records:
        validator.validate(importer)
    assert all([
        warn.message.args[0].startswith("Slot auto-fill has been removed")
        for warn in records.list
    ])
Esempio n. 4
0
def test_get_configuration_for_different_training_types(
    tmp_path: Path,
    input_file: Text,
    expected_file: Text,
    training_type: TrainingType,
):
    config_file = str(tmp_path / "config.yml")
    shutil.copyfile(str(CONFIG_FOLDER / input_file), config_file)
    config = rasa.shared.utils.io.read_model_configuration(config_file)

    DefaultV1Recipe.auto_configure(config_file, config, training_type)

    actual = rasa.shared.utils.io.read_file(config_file)

    expected = rasa.shared.utils.io.read_file(
        str(CONFIG_FOLDER / expected_file))

    assert actual == expected
Esempio n. 5
0
def test_get_configuration(config_path: Path,
                           expected_keys_to_configure: Set[Text],
                           tmp_path: Path):
    new_config_file = tmp_path / "new_config.yml"
    shutil.copyfile(config_path, new_config_file)

    config = rasa.shared.utils.io.read_model_configuration(new_config_file)
    _config, _missing_keys, configured_keys = DefaultV1Recipe.auto_configure(
        new_config_file, config)

    assert sorted(configured_keys) == sorted(expected_keys_to_configure)
Esempio n. 6
0
def test_comment_causing_invalid_autoconfig(tmp_path: Path):
    """Regression test for https://github.com/RasaHQ/rasa/issues/6948."""
    config_file = tmp_path / "config.yml"
    shutil.copyfile(
        str(CONFIG_FOLDER / "config_with_comment_between_suggestions.yml"),
        config_file)
    config = rasa.shared.utils.io.read_model_configuration(config_file)

    _ = DefaultV1Recipe.auto_configure(str(config_file), config)

    # This should not throw
    dumped = rasa.shared.utils.io.read_yaml_file(config_file)

    assert dumped
Esempio n. 7
0
def test_no_warnings_with_default_project(tmp_path: Path):
    rasa.utils.common.copy_directory(Path("rasa/cli/initial_project"),
                                     tmp_path)

    importer = TrainingDataImporter.load_from_config(
        config_path=str(tmp_path / "config.yml"),
        domain_path=str(tmp_path / "domain.yml"),
        training_data_paths=[str(tmp_path / "data")],
    )

    config, _missing_keys, _configured_keys = DefaultV1Recipe.auto_configure(
        importer.get_config_file_for_auto_config(),
        importer.get_config(),
        TrainingType.END_TO_END,
    )
    graph_config = DefaultV1Recipe().graph_config_for_recipe(
        config, cli_parameters={}, training_type=TrainingType.END_TO_END)
    validator = DefaultV1RecipeValidator(graph_config.train_schema)

    with pytest.warns(None) as records:
        validator.validate(importer)
    assert len(records) == 0