Files
wehub-resource-sync dc6079821b
Docs Tests / Check for file changes (push) Has been cancelled
Docs Tests / Test Documentation (push) Has been cancelled
Docs Tests / Documentation Linting Checks (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.9) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.9) (push) Has been cancelled
Continuous Integration / Check for file changes (push) Has been cancelled
Continuous Integration / Wait for docs tests (push) Has been cancelled
Continuous Integration / Code Quality (push) Has been cancelled
Continuous Integration / Check for changelog (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Upload coverage reports to codeclimate (push) Has been cancelled
Continuous Integration / Run Non-Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Run Broker Integration Tests (push) Has been cancelled
Continuous Integration / Run Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Build Docker base images and setup environment (push) Has been cancelled
Continuous Integration / Build Docker (default) (push) Has been cancelled
Continuous Integration / Build Docker (full) (push) Has been cancelled
Continuous Integration / Build Docker (mitie-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-de) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-it) (push) Has been cancelled
Continuous Integration / Deploy to PyPI (push) Has been cancelled
Continuous Integration / Notify Slack & Publish Release Notes (push) Has been cancelled
Publish Documentation / Evaluate release tag (push) Has been cancelled
Publish Documentation / Prebuild Docs (push) Has been cancelled
Publish Documentation / Preview Docs (push) Has been cancelled
Publish Documentation / Check for file changes (push) Has been cancelled
Publish Documentation / Publish Docs (push) Has been cancelled
Automatic PR Merger / mergepal (push) Has been cancelled
CI Github Actions / Run Tests (push) Has been cancelled
Semgrep / Semgrep Workflow Security Scan (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:24:47 +08:00

254 lines
7.4 KiB
Python

from typing import Text
import pytest
from rasa.shared.constants import LATEST_TRAINING_DATA_FORMAT_VERSION
from rasa.shared.core.constants import SlotMappingType
from rasa.shared.core.domain import Domain
from rasa.shared.core.events import UserUttered, ActiveLoop
from rasa.shared.core.slot_mappings import SlotMapping
from rasa.shared.core.trackers import DialogueStateTracker
from rasa.shared.utils.validation import YamlValidationException
@pytest.mark.parametrize(
"slot_name, expected", [("GPE_destination", True), ("GPE_origin", False)]
)
def test_slot_mapping_entity_is_desired(slot_name: Text, expected: bool):
domain = Domain.from_file("data/test_domains/travel_form.yml")
tracker = DialogueStateTracker("test_id", slots=domain.slots)
event = UserUttered(
text="I'm travelling to Vancouver.",
intent={"name": "inform", "confidence": 0.9604260921478271},
entities=[{"entity": "GPE", "value": "Vancouver", "role": "destination"}],
)
tracker.update(event, domain)
slot_mappings = domain.as_dict().get("slots").get(slot_name).get("mappings")
assert SlotMapping.entity_is_desired(slot_mappings[0], tracker) is expected
def test_slot_mapping_intent_is_desired(domain: Domain):
domain = Domain.from_file("examples/formbot/domain.yml")
tracker = DialogueStateTracker("sender_id_test", slots=domain.slots)
event1 = UserUttered(
text="I'd like to book a restaurant for 2 people.",
intent={"name": "request_restaurant", "confidence": 0.9604260921478271},
entities=[{"entity": "number", "value": 2}],
)
tracker.update(event1, domain)
mappings_for_num_people = (
domain.as_dict().get("slots").get("num_people").get("mappings")
)
assert SlotMapping.intent_is_desired(mappings_for_num_people[0], tracker, domain)
event2 = UserUttered(
text="Yes, 2 please",
intent={"name": "affirm", "confidence": 0.9604260921478271},
entities=[{"entity": "number", "value": 2}],
)
tracker.update(event2, domain)
assert (
SlotMapping.intent_is_desired(mappings_for_num_people[0], tracker, domain)
is False
)
event3 = UserUttered(
text="Yes, please",
intent={"name": "affirm", "confidence": 0.9604260921478271},
entities=[],
)
tracker.update(event3, domain)
mappings_for_preferences = (
domain.as_dict().get("slots").get("preferences").get("mappings")
)
assert (
SlotMapping.intent_is_desired(mappings_for_preferences[0], tracker, domain)
is False
)
def test_slot_mappings_ignored_intents_during_active_loop():
domain = Domain.from_yaml(
"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
intents:
- greet
- chitchat
slots:
cuisine:
type: text
mappings:
- type: from_text
conditions:
- active_loop: restaurant_form
forms:
restaurant_form:
ignored_intents:
- chitchat
required_slots:
- cuisine
"""
)
tracker = DialogueStateTracker("sender_id", slots=domain.slots)
event1 = ActiveLoop("restaurant_form")
event2 = UserUttered(
text="The weather is sunny today",
intent={"name": "chitchat", "confidence": 0.9604260921478271},
entities=[],
)
tracker.update_with_events([event1, event2], domain)
mappings_for_cuisine = domain.as_dict().get("slots").get("cuisine").get("mappings")
assert (
SlotMapping.intent_is_desired(mappings_for_cuisine[0], tracker, domain) is False
)
def test_missing_slot_mappings_raises():
with pytest.raises(YamlValidationException):
Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
slots:
some_slot:
type: text
influence_conversation: False
"""
)
def test_slot_mappings_invalid_type_raises():
with pytest.raises(YamlValidationException):
Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
entities:
- from_entity
slots:
some_slot:
type: text
influence_conversation: False
mappings:
type: from_entity
entity: some_entity
"""
)
def test_slot_mappings_check_mapping_validity_from_intent():
slot_name = "mood"
domain = Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
intents:
- greet
- goodbye
- mood_great
- mood_unhappy
slots:
{slot_name}:
type: categorical
values:
- great
- sad
mappings:
- type: from_intent
not_intent: mood_unhappy
value: great
- type: from_intent
intent: mood_unhappy
value: sad
"""
)
mappings_for_slot = domain.as_dict().get("slots").get(slot_name).get("mappings")
assert SlotMapping.check_mapping_validity(
slot_name=slot_name,
mapping_type=SlotMappingType.FROM_INTENT,
mapping=mappings_for_slot[0],
domain=domain,
)
@pytest.mark.parametrize(
"intent, expected",
[
(["goodbye", "mood_great", "greet"], True),
([], True),
("", True),
({}, True),
("null", True),
],
)
def test_slot_mappings_check_mapping_validity_valid_intent_list(
intent: Text, expected: bool
):
slot_name = "mood"
domain = Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
intents:
- greet
- goodbye
- mood_great
- mood_unhappy
slots:
{slot_name}:
type: any
influence_conversation: false
mappings:
- type: from_intent
value: "testing 123"
intent: {intent}
forms:
test_form:
required_slots:
- test_slot
"""
)
mappings_for_slot = domain.as_dict().get("slots").get(slot_name).get("mappings")
assert (
SlotMapping.check_mapping_validity(
slot_name=slot_name,
mapping_type=SlotMappingType.FROM_INTENT,
mapping=mappings_for_slot[0],
domain=domain,
)
is expected
)
def test_slot_mappings_check_mapping_validity_invalid_intent_list():
slot_name = "mood"
domain = Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
intents:
- greet
- goodbye
- mood_great
- mood_unhappy
slots:
{slot_name}:
type: any
influence_conversation: false
mappings:
- type: from_intent
value: "testing 123"
intent:
- aaaa
- bbbb
- cccc
forms:
test_form:
required_slots:
- test_slot
"""
)
mappings_for_slot = domain.as_dict().get("slots").get(slot_name).get("mappings")
assert not SlotMapping.check_mapping_validity(
slot_name=slot_name,
mapping_type=SlotMappingType.FROM_INTENT,
mapping=mappings_for_slot[0],
domain=domain,
)