Skip to content

Commit

Permalink
unittests/message_routing
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Oct 19, 2023
1 parent 3d64590 commit 26017fc
Show file tree
Hide file tree
Showing 46 changed files with 203 additions and 24 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ jobs:
run: |
pip install -r requirements/tests.txt
pip install ./test/unittests/common_query/ovos_tskill_fakewiki
pip install ./test/end2end/session/skill-ovos-hello-world
pip install ./test/end2end/session/skill-ovos-schedule
pip install ./test/end2end/session/skill-ovos-fallback-unknown
pip install ./test/end2end/session/skill-ovos-fallback-unknownv1
pip install ./test/end2end/session/skill-converse_test
pip install ./test/end2end/skill-ovos-hello-world
pip install ./test/end2end/skill-ovos-schedule
pip install ./test/end2end/skill-ovos-fallback-unknown
pip install ./test/end2end/skill-ovos-fallback-unknownv1
pip install ./test/end2end/skill-converse_test
- name: Generate coverage report
run: |
pytest --cov=ovos_core --cov-report xml test/unittests
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ jobs:
run: |
pip install -r requirements/tests.txt
pip install ./test/unittests/common_query/ovos_tskill_fakewiki
pip install ./test/end2end/session/skill-ovos-hello-world
pip install ./test/end2end/session/skill-ovos-fallback-unknown
pip install ./test/end2end/session/skill-ovos-fallback-unknownv1
pip install ./test/end2end/session/skill-converse_test
pip install ./test/end2end/session/skill-ovos-schedule
pip install ./test/end2end/skill-ovos-hello-world
pip install ./test/end2end/skill-ovos-fallback-unknown
pip install ./test/end2end/skill-ovos-fallback-unknownv1
pip install ./test/end2end/skill-converse_test
pip install ./test/end2end/skill-ovos-schedule
pip install git+https://github.com/OpenVoiceOS/ovos-utils@troubleshoot
- name: Run unittests
run: |
pytest --cov=ovos_core --cov-report xml test/unittests
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ padacioso~=0.2, >=0.2.1a8
adapt-parser>=1.0.0, <2.0.0

ovos-bus-client<0.1.0, >=0.0.6a10
ovos-utils==0.0.36a9
ovos-utils<0.1.0, >=0.0.36a10
ovos-plugin-manager<0.1.0, >=0.0.24a9
ovos-config~=0.0,>=0.0.11a13
ovos-lingua-franca>=0.4.7
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
83 changes: 83 additions & 0 deletions test/end2end/routing/test_sched.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import time
from time import sleep
from unittest import TestCase

from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager, Session
from ..minicroft import get_minicroft


class TestSched(TestCase):

def setUp(self):
self.skill_id = "skill-ovos-schedule.openvoiceos"
self.core = get_minicroft(self.skill_id)

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

messages = []

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

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)

utt = Message("recognizer_loop:utterance",
{"utterances": ["schedule event"]},
{"source": "A", "destination": "B"})
self.core.bus.emit(utt)

# confirm all expected messages are sent
expected_messages = [
"recognizer_loop:utterance", # no session
"intent.service.skills.activated", # default session injected
f"{self.skill_id}.activate",
f"{self.skill_id}:ScheduleIntent",
"mycroft.skill.handler.start",
"enclosure.active_skill",
"speak",
"mycroft.scheduler.schedule_event",
"mycroft.skill.handler.complete",
"ovos.session.update_default",
# event triggering after 3 seconds
"skill-ovos-schedule.openvoiceos:my_event",
"enclosure.active_skill",
"speak"
]
wait_for_n_messages(len(expected_messages))

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

mtypes = [m.msg_type for m in messages]
for m in expected_messages:
self.assertTrue(m in mtypes)

# verify that source an destination are kept until intent trigger
for m in messages[:3]:
self.assertEqual(m.context["source"], "A")
self.assertEqual(m.context["destination"], "B")

# verify that source and destination are swapped after intent trigger
self.assertEqual(messages[3].msg_type, f"{self.skill_id}:ScheduleIntent")
for m in messages[3:]:
self.assertEqual(m.context["source"], "B")
self.assertEqual(m.context["destination"], "A")

def tearDown(self) -> None:
self.core.stop()
85 changes: 85 additions & 0 deletions test/end2end/routing/test_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import time
from time import sleep
from unittest import TestCase

from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager, Session
from ..minicroft import get_minicroft


class TestRouting(TestCase):

def setUp(self):
self.skill_id = "skill-ovos-hello-world.openvoiceos"
self.core = get_minicroft(self.skill_id)

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

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

messages = []

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

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)

utt = Message("recognizer_loop:utterance",
{"utterances": ["hello world"]},
{"source": "A", "destination": "B"})
self.core.bus.emit(utt)

# confirm all expected messages are sent
expected_messages = [
"recognizer_loop:utterance", # no session
"intent.service.skills.activated", # default session injected
f"{self.skill_id}.activate",
f"{self.skill_id}:HelloWorldIntent",
"mycroft.skill.handler.start",
"enclosure.active_skill",
"speak",
"mycroft.skill.handler.complete",
"ovos.session.update_default"
]
wait_for_n_messages(len(expected_messages))

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

mtypes = [m.msg_type for m in messages]
for m in expected_messages:
self.assertTrue(m in mtypes)

# verify that "session" is injected
# (missing in utterance message) and kept in all messages
for m in messages[1:]:
self.assertEqual(m.context["session"]["session_id"], "default")

# verify that source an destination are kept until intent trigger
for m in messages[:3]:
self.assertEqual(m.context["source"], "A")
self.assertEqual(m.context["destination"], "B")

# verify that source and destination are swapped after intent trigger
self.assertEqual(messages[3].msg_type, f"{self.skill_id}:HelloWorldIntent")
for m in messages[3:]:
self.assertEqual(m.context["source"], "B")
self.assertEqual(m.context["destination"], "A")


2 changes: 1 addition & 1 deletion test/end2end/session/test_complete_failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager, Session
from .minicroft import get_minicroft
from ..minicroft import get_minicroft


class TestSessions(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion test/end2end/session/test_converse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager, Session
from .minicroft import get_minicroft
from ..minicroft import get_minicroft


class TestSessions(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion test/end2end/session/test_fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager, Session
from .minicroft import get_minicroft
from ..minicroft import get_minicroft


class TestFallback(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion test/end2end/session/test_fallback_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager, Session
from .minicroft import get_minicroft
from ..minicroft import get_minicroft


class TestFallback(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion test/end2end/session/test_get_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager, Session
from .minicroft import get_minicroft
from ..minicroft import get_minicroft


class TestSessions(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion test/end2end/session/test_sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager, Session
from .minicroft import get_minicroft
from ..minicroft import get_minicroft


class TestSessions(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion test/end2end/session/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager, Session
from .minicroft import get_minicroft
from ..minicroft import get_minicroft


class TestSessions(TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
from os import path, walk

from setuptools import setup
from os import getenv, path, walk


def find_resource_files():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ovos_workshop.skills.fallback import FallbackSkill
from ovos_workshop.decorators import fallback_handler
from ovos_workshop.skills.fallback import FallbackSkill


class UnknownSkill(FallbackSkill):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
from setuptools import setup
from os import walk, path

from setuptools import setup

URL = "https://github.com/OpenVoiceOS/skill-ovos-fallback-unknown"
SKILL_CLAZZ = "UnknownSkill" # needs to match __init__.py class name
PYPI_NAME = "ovos-skill-fallback-unknown" # pip install PYPI_NAME
Expand All @@ -10,6 +11,8 @@
SKILL_AUTHOR, SKILL_NAME = URL.split(".com/")[-1].split("/")
SKILL_PKG = SKILL_NAME.lower().replace('-', '_')
PLUGIN_ENTRY_POINT = f'{SKILL_NAME.lower()}.{SKILL_AUTHOR.lower()}={SKILL_PKG}:{SKILL_CLAZZ}'


# skill_id=package_name:SkillClass


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ovos_workshop.skills.fallback import FallbackSkillV1
from ovos_workshop.decorators import fallback_handler
from ovos_workshop.skills.fallback import FallbackSkillV1


# explicitly use class with compat for older cores
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
from setuptools import setup
from os import walk, path

from setuptools import setup

URL = "https://github.com/OpenVoiceOS/skill-ovos-fallback-unknownv1"
SKILL_CLAZZ = "UnknownSkill" # needs to match __init__.py class name
PYPI_NAME = "ovos-skill-fallback-unknown-v1" # pip install PYPI_NAME
Expand All @@ -10,6 +11,8 @@
SKILL_AUTHOR, SKILL_NAME = URL.split(".com/")[-1].split("/")
SKILL_PKG = SKILL_NAME.lower().replace('-', '_')
PLUGIN_ENTRY_POINT = f'{SKILL_NAME.lower()}.{SKILL_AUTHOR.lower()}={SKILL_PKG}:{SKILL_CLAZZ}'


# skill_id=package_name:SkillClass


Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#!/usr/bin/env python3
from setuptools import setup
from os import walk, path

from setuptools import setup

URL = "https://github.com/OpenVoiceOS/skill-ovos-hello-world"
SKILL_CLAZZ = "HelloWorldSkill" # needs to match __init__.py class name

# below derived from github url to ensure standard skill_id
SKILL_AUTHOR, SKILL_NAME = URL.split(".com/")[-1].split("/")
SKILL_PKG = SKILL_NAME.lower().replace('-', '_')
PLUGIN_ENTRY_POINT = f'{SKILL_NAME.lower()}.{SKILL_AUTHOR.lower()}={SKILL_PKG}:{SKILL_CLAZZ}'


# skill_id=package_name:SkillClass


Expand Down
File renamed without changes.

0 comments on commit 26017fc

Please sign in to comment.