Skip to content

Commit

Permalink
Add test for NLG change - [ENG 501] (#12875)
Browse files Browse the repository at this point in the history
* Add test for NLG change
  • Loading branch information
varunshankar authored Oct 10, 2023
1 parent fc5a2a7 commit 1a66128
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions tests/core/nlg/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rasa.shared.core.domain import Domain
from rasa.shared.core.slots import TextSlot, AnySlot, CategoricalSlot, BooleanSlot
from rasa.shared.core.trackers import DialogueStateTracker
from rasa.shared.utils.validation import YamlValidationException


async def test_nlg_conditional_response_variations_with_no_slots():
Expand Down Expand Up @@ -625,3 +626,93 @@ async def test_nlg_conditional_response_variations_condition_logging(
"[condition 2] type: slot | name: test_B | value: B" in message
for message in caplog.messages
)


async def test_nlg_response_with_no_text():
with pytest.raises(YamlValidationException):
Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
responses:
utter_flow_xyz:
- buttons:
- payload: "yes"
title: Yes
- payload: "no"
title: No
"""
)


async def test_nlg_response_with_default_template_engine():
domain = Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
responses:
utter_flow_xyz:
- text: "Do you want to update the values?"
"""
)
t = TemplatedNaturalLanguageGenerator(domain.responses)
r = t.generate_from_slots(
"utter_flow_xyz",
{"tm": "50"},
{
"frame_id": "XYYZABCD",
"corrected_slots": {"tm": "100"},
},
"",
)
assert r.get("text") == "Do you want to update the values?"


async def test_nlg_response_with_jinja_template():
domain = Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
responses:
utter_flow_xyz:
- text: "Do you want to update the
{{{{ context.corrected_slots.keys()|join(', ') }}}}?"
metadata:
rephrase: true
template: jinja
"""
)
t = TemplatedNaturalLanguageGenerator(domain.responses)
r = t.generate_from_slots(
"utter_flow_xyz",
{"tm": "50"},
{
"frame_id": "XYYZABCD",
"corrected_slots": {"tm": "100"},
},
"",
)
assert r.get("text") == "Do you want to update the tm?"


async def test_nlg_response_with_unknown_var_jinja_template():
domain = Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
responses:
utter_flow_xyz:
- text: "Do you want to update the {{{{ context.unknown_key }}}}?"
metadata:
rephrase: true
template: jinja
"""
)
t = TemplatedNaturalLanguageGenerator(domain.responses)
r = t.generate_from_slots(
"utter_flow_xyz",
{"tm": "50"},
{
"frame_id": "XYYZABCD",
"corrected_slots": {"tm": "100"},
},
"",
)
assert r.get("text") == "Do you want to update the ?"

0 comments on commit 1a66128

Please sign in to comment.