Skip to content

Commit

Permalink
Fix message context handling in __handle_stop (#44)
Browse files Browse the repository at this point in the history
* Fix message context handling in `__handle_stop`

* Add unit test for `BaseSkill.stop`
  • Loading branch information
NeonDaniel authored Jan 19, 2023
1 parent 8c38b57 commit 6842ac9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ovos_workshop/skills/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1652,8 +1652,8 @@ def __handle_stop(self, message):
"""Handler for the "mycroft.stop" signal. Runs the user defined
`stop()` method.
"""
self.bus.emit(message.forward(self.skill_id + ".stop",
context={"skill_id": self.skill_id}))
message.context['skill_id'] = self.skill_id
self.bus.emit(message.forward(self.skill_id + ".stop"))
try:
if self.stop():
self.bus.emit(message.reply("mycroft.stop.handled",
Expand Down
17 changes: 17 additions & 0 deletions test/unittests/test_skill.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import json
import unittest
from unittest.mock import Mock

from mycroft_bus_client import Message

from ovos_utils.fingerprinting import is_ovos
from ovos_workshop.skills.ovos import OVOSSkill
Expand Down Expand Up @@ -83,5 +86,19 @@ def test_registered_events(self):
for event in default_ovos:
self.assertTrue(event in registered_events)

def test_stop(self):
skill = self.skill.instance
handle_stop = Mock()
real_stop = skill.stop
skill.stop = Mock()
self.bus.once(f"{self.skill.skill_id}.stop", handle_stop)
self.bus.emit(Message("mycroft.stop"))
handle_stop.assert_called_once()
self.assertEqual(handle_stop.call_args[0][0].context['skill_id'],
skill.skill_id)
skill.stop.assert_called_once()

skill.stop = real_stop

def tearDown(self) -> None:
self.skill.unload()

0 comments on commit 6842ac9

Please sign in to comment.