def test_read_mixed_training_data_file(domain: Domain): training_data_file = "data/test_mixed_yaml_training_data/training_data.yml" reader = YAMLStoryReader(domain) yaml_content = rasa.shared.utils.io.read_yaml_file(training_data_file) with pytest.warns(None) as record: reader.read_from_parsed_yaml(yaml_content) assert not len(record)
async def test_no_warning_if_intent_in_domain(default_domain: Domain): stories = (f'version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"\n' f"stories:\n" f"- story: I am fine 💥\n" f" steps:\n" f" - intent: greet") reader = YAMLStoryReader(default_domain) yaml_content = rasa.shared.utils.io.read_yaml(stories) with pytest.warns(None) as record: reader.read_from_parsed_yaml(yaml_content) assert not len(record)
async def test_active_loop_is_parsed(default_domain: Domain): stories = (f'version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"\n' f"stories:\n" f"- story: name\n" f" steps:\n" f" - intent: greet\n" f" - active_loop: null") reader = YAMLStoryReader(default_domain) yaml_content = rasa.shared.utils.io.read_yaml(stories) with pytest.warns(None) as record: reader.read_from_parsed_yaml(yaml_content) assert not len(record)
def test_or_statement_if_not_training_mode(): stories = """ stories: - story: hello world steps: - or: - intent: intent1 - intent: intent2 - action: some_action - intent: intent3 - action: other_action """ reader = YAMLStoryReader(is_used_for_training=False) yaml_content = rasa.shared.utils.io.read_yaml(stories) steps = reader.read_from_parsed_yaml(yaml_content) assert len(steps) == 1 assert len(steps[0].events) == 4 # 4 events in total assert len(steps[0].start_checkpoints) == 1 assert steps[0].start_checkpoints[0].name == "STORY_START" assert steps[0].end_checkpoints == [] or_statement = steps[0].events[0] assert isinstance(or_statement, list) # But first one is a list (OR) assert or_statement[0].intent["name"] == "intent1" assert or_statement[1].intent["name"] == "intent2"
def test_as_story_string_or_statement(): from rasa.shared.core.training_data.story_reader.yaml_story_reader import ( YAMLStoryReader, ) import rasa.shared.utils.io stories = """ stories: - story: hello world steps: - or: - intent: intent1 - intent: intent2 - intent: intent3 - action: some_action """ reader = YAMLStoryReader(is_used_for_training=False) yaml_content = rasa.shared.utils.io.read_yaml(stories) steps = reader.read_from_parsed_yaml(yaml_content) assert len(steps) == 1 assert (steps[0].as_story_string() == """ ## hello world * intent1 OR intent2 OR intent3 - some_action """)
async def test_warning_if_intent_not_in_domain(domain: Domain): stories = """ stories: - story: I am gonna make you explode 💥 steps: # Intent defined in user key. - intent: definitely not in domain """ reader = YAMLStoryReader(domain) yaml_content = rasa.shared.utils.io.read_yaml(stories) with pytest.warns(UserWarning) as record: reader.read_from_parsed_yaml(yaml_content) # one for missing intent assert len(record) == 1
def test_handles_mixed_steps_for_test_and_e2e_stories(is_conversation_test): stories = """ stories: - story: hello world steps: - user: Hi - bot: Hello? - user: Well... intent: suspicion """ reader = YAMLStoryReader() yaml_content = rasa.shared.utils.io.read_yaml(stories) steps = reader.read_from_parsed_yaml(yaml_content) events = steps[0].events assert len(events) == 3 assert events[0].text == "Hi" assert events[1].action_text == "Hello?" assert events[2].text == "Well..."
def test_or_statement_with_slot_was_set(): stories = """ stories: - story: tell name bob or joe steps: - intent: greet - action: utter_greet - intent: tell_name - or: - slot_was_set: - name: joe - slot_was_set: - name: bob - slot_was_set: - name: null """ reader = YAMLStoryReader() yaml_content = rasa.shared.utils.io.read_yaml(stories) steps = reader.read_from_parsed_yaml(yaml_content) assert len(steps) == 3 slot = steps[0].events[3] assert isinstance(slot, SlotSet) assert slot.key == "name" assert slot.value == "joe" slot = steps[1].events[3] assert isinstance(slot, SlotSet) assert slot.key == "name" assert slot.value == "bob" slot = steps[2].events[3] assert isinstance(slot, SlotSet) assert slot.key == "name" assert slot.value is None