Skip to content

Commit

Permalink
Changes while checking the intent mapping & new test
Browse files Browse the repository at this point in the history
- Replaced try/except statement with if/else when checking if intent mapping is empty.
- Minor rewording on the exception message.
- Added a new test to check if the exception is correctly raised.
  • Loading branch information
Imod7 committed Mar 17, 2021
1 parent 4505282 commit be336d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rasa/shared/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@ def _transform_intent_properties_for_internal_use(
"""
name, properties = list(intent.items())[0]

try:
if properties:
properties.setdefault(USE_ENTITIES_KEY, True)
except:
else:
raise InvalidDomain(
f"In the `domain.yml` file, the intent `{name}` cannot have value of"
f" `{type(properties)}`. This can happen if you add an intent with the"
f"`:`(colon character) after it and do not add any further information"
f"to this specific intent."
f" `:` (colon character) after it and do not add any"
f" further information to this specific intent."
f" If you remove the `:` character it should work. Please see "
f"{rasa.shared.constants.DOCS_URL_DOMAINS} for more information on how"
f" to correctly add `intents` in the `domain` and"
Expand Down
10 changes: 10 additions & 0 deletions tests/shared/core/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,3 +1306,13 @@ def test_is_valid_domain_doesnt_raise_with_invalid_yaml(tmpdir: Path):
potential_domain_path,
)
assert not Domain.is_domain_file(potential_domain_path)


def test_domain_with_empty_intent_mapping():
# domain.yml with intent (intent_name) that has a `:` character
# and nothing after it.
test_yaml = """intents:
- intent_name:"""

with pytest.raises(InvalidDomain):
Domain.from_yaml(test_yaml).as_dict()

0 comments on commit be336d9

Please sign in to comment.