Exemplo 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)

    autoconfig.get_configuration(config_file)

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

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

    assert actual == 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
Exemplo n.º 2
0
def test_get_configuration_missing_file(tmp_path: Path, config_file: Text):
    if config_file:
        config_file = tmp_path / "non_existent_config.yml"

    config = autoconfig.get_configuration(str(config_file))

    assert config == {}
Exemplo n.º 3
0
def test_get_configuration_for_different_training_types(
    tmp_path: Path,
    input_file: Text,
    expected_file: Text,
    training_type: autoconfig.TrainingType,
):
    config_file = str(tmp_path / "config.yml")
    shutil.copyfile(str(CONFIG_FOLDER / input_file), config_file)

    autoconfig.get_configuration(config_file, 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
Exemplo n.º 4
0
    def __init__(
        self,
        config_file: Optional[Text] = None,
        domain_path: Optional[Text] = None,
        training_data_paths: Optional[Union[List[Text], Text]] = None,
        training_type: Optional[TrainingType] = TrainingType.BOTH,
    ):

        self._domain_path = domain_path

        self._nlu_files = rasa.shared.data.get_data_files(
            training_data_paths, rasa.shared.data.is_nlu_file)
        self._story_files = rasa.shared.data.get_data_files(
            training_data_paths, rasa.shared.data.is_story_file)

        self.config = autoconfig.get_configuration(config_file, training_type)
Exemplo n.º 5
0
def test_get_configuration(
    config_path: Path, autoconfig_keys: Set[Text], monkeypatch: MonkeyPatch
):
    def _auto_configure(_, keys_to_configure: Set[Text]) -> Set[Text]:
        return keys_to_configure

    monkeypatch.setattr(autoconfig, "_dump_config", Mock())
    monkeypatch.setattr(autoconfig, "_auto_configure", _auto_configure)

    config = autoconfig.get_configuration(str(config_path))

    if autoconfig_keys:
        expected_config = _auto_configure(config, autoconfig_keys)
    else:
        expected_config = config

    assert sorted(config) == sorted(expected_config)