Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wochinge committed Dec 14, 2020
1 parent f1168ee commit 7e29de1
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 19 deletions.
1 change: 1 addition & 0 deletions data/test_config/max_hist_config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
policies:
- name: MemoizationPolicy
max_history: 5
- name: RulePolicy
- name: TEDPolicy
max_history: 5
1 change: 1 addition & 0 deletions data/test_config/no_max_hist_config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
policies:
- name: MemoizationPolicy
- name: RulePolicy
- name: TEDPolicy
1 change: 1 addition & 0 deletions data/test_config/ted_random_seed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ policies:
random_seed: 42
validation_split: 0
max_history: 5
- name: RulePolicy
4 changes: 4 additions & 0 deletions data/test_stories/stories_defaultdomain.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
- utter_default
* goodbye
- utter_goodbye

## goodbye
* goodbye
- utter_goodbye
2 changes: 1 addition & 1 deletion data/test_trackers/tracker_moodbot.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"paused": false,
"latest_event_time": 1517821726.211042,
"followup_action": null,
"slots": {"name": null},
"slots": {"name": null, "requested_slot": null},
"latest_input_channel": null,
"events": [
{
Expand Down
6 changes: 3 additions & 3 deletions rasa/core/policies/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,9 @@ def _check_policy_for_forms_available(
if domain.form_names and not has_policy_for_forms:
raise InvalidDomain(
"You have defined a form action, but have neither added the "
f"'{RulePolicy.__name__}' nor '{FormPolicy.__name__}' (deprecated) to your "
f"policy ensemble. Either remove all forms from your domain or add the "
"missing policy to your policy configuration."
f"'{RulePolicy.__name__}' nor the '{FormPolicy.__name__}' (deprecated) to "
f"your policy ensemble. Either remove all forms from your domain or add "
f"the missing policy to your policy configuration."
)


Expand Down
5 changes: 3 additions & 2 deletions tests/core/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
RULE_SNIPPET_ACTION_NAME,
ACTIVE_LOOP,
FOLLOWUP_ACTION,
REQUESTED_SLOT,
)
from rasa.shared.core.trackers import DialogueStateTracker
from rasa.utils.endpoints import ClientResponseError, EndpointConfig
Expand Down Expand Up @@ -164,7 +165,7 @@ async def test_remote_action_runs(
"paused": False,
"latest_event_time": None,
FOLLOWUP_ACTION: "action_listen",
"slots": {"name": None},
"slots": {"name": None, REQUESTED_SLOT: None},
"events": [],
"latest_input_channel": None,
},
Expand Down Expand Up @@ -219,7 +220,7 @@ async def test_remote_action_logs_events(
"paused": False,
FOLLOWUP_ACTION: ACTION_LISTEN_NAME,
"latest_event_time": None,
"slots": {"name": None},
"slots": {"name": None, REQUESTED_SLOT: None},
"events": [],
"latest_input_channel": None,
},
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def test_form_without_form_policy(policy_config: Dict[Text, List[Text]]):
domain=Domain.from_dict({"forms": ["restaurant_form"]}),
policies=PolicyEnsemble.from_dict(policy_config),
)
assert "haven't added the FormPolicy" in str(execinfo.value)
assert "neither added the 'RulePolicy' nor the 'FormPolicy'" in str(execinfo.value)


@pytest.mark.parametrize(
Expand Down
9 changes: 4 additions & 5 deletions tests/core/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,13 @@ async def test_reminder_scheduled(
# retrieve the updated tracker
t = default_processor.tracker_store.retrieve(sender_id)

assert t.events[-5] == UserUttered("test")
assert t.events[-4] == ActionExecuted("action_schedule_reminder")
assert isinstance(t.events[-3], ReminderScheduled)
assert t.events[-2] == UserUttered(
assert t.events[1] == UserUttered("test")
assert t.events[2] == ActionExecuted("action_schedule_reminder")
assert isinstance(t.events[3], ReminderScheduled)
assert t.events[4] == UserUttered(
f"{EXTERNAL_MESSAGE_PREFIX}remind",
intent={INTENT_NAME_KEY: "remind", IS_EXTERNAL: True},
)
assert t.events[-1] == ActionExecuted("action_listen")


async def test_trigger_external_latest_input_channel(
Expand Down
13 changes: 8 additions & 5 deletions tests/core/test_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from _pytest.monkeypatch import MonkeyPatch

from rasa.core.policies.memoization import MemoizationPolicy, OLD_DEFAULT_MAX_HISTORY
from rasa.core.policies.rule_policy import RulePolicy
from rasa.shared.core.domain import Domain
from rasa.core.interpreter import RasaNLUInterpreter
from rasa.shared.nlu.interpreter import RegexInterpreter
Expand Down Expand Up @@ -113,12 +114,12 @@ async def test_training_script_with_max_history_set(tmp_path: Path):
additional_arguments={},
)
agent = Agent.load(tmpdir)

expected_max_history = {FormPolicy: 2, RulePolicy: None}
for policy in agent.policy_ensemble.policies:
if hasattr(policy.featurizer, "max_history"):
if type(policy) == FormPolicy:
assert policy.featurizer.max_history == 2
else:
assert policy.featurizer.max_history == 5
expected_history = expected_max_history.get(type(policy), 5)
assert policy.featurizer.max_history == expected_history


@pytest.mark.parametrize(
Expand Down Expand Up @@ -181,7 +182,9 @@ async def test_trained_interpreter_passed_to_policies(
):
from rasa.core.policies.ted_policy import TEDPolicy

policies_config = {"policies": [{"name": TEDPolicy.__name__}]}
policies_config = {
"policies": [{"name": TEDPolicy.__name__}, {"name": RulePolicy.__name__}]
}

policy_train = Mock()
monkeypatch.setattr(TEDPolicy, "train", policy_train)
Expand Down
1 change: 1 addition & 0 deletions tests/shared/core/test_trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ async def test_tracker_dump_e2e_story(default_agent: Agent):
"* greet: /greet",
" - utter_greet",
"* goodbye: /goodbye",
" - utter_goodbye",
]


Expand Down
8 changes: 6 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
CallbackInput,
)
from rasa.core.channels.slack import SlackBot
from rasa.shared.core.constants import ACTION_SESSION_START_NAME, ACTION_LISTEN_NAME
from rasa.shared.core.constants import (
ACTION_SESSION_START_NAME,
ACTION_LISTEN_NAME,
REQUESTED_SLOT,
)
from rasa.shared.core.domain import Domain, SessionConfig
from rasa.shared.core.events import (
Event,
Expand Down Expand Up @@ -854,7 +858,7 @@ async def test_requesting_non_existent_tracker(rasa_app: SanicASGITestClient):
content = response.json()
assert response.status == 200
assert content["paused"] is False
assert content["slots"] == {"name": None}
assert content["slots"] == {"name": None, REQUESTED_SLOT: None}
assert content["sender_id"] == "madeupid"
assert content["events"] == [
{
Expand Down

0 comments on commit 7e29de1

Please sign in to comment.