Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Common Query and Intent Tests #25

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ The following top-level sections can be added to intent test configuration:
to expected: `callback_data` (list keys or dict data), `min_confidence`, and
`max_confidence`
- `common play`: TBD

- `ready event`: Optional event name to wait for before starting tests. For example,
a skill may set `_update_event` after doing some long-running process at initialization;
configuring `ready event: _update_event` means intent tests will not start until
the skill has updated and is ready to handle inputs.
## Advanced Usage
In addition to convenient CLI methods, this package also provides test cases that
may be extended.
Expand Down
72 changes: 42 additions & 30 deletions neon_minerva/tests/test_skill_intents.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from os import getenv
from os.path import join, exists
from threading import Event
from unittest.mock import Mock

from ovos_bus_client import Message
Expand Down Expand Up @@ -57,10 +58,11 @@ class TestSkillIntentMatching(unittest.TestCase):
skill_entrypoint = getenv("TEST_SKILL_ENTRYPOINT")

# Populate configuration
languages = list(valid_intents.keys())
core_config_patch = {"secondary_langs": languages}
negative_intents = valid_intents.pop('unmatched intents', dict())
common_query = valid_intents.pop("common query", dict())
ready_event = valid_intents.pop("ready event")
languages = list(valid_intents.keys())
core_config_patch = {"secondary_langs": languages}

# Define intent parsers for tests
if getenv("TEST_PADACIOSO") == "true":
Expand Down Expand Up @@ -92,6 +94,15 @@ class TestSkillIntentMatching(unittest.TestCase):
skill_id=test_skill_id, bus=bus,
config_patch=core_config_patch)

@classmethod
def setUpClass(cls):
# Default respond "no" to any yes/no prompts
cls.skill.ask_yesno = Mock(return_value="no")
if cls.ready_event and hasattr(cls.skill, cls.ready_event):
print("Configured ready event to wait for")
event: Event = getattr(cls.skill, cls.ready_event)
event.wait()

@classmethod
def tearDownClass(cls) -> None:
import shutil
Expand Down Expand Up @@ -168,41 +179,42 @@ def test_common_query(self):
for lang in self.common_query.keys():
for utt in self.common_query[lang]:
if isinstance(utt, dict):
data = list(utt.values())[0]
cqs_data = list(utt.values())[0]
utt = list(utt.keys())[0]
else:
data = dict()
cqs_data = dict()
utt = utt.lower()
message = Message('test_utterance',
{"utterance": utt, "lang": lang})
self.common_query_service.handle_question(message)
response = qa_response.call_args[0][0]
callback = qa_response.call_args[0][0]
self.assertIsInstance(response, Message)
self.assertTrue(response.data["phrase"] in utt)
self.assertEqual(response.data["skill_id"], self.skill.skill_id)
self.assertIn("callback_data", response.data.keys())
self.assertIsInstance(response.data["conf"], float)
self.assertIsInstance(response.data["answer"], str)

self.assertIsInstance(callback, Message)
self.assertEqual(callback.data['skill_id'], self.skill.skill_id)
self.assertEqual(callback.data['phrase'],
response.data['phrase'])
if not data:
response_msg = qa_response.call_args[0][0]
callback_msg = qa_response.call_args[0][0]
self.assertIsInstance(response_msg, Message)
self.assertTrue(response_msg.data["phrase"] in utt)
self.assertEqual(response_msg.data["skill_id"], self.skill.skill_id)
self.assertIn("callback_data", response_msg.data.keys())
self.assertIsInstance(response_msg.data["conf"], float)
self.assertIsInstance(response_msg.data["answer"], str)

self.assertIsInstance(callback_msg, Message)
self.assertEqual(callback_msg.data['skill_id'], self.skill.skill_id)
self.assertEqual(callback_msg.data['phrase'],
response_msg.data['phrase'])
if not cqs_data:
continue
if isinstance(data.get('callback'), dict):
self.assertEqual(callback.data['callback_data'],
data['callback'])
elif isinstance(data.get('callback'), list):
self.assertEqual(set(callback.data['callback_data'].keys()),
set(data.get('callback')))
if data.get('min_confidence'):
self.assertGreaterEqual(response.data['conf'],
data['min_confidence'])
if data.get('max_confidence'):
self.assertLessEqual(response.data['conf'],
data['max_confidence'])
if isinstance(cqs_data.get('callback'), dict):
self.assertEqual(callback_msg.data['callback_data'],
cqs_data['callback'])
elif isinstance(cqs_data.get('callback'), list):
# callback_data has `answer` but callback does not
self.assertEqual(set(callback_msg.data['callback_data'].keys()),
set(cqs_data.get('callback') + ['answer']))
if cqs_data.get('min_confidence'):
self.assertGreaterEqual(response_msg.data['conf'],
cqs_data['min_confidence'], utt)
if cqs_data.get('max_confidence'):
self.assertLessEqual(response_msg.data['conf'],
cqs_data['max_confidence'], utt)

def test_common_play(self):
# TODO
Expand Down
Loading