Skip to content

Commit

Permalink
improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
twerkmeister committed Sep 25, 2023
1 parent 416be84 commit 68af0a3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 25 deletions.
1 change: 1 addition & 0 deletions data/test_trackers/tracker_moodbot.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"followup_action": null,
"slots": {
"dialogue_stack": null,
"flow_hashes": null,
"name": null,
"requested_slot": null,
"return_value": null,
Expand Down
5 changes: 4 additions & 1 deletion rasa/core/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
ACTION_VALIDATE_SLOT_MAPPINGS,
MAPPING_TYPE,
SlotMappingType,
KNOWLEDGE_BASE_SLOT_NAMES,
)
from rasa.shared.core.domain import Domain
from rasa.shared.core.events import (
Expand Down Expand Up @@ -1292,7 +1293,9 @@ async def run(
executed_custom_actions: Set[Text] = set()

user_slots = [
slot for slot in domain.slots if slot.name not in DEFAULT_SLOT_NAMES
slot
for slot in domain.slots
if slot.name not in DEFAULT_SLOT_NAMES | KNOWLEDGE_BASE_SLOT_NAMES
]

for slot in user_slots:
Expand Down
9 changes: 6 additions & 3 deletions rasa/shared/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,16 @@
SLOT_LAST_OBJECT_TYPE = "knowledge_base_last_object_type"
DEFAULT_KNOWLEDGE_BASE_ACTION = "action_query_knowledge_base"

KNOWLEDGE_BASE_SLOT_NAMES = {
SLOT_LISTED_ITEMS,
SLOT_LAST_OBJECT,
SLOT_LAST_OBJECT_TYPE,
}

DEFAULT_SLOT_NAMES = {
REQUESTED_SLOT,
DIALOGUE_STACK_SLOT,
SESSION_START_METADATA_SLOT,
SLOT_LISTED_ITEMS,
SLOT_LAST_OBJECT,
SLOT_LAST_OBJECT_TYPE,
RETURN_VALUE_SLOT,
FLOW_HASHES_SLOT,
}
Expand Down
9 changes: 2 additions & 7 deletions rasa/shared/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
IGNORED_INTENTS,
RESPONSE_CONDITION,
)
import rasa.shared.core.constants
from rasa.shared.core.constants import (
ACTION_SHOULD_SEND_DOMAIN,
SlotMappingType,
MAPPING_TYPE,
MAPPING_CONDITIONS,
KNOWLEDGE_BASE_SLOT_NAMES,
)
from rasa.shared.exceptions import (
RasaException,
Expand Down Expand Up @@ -1030,12 +1030,7 @@ def _add_knowledge_base_slots(self) -> None:
)
)
slot_names = [slot.name for slot in self.slots]
knowledge_base_slots = [
rasa.shared.core.constants.SLOT_LISTED_ITEMS,
rasa.shared.core.constants.SLOT_LAST_OBJECT,
rasa.shared.core.constants.SLOT_LAST_OBJECT_TYPE,
]
for slot in knowledge_base_slots:
for slot in KNOWLEDGE_BASE_SLOT_NAMES:
if slot not in slot_names:
self.slots.append(
TextSlot(slot, mappings=[], influence_conversation=False)
Expand Down
9 changes: 3 additions & 6 deletions tests/shared/core/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
DEFAULT_KNOWLEDGE_BASE_ACTION,
ENTITY_LABEL_SEPARATOR,
DEFAULT_ACTION_NAMES,
DEFAULT_SLOT_NAMES,
)
from rasa.shared.core.domain import (
InvalidDomain,
Expand Down Expand Up @@ -888,10 +889,9 @@ def test_domain_from_multiple_files():
"utter_default": [{"text": "default message"}],
"utter_amazement": [{"text": "awesomness!"}],
}
expected_slots = [
expected_slots = list(DEFAULT_SLOT_NAMES) + [
"activate_double_simulation",
"activate_simulation",
"dialogue_stack",
"display_cure_method",
"display_drum_cure_horns",
"display_method_artwork",
Expand All @@ -914,9 +914,6 @@ def test_domain_from_multiple_files():
"humbleSelectionManagement",
"humbleSelectionStatus",
"offers",
"requested_slot",
"return_value",
"session_started_metadata",
]

domain_slots = []
Expand All @@ -930,7 +927,7 @@ def test_domain_from_multiple_files():
assert expected_responses == domain.responses
assert expected_forms == domain.forms
assert domain.session_config.session_expiration_time == 360
assert expected_slots == sorted(domain_slots)
assert sorted(expected_slots) == sorted(domain_slots)


def test_domain_warnings(domain: Domain):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,12 +775,17 @@ def test_generate_training_data_with_cycles(domain: Domain):
# deterministic way but should always be 3 or 4
assert len(training_trackers) == 3 or len(training_trackers) == 4

# if we have 4 trackers, there is going to be one example more for label 10
num_tens = len(training_trackers) - 1
# if new default actions are added the keys of the actions will be changed
# if we have 4 trackers, there is going to be one example more for utter_default
num_utter_default = len(training_trackers) - 1

all_label_ids = [id for ids in label_ids for id in ids]
assert Counter(all_label_ids) == {0: 6, 20: 3, 19: num_tens, 1: 2, 21: 1}
assert Counter(all_label_ids) == {
0: 6,
domain.action_names_or_texts.index("utter_goodbye"): 3,
domain.action_names_or_texts.index("utter_default"): num_utter_default,
1: 2,
domain.action_names_or_texts.index("utter_greet"): 1,
}


def test_generate_training_data_with_unused_checkpoints(domain: Domain):
Expand Down
14 changes: 10 additions & 4 deletions tests/shared/importers/test_rasa.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
SESSION_START_METADATA_SLOT,
DIALOGUE_STACK_SLOT,
RETURN_VALUE_SLOT,
FLOW_HASHES_SLOT,
DEFAULT_SLOT_NAMES,
REQUESTED_SLOT,
)
from rasa.shared.core.domain import Domain
from rasa.shared.core.slots import AnySlot
Expand All @@ -30,11 +33,14 @@ def test_rasa_file_importer(project: Text):

domain = importer.get_domain()
assert len(domain.intents) == 7 + len(DEFAULT_INTENTS)
assert domain.slots == [
AnySlot(DIALOGUE_STACK_SLOT, mappings=[{}]),
AnySlot(RETURN_VALUE_SLOT, mappings=[{}]),
AnySlot(SESSION_START_METADATA_SLOT, mappings=[{}]),
default_slots = [
AnySlot(slot_name, mappings=[{}])
for slot_name in DEFAULT_SLOT_NAMES
if slot_name != REQUESTED_SLOT
]
assert sorted(domain.slots, key=lambda s: s.name) == sorted(
default_slots, key=lambda s: s.name
)

assert domain.entities == []
assert len(domain.action_names_or_texts) == 6 + len(DEFAULT_ACTION_NAMES)
Expand Down

0 comments on commit 68af0a3

Please sign in to comment.