def test_prepare_credentials_if_already_valid(tmpdir: Path): credentials_path = str(tmpdir / "credentials.yml") credentials = { "rasa": { "url": "my-custom-url" }, "another-channel": { "url": "some-url" }, } io_utils.write_yaml_file(credentials, credentials_path) x._prepare_credentials_for_rasa_x(credentials_path) actual = io_utils.read_config_file(credentials_path) assert actual == credentials
def update_number_of_epochs(config_path: Text, output_file: Text): config = io_utils.read_yaml_file(config_path) if "pipeline" not in config.keys(): raise ValueError(f"Invalid config provided! File: '{config_path}'.") for component in config["pipeline"]: # do not update epochs for pipeline templates if not isinstance(component, dict): continue if component["name"] in [ DIETClassifier.name, ResponseSelector.name, ]: component[EPOCHS] = 1 io_utils.write_yaml_file(config, output_file)
def test_prepare_credentials_if_already_valid(tmpdir_factory): directory = tmpdir_factory.mktemp("directory") credentials_path = str(directory / "credentials.yml") credentials = { "rasa": { "url": "my-custom-url" }, "another-channel": { "url": "some-url" }, } io_utils.write_yaml_file(credentials, credentials_path) x._prepare_credentials_for_rasa_x(credentials_path) actual = io_utils.read_yaml_file(credentials_path) assert actual == credentials
def _prepare_credentials_for_rasa_x(credentials_path: Optional[Text]) -> Text: credentials_path = get_validated_path(credentials_path, "credentials", DEFAULT_CREDENTIALS_PATH, True) if credentials_path: credentials = io_utils.read_yaml_file(credentials_path) else: credentials = {} # If no credentials are given, create a new credentials file. credentials_path = DEFAULT_CREDENTIALS_PATH if not credentials.get("rasa"): credentials["rasa"] = {"url": "http://localhost:5002/api"} io_utils.write_yaml_file(credentials, credentials_path) logging.debug("No Rasa credentials given. Creating one in '{}'" "".format(credentials_path)) return credentials_path
async def test_fail_on_invalid_utterances(tmpdir): # domain and stories are from different domain and should produce warnings invalid_domain = str(tmpdir / "invalid_domain.yml") io_utils.write_yaml_file( { "responses": { "utter_greet": { "text": "hello" } }, "actions": [ "utter_greet", "utter_non_existent", # error: utter template odes not exist ], }, invalid_domain, ) importer = RasaFileImporter(domain_path=invalid_domain) validator = await Validator.from_importer(importer) assert not validator.verify_utterances()
def test_dump_yaml_key_order(tmp_path: Path, should_preserve_key_order: bool, expected_keys: List[Text]): file = tmp_path / "test.yml" # create YAML file with keys in reverse-alphabetical order content = "" for i in reversed(string.ascii_lowercase): content += f"{i}: {uuid.uuid4().hex}\n" file.write_text(content) # load this file and ensure keys are in correct reverse-alphabetical order data = io_utils.read_yaml_file(file) assert list(data.keys()) == list(reversed(string.ascii_lowercase)) # dumping `data` will result in alphabetical or reverse-alphabetical list of keys, # depending on the value of `should_preserve_key_order` io_utils.write_yaml_file( data, file, should_preserve_key_order=should_preserve_key_order) with file.open() as f: keys = [line.split(":")[0] for line in f.readlines()] assert keys == expected_keys
def test_get_valid_config(parameters): config_path = None if parameters["config_data"] is not None: config_path = os.path.join(tempfile.mkdtemp(), "config.yml") io_utils.write_yaml_file(parameters["config_data"], config_path) default_config_path = None if parameters["default_config"] is not None: default_config_path = os.path.join(tempfile.mkdtemp(), "default-config.yml") io_utils.write_yaml_file(parameters["default_config"], default_config_path) if parameters["error"]: with pytest.raises(SystemExit): _get_valid_config(config_path, parameters["mandatory_keys"]) else: config_path = _get_valid_config( config_path, parameters["mandatory_keys"], default_config_path ) config_data = io_utils.read_yaml_file(config_path) for k in parameters["mandatory_keys"]: assert k in config_data
def dump_obj_as_yaml_to_file(filename: Union[Text, Path], obj: Dict) -> None: """Writes data (python dict) to the filename in yaml repr.""" io_utils.write_yaml_file(obj, filename)
def _write_endpoint_config_to_yaml(path: Path, data: Dict[Text, Any]) -> Path: endpoints_path = path / "endpoints.yml" # write endpoints config to file io_utils.write_yaml_file(data, endpoints_path) return endpoints_path