Skip to content

Commit

Permalink
improved and fixed tests relying on strict number indices
Browse files Browse the repository at this point in the history
  • Loading branch information
twerkmeister committed Sep 25, 2023
1 parent f7a4391 commit a0b95b3
Showing 1 changed file with 88 additions and 8 deletions.
96 changes: 88 additions & 8 deletions tests/core/featurizers/test_tracker_featurizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ACTION_UNLIKELY_INTENT_NAME,
USER,
PREVIOUS_ACTION,
DEFAULT_ACTION_NAMES,

Check failure on line 25 in tests/core/featurizers/test_tracker_featurizer.py

View workflow job for this annotation

GitHub Actions / Code Quality

F401 [*] `rasa.shared.core.constants.DEFAULT_ACTION_NAMES` imported but unused
)
from rasa.shared.core.events import ActionExecuted
from rasa.shared.core.trackers import DialogueStateTracker
Expand Down Expand Up @@ -179,14 +180,25 @@ def test_featurize_trackers_with_full_dialogue_tracker_featurizer(
},
]
]

assert actual_features is not None
assert len(actual_features) == len(expected_features)

for actual, expected in zip(actual_features, expected_features):
assert compare_featurized_states(actual, expected)

expected_labels = np.array([[0, 21, 0, 18, 19, 0, 20]])
expected_labels = np.array(
[
[
0,
moodbot_domain.action_names_or_texts.index("utter_greet"),
0,
moodbot_domain.action_names_or_texts.index("utter_cheer_up"),
moodbot_domain.action_names_or_texts.index("utter_did_that_help"),
0,
moodbot_domain.action_names_or_texts.index("utter_goodbye"),
]
]
)
assert actual_labels is not None
assert len(actual_labels) == 1
for actual, expected in zip(actual_labels, expected_labels):
Expand Down Expand Up @@ -255,7 +267,19 @@ def test_trackers_ignore_action_unlikely_intent_with_full_dialogue_tracker_featu
for actual, expected in zip(actual_features, expected_features):
assert compare_featurized_states(actual, expected)

expected_labels = np.array([[0, 21, 0, 18, 19, 0, 20]])
expected_labels = np.array(
[
[
0,
moodbot_domain.action_names_or_texts.index("utter_greet"),
0,
moodbot_domain.action_names_or_texts.index("utter_cheer_up"),
moodbot_domain.action_names_or_texts.index("utter_did_that_help"),
0,
moodbot_domain.action_names_or_texts.index("utter_goodbye"),
]
]
)
assert actual_labels is not None
assert len(actual_labels) == 1
for actual, expected in zip(actual_labels, expected_labels):
Expand Down Expand Up @@ -324,7 +348,22 @@ def test_trackers_keep_action_unlikely_intent_with_full_dialogue_tracker_featuri
for actual, expected in zip(actual_features, expected_features):
assert compare_featurized_states(actual, expected)

expected_labels = np.array([[0, 9, 21, 0, 9, 18, 19, 0, 9, 20]])
expected_labels = np.array(
[
[
0,
moodbot_domain.action_names_or_texts.index("action_unlikely_intent"),
moodbot_domain.action_names_or_texts.index("utter_greet"),
0,
moodbot_domain.action_names_or_texts.index("action_unlikely_intent"),
moodbot_domain.action_names_or_texts.index("utter_cheer_up"),
moodbot_domain.action_names_or_texts.index("utter_did_that_help"),
0,
moodbot_domain.action_names_or_texts.index("action_unlikely_intent"),
moodbot_domain.action_names_or_texts.index("utter_goodbye"),
]
]
)
assert actual_labels is not None
assert len(actual_labels) == 1
for actual, expected in zip(actual_labels, expected_labels):
Expand Down Expand Up @@ -832,7 +871,19 @@ def test_featurize_trackers_with_max_history_tracker_featurizer(
for actual, expected in zip(actual_features, expected_features):
assert compare_featurized_states(actual, expected)

expected_labels = np.array([[0, 21, 0, 18, 19, 0, 20]]).T
expected_labels = np.array(
[
[
0,
moodbot_domain.action_names_or_texts.index("utter_greet"),
0,
moodbot_domain.action_names_or_texts.index("utter_cheer_up"),
moodbot_domain.action_names_or_texts.index("utter_did_that_help"),
0,
moodbot_domain.action_names_or_texts.index("utter_goodbye"),
]
]
).T

assert actual_labels is not None
assert actual_labels.shape == expected_labels.shape
Expand Down Expand Up @@ -899,7 +950,15 @@ def test_featurize_trackers_ignore_action_unlikely_intent_max_history_featurizer
for actual, expected in zip(actual_features, expected_features):
assert compare_featurized_states(actual, expected)

expected_labels = np.array([[0, 21, 0]]).T
expected_labels = np.array(
[
[
0,
moodbot_domain.action_names_or_texts.index("utter_greet"),
0,
]
]
).T
assert actual_labels.shape == expected_labels.shape
for actual, expected in zip(actual_labels, expected_labels):
assert np.all(actual == expected)
Expand Down Expand Up @@ -971,7 +1030,16 @@ def test_featurize_trackers_keep_action_unlikely_intent_max_history_featurizer(
for actual, expected in zip(actual_features, expected_features):
assert compare_featurized_states(actual, expected)

expected_labels = np.array([[0, 9, 21, 0]]).T
expected_labels = np.array(
[
[
0,
moodbot_domain.action_names_or_texts.index("action_unlikely_intent"),
moodbot_domain.action_names_or_texts.index("utter_greet"),
0,
]
]
).T
assert actual_labels is not None
assert actual_labels.shape == expected_labels.shape
for actual, expected in zip(actual_labels, expected_labels):
Expand Down Expand Up @@ -1088,7 +1156,19 @@ def test_deduplicate_featurize_trackers_with_max_history_tracker_featurizer(
for actual, expected in zip(actual_features, expected_features):
assert compare_featurized_states(actual, expected)

expected_labels = np.array([[0, 21, 0, 18, 19, 0, 20]]).T
expected_labels = np.array(
[
[
0,
moodbot_domain.action_names_or_texts.index("utter_greet"),
0,
moodbot_domain.action_names_or_texts.index("utter_cheer_up"),
moodbot_domain.action_names_or_texts.index("utter_did_that_help"),
0,
moodbot_domain.action_names_or_texts.index("utter_goodbye"),
]
]
).T
if not remove_duplicates:
expected_labels = np.vstack([expected_labels] * 2)

Expand Down

0 comments on commit a0b95b3

Please sign in to comment.