def test_read_yaml_string_with_env_var_not_exist(): config_with_env_var_not_exist = """ user: ${USER_NAME} password: ${PASSWORD} """ with pytest.raises(ValueError): utils.read_yaml_string(config_with_env_var_not_exist)
def test_read_yaml_string_with_multiple_env_vars_per_line(): config_with_env_var = """ user: ${USER_NAME} ${PASS} password: ${PASS} """ r = utils.read_yaml_string(config_with_env_var) assert r['user'] == 'user pass' and r['password'] == 'pass'
def test_read_yaml_string_with_env_var_infix(): config_with_env_var_infix = """ user: db_${USER_NAME}_admin password: db_${PASS}_admin """ r = utils.read_yaml_string(config_with_env_var_infix) assert r['user'] == 'db_user_admin' and r['password'] == 'db_pass_admin'
def test_read_yaml_string(): config_without_env_var = """ user: user password: pass """ r = utils.read_yaml_string(config_without_env_var) assert r['user'] == 'user' and r['password'] == 'pass'
def test_read_yaml_string_with_env_var(): config_with_env_var = """ user: ${USER_NAME} password: ${PASS} """ r = utils.read_yaml_string(config_with_env_var) assert r['user'] == 'user' and r['password'] == 'pass'
def test_read_yaml_string_with_env_var_prefix(): config_with_env_var_prefix = """ user: db_${USER_NAME} password: db_${PASS} """ r = utils.read_yaml_string(config_with_env_var_prefix) assert r['user'] == 'db_user' and \ r['password'] == 'db_pass'
def load_from_yaml(cls, yaml, action_factory=None): cls.validate_domain_yaml(yaml) data = read_yaml_string(yaml) utter_templates = cls.collect_templates(data.get("templates", {})) if not action_factory: action_factory = data.get("action_factory", None) slots = cls.collect_slots(data.get("slots", {})) additional_arguments = data.get("config", {}) intents = cls.collect_intents(data.get("intents", {})) return cls(intents, data.get("entities", []), slots, utter_templates, data.get("actions", []), data.get("action_names", []), action_factory, **additional_arguments)
def validate_domain_yaml(cls, yaml): """Validate domain yaml.""" from pykwalify.core import Core log = logging.getLogger('pykwalify') log.setLevel(logging.WARN) schema_file = pkg_resources.resource_filename(__name__, "schemas/domain.yml") source_data = utils.read_yaml_string(yaml) c = Core(source_data=source_data, schema_files=[schema_file]) try: c.validate(raise_exception=True) except SchemaError: raise InvalidDomain("Failed to validate your domain yaml. " "Make sure the file is correct, to do so" "take a look at the errors logged during " "validation previous to this exception. ")
def load_from_yaml(cls, yaml, action_factory=None): cls.validate_domain_yaml(yaml) data = read_yaml_string(yaml) utter_templates = cls.collect_templates(data.get("templates", {})) if not action_factory: action_factory = data.get("action_factory", None) slots = cls.collect_slots(data.get("slots", {})) additional_arguments = data.get("config", {}) return cls( data.get("intents", []), data.get("entities", []), slots, utter_templates, data.get("actions", []), data.get("action_names", []), action_factory, **additional_arguments )
def validate_domain_yaml(cls, yaml): """Validate domain yaml.""" from pykwalify.core import Core log = logging.getLogger('pykwalify') log.setLevel(logging.WARN) schema_file = pkg_resources.resource_filename(__name__, "schemas/domain.yml") source_data = utils.read_yaml_string(yaml) c = Core(source_data=source_data, schema_files=[schema_file]) try: c.validate(raise_exception=True) except SchemaError: raise ValueError("Failed to validate your domain yaml. " "Make sure the file is correct, to do so" "take a look at the errors logged during " "validation previous to this exception. ")
def from_yaml(cls, yaml): cls.validate_domain_yaml(yaml) data = read_yaml_string(yaml) return cls.from_dict(data)