Skip to content

Commit

Permalink
common_qa blacklist tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Jun 17, 2024
1 parent aa9b1c7 commit 76e983f
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
pip install ./test/end2end/skill-old-stop
pip install ./test/end2end/skill-fake-fm
pip install ./test/end2end/skill-fake-fm-legacy
pip install ./test/end2end/skill-ovos-fakewiki
pip install ./test/end2end/metadata-test-plugin
- name: Install core repo
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
pip install ./test/end2end/skill-old-stop
pip install ./test/end2end/skill-fake-fm
pip install ./test/end2end/skill-fake-fm-legacy
pip install ./test/end2end/skill-ovos-fakewiki
pip install ./test/end2end/metadata-test-plugin
- name: Install core repo
run: |
Expand Down
2 changes: 2 additions & 0 deletions test/end2end/minicroft.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from ovos_utils.process_utils import ProcessState
from ovos_workshop.skills.fallback import FallbackSkill

LOG.set_level("DEBUG")


class MiniCroft(SkillManager):
def __init__(self, skill_ids, *args, **kwargs):
Expand Down
91 changes: 91 additions & 0 deletions test/end2end/session/test_blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,94 @@ def wait_for_n_messages(n):
for idx, m in enumerate(messages):
self.assertEqual(m.msg_type, expected_messages[idx])


class TestCommonQuery(TestCase):

def setUp(self):
self.skill_id = "ovos-skill-fakewiki.openvoiceos"
self.core = get_minicroft(self.skill_id)
# self.core.intent_service.common_qa.common_query_skills = [self.skill_id]

def tearDown(self) -> None:
self.core.stop()

def test_common_qa(self):
SessionManager.sessions = {}
SessionManager.default_session = SessionManager.sessions["default"] = Session("default")
SessionManager.default_session.lang = "en-us"
SessionManager.default_session.pipeline = ["common_qa"]
messages = []

def new_msg(msg):
nonlocal messages
m = Message.deserialize(msg)
if m.msg_type in ["ovos.skills.settings_changed",
"ovos.common_play.status"]:
return # skip these, only happen in 1st run
messages.append(m)
print(len(messages), msg)

def wait_for_n_messages(n):
nonlocal messages
t = time.time()
while len(messages) < n:
sleep(0.1)
if time.time() - t > 10:
raise RuntimeError("did not get the number of expected messages under 10 seconds")

self.core.bus.on("message", new_msg)

sess = Session("123",
blacklisted_skills=[],
pipeline=["common_qa"])
utt = Message("recognizer_loop:utterance",
{"utterances": ["what is the speed of light"]},
{"session": sess.serialize()})
self.core.bus.emit(utt)

# confirm all expected messages are sent
expected_messages = [
"recognizer_loop:utterance",
"enclosure.mouth.think",
"question:query",
"question:query.response", # searching
"question:query.response", # response
"enclosure.mouth.reset",
"question:action",
"intent.service.skills.activate",
"intent.service.skills.activated",
f"{self.skill_id}.activate",
"enclosure.active_skill",
"speak", # answer
"enclosure.active_skill",
"speak", # callback
"mycroft.skill.handler.complete",
"ovos.utterance.handled"
]
wait_for_n_messages(len(expected_messages))

self.assertEqual(len(expected_messages), len(messages))

for idx, m in enumerate(messages):
self.assertEqual(m.msg_type, expected_messages[idx])

messages = []
sess.blacklisted_skills = [self.skill_id]
utt = Message("recognizer_loop:utterance",
{"utterances": ["invalid"]},
{"session": sess.serialize()})
self.core.bus.emit(utt)

# confirm intent failure
expected_messages = [
"recognizer_loop:utterance",
"mycroft.audio.play_sound",
"complete_intent_failure",
"ovos.utterance.handled"
]
wait_for_n_messages(len(expected_messages))

self.assertEqual(len(expected_messages), len(messages))

for idx, m in enumerate(messages):
self.assertEqual(m.msg_type, expected_messages[idx])
14 changes: 14 additions & 0 deletions test/end2end/skill-ovos-fakewiki/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from ovos_workshop.skills.common_query_skill import CommonQuerySkill, CQSMatchLevel


class UnWikiSkill(CommonQuerySkill):

# common query integration
def CQS_match_query_phrase(self, utt):
response = "42"
return (utt, CQSMatchLevel.EXACT, response,
{'query': utt, 'answer': response})

def CQS_action(self, phrase, data):
""" If selected show gui """
self.speak("selected")
23 changes: 23 additions & 0 deletions test/end2end/skill-ovos-fakewiki/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
from setuptools import setup

# skill_id=package_name:SkillClass
PLUGIN_ENTRY_POINT = 'ovos-skill-fakewiki.openvoiceos=ovos_skill_fakewiki:UnWikiSkill'

setup(
# this is the package name that goes on pip
name='ovos-skill-fakewiki',
version='0.0.1',
description='this is a OVOS test skill for the common query framework',
url='https://github.com/OpenVoiceOS/ovos-core',
author='JarbasAi',
author_email='jarbasai@mailfence.com',
license='Apache-2.0',
package_dir={"ovos_skill_fakewiki": ""},
package_data={'ovos_skill_fakewiki': ['locale/*']},
packages=['ovos_skill_fakewiki'],
include_package_data=True,
install_requires=["ovos-workshop"],
keywords='ovos skill plugin',
entry_points={'ovos.plugin.skill': PLUGIN_ENTRY_POINT}
)

0 comments on commit 76e983f

Please sign in to comment.