Skip to content

Commit

Permalink
fix:cov
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Oct 15, 2024
1 parent 76b8f04 commit bdec136
Show file tree
Hide file tree
Showing 31 changed files with 21 additions and 1,313 deletions.
5 changes: 0 additions & 5 deletions ovos_workshop/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
from ovos_workshop.app import OVOSAbstractApplication
from ovos_workshop.decorators import *
from ovos_workshop.decorators.killable import killable_event, \
AbortEvent, AbortQuestion
from ovos_workshop.decorators.layers import IntentLayers
3 changes: 1 addition & 2 deletions ovos_workshop/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import yaml
from json_database import JsonStorageXDG

from ovos_workshop.skills.ovos import OVOSSkill
from ovos_backend_client.api import DeviceApi
from ovos_backend_client.pairing import is_paired, requires_backend
from ovos_backend_client.settings import RemoteSkillSettings, get_display_name
Expand All @@ -18,7 +17,7 @@
class SkillSettingsManager:
def __init__(self, skill):
self.download_timer: Optional[Timer] = None
self.skill: OVOSSkill = skill
self.skill = skill
self.api = DeviceApi()
self.remote_settings = \
RemoteSkillSettings(self.skill_id,
Expand Down
4 changes: 2 additions & 2 deletions ovos_workshop/skills/active.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ def bind(self, bus):
super(ActiveSkill, self).bind(bus)
if bus:
""" insert skill in active skill list on load """
self.make_active()
self.activate()

def handle_skill_deactivated(self, message=None):
"""
skill is always in active skill list, ie, converse is always called
"""
self.make_active()
self.activate()


6 changes: 3 additions & 3 deletions ovos_workshop/skills/auto_translatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ovos_utils.log import LOG
from ovos_workshop.resource_files import SkillResources
from ovos_workshop.skills.common_query_skill import CommonQuerySkill
from ovos_workshop.skills.fallback import FallbackSkillV2
from ovos_workshop.skills.fallback import FallbackSkill
from ovos_workshop.skills.ovos import OVOSSkill


Expand Down Expand Up @@ -311,7 +311,7 @@ def _handle_converse_request(self, message: Message):
super()._handle_converse_request(message)


class UniversalFallback(UniversalSkill, FallbackSkillV2):
class UniversalFallback(UniversalSkill, FallbackSkill):
"""
Fallback Skill that auto translates input/output from any language.
Expand Down Expand Up @@ -373,7 +373,7 @@ def register_fallback(self, handler, priority: int):
- `create_universal_fallback_handler` method for creating universal fallback handlers.
"""
handler = self.create_universal_fallback_handler(handler)
FallbackSkillV2.register_fallback(self, handler, priority)
FallbackSkill.register_fallback(self, handler, priority)


class UniversalCommonQuerySkill(UniversalSkill, CommonQuerySkill, ABC):
Expand Down
4 changes: 2 additions & 2 deletions test/unittests/skills/test_active.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from unittest.mock import Mock

from ovos_utils.messagebus import FakeBus
from ovos_workshop.skills.active import ActiveSkill
from ovos_workshop.skills.ovos import OVOSSkill
from ovos_workshop.skills.active import ActiveSkill


class ActiveSkillExample(ActiveSkill):
active = Mock()

def make_active(self):
def activate(self, *args):
self.active()
ActiveSkill.activate(self)

Expand Down
26 changes: 0 additions & 26 deletions test/unittests/skills/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@
from ovos_utils.messagebus import FakeBus


class TestBase(unittest.TestCase):
def test_is_classic_core(self):
from ovos_workshop.skills.base import is_classic_core
self.assertIsInstance(is_classic_core(), bool)

def test_simple_trace(self):
from ovos_workshop.skills.base import simple_trace
trace = ["line_1\n", " line_2 \n", " \n", "line_3 \n"]
self.assertEqual(simple_trace(trace), "Traceback:\nline_1\n line_2 \n")


class TestOVOSSkill(unittest.TestCase):
test_config_path = join(dirname(__file__), "temp_config")
os.environ["XDG_CONFIG_HOME"] = test_config_path
Expand Down Expand Up @@ -558,18 +547,3 @@ class GuiSkill(Mock):
"legacy": False}}
root_dir = join(dirname(__file__), "test_gui")

@patch("ovos_workshop.skills.ovos.GUIInterface.__init__")
def test_skill_gui(self, interface_init):
from ovos_bus_client.apis.gui import GUIInterface
from ovos_workshop.skills.base import SkillGUI

# Old skill with `ui` directory in root
old_skill = self.LegacySkill()
old_gui = SkillGUI(old_skill)
self.assertEqual(old_gui.skill, old_skill)
self.assertIsInstance(old_gui, GUIInterface)
interface_init.assert_called_once_with(
old_gui, skill_id=old_skill.skill_id, bus=old_skill.bus,
config=old_skill.config_core['gui'],
ui_directories={"qt5": join(old_skill.root_dir, "ui")})

159 changes: 8 additions & 151 deletions test/unittests/skills/test_fallback_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,12 @@
from ovos_utils.messagebus import FakeBus
from ovos_bus_client.message import Message
from ovos_workshop.decorators import fallback_handler
from ovos_workshop.skills.fallback import FallbackSkillV1, FallbackSkillV2, \
FallbackSkill
from ovos_workshop.skills.fallback import FallbackSkill


class SimpleFallback(FallbackSkillV1):
"""Simple fallback skill used for test."""
def initialize(self):
self.register_fallback(self.fallback_handler, 42)

def fallback_handler(self, _):
pass


class V2FallbackSkill(FallbackSkillV2):
class V2FallbackSkill(FallbackSkill):
def __init__(self):
FallbackSkillV2.__init__(self, FakeBus(), "fallback_v2")
super().__init__(FakeBus(), "fallback_v2")

@fallback_handler
def handle_fallback(self, message):
Expand All @@ -32,160 +22,27 @@ def high_prio_fallback(self, message):
pass


class TestFallbackSkill(TestCase):
# TODO: Test `__new__` logic
pass

def test_class_inheritance(self):
from ovos_workshop.skills.ovos import OVOSSkill
fallback = FallbackSkill("test")
self.assertIsInstance(fallback, OVOSSkill)
self.assertIsInstance(fallback, FallbackSkillV1)
self.assertIsInstance(fallback, FallbackSkillV2)
self.assertIsInstance(fallback, FallbackSkill)


class TestFallbackSkillV1(TestCase):
@staticmethod
def setup_fallback(fb_class):
fb_skill = fb_class()
fb_skill.bind(FakeBus())
fb_skill.initialize()
return fb_skill

def test_inheritance(self):
from ovos_workshop.skills.ovos import OVOSSkill
fallback = FallbackSkillV1("test")
self.assertIsInstance(fallback, OVOSSkill)
self.assertIsInstance(fallback, FallbackSkillV1)
self.assertIsInstance(fallback, FallbackSkillV2)
self.assertIsInstance(fallback, FallbackSkill)

def test_make_intent_failure_handler(self):
# TODO
pass

def test_report_timing(self):
# TODO
pass

def test__register_fallback(self):
# TODO
pass

def test_register_fallback(self):
# TODO
pass

def test_remove_registered_handler(self):
# TODO
pass

@patch("ovos_workshop.skills.fallback.FallbackSkillV1."
"_remove_registered_handler")
def test_remove_fallback(self, remove_handler):
def wrapper(handler):
def wrapped():
if handler():
return True
return False
return wrapped

def _mock_1():
pass

def _mock_2():
pass

FallbackSkillV1.wrapper_map.append((_mock_1, wrapper(_mock_1)))
self.assertEqual(len(FallbackSkillV1.wrapper_map), 1)

FallbackSkillV1.wrapper_map.append((_mock_2, wrapper(_mock_2)))
self.assertEqual(len(FallbackSkillV1.wrapper_map), 2)

# Successful remove existing wrapper
remove_handler.return_value = True
self.assertTrue(FallbackSkillV1.remove_fallback(_mock_1))
self.assertEqual(len(FallbackSkillV1.wrapper_map), 1)
self.assertFalse(FallbackSkillV1.remove_fallback(_mock_1))
self.assertEqual(len(FallbackSkillV1.wrapper_map), 1)

# Failed remove existing wrapper
remove_handler.return_value = False
self.assertFalse(FallbackSkillV1.remove_fallback(
FallbackSkillV1.wrapper_map[0][1]))
self.assertEqual(FallbackSkillV1.wrapper_map, [])

def test_remove_instance_handlers(self):
# TODO
pass

def test_default_shutdown(self):
# TODO
pass

def test_register_decorated(self):
# TODO
pass

def test_life_cycle(self):
"""
Test startup and shutdown of a fallback skill.
Ensure that an added handler is removed as part of default shutdown.
"""
self.assertEqual(len(FallbackSkillV1.fallback_handlers), 0)
fb_skill = self.setup_fallback(SimpleFallback)
self.assertEqual(len(FallbackSkillV1.fallback_handlers), 1)
self.assertEqual(FallbackSkillV1.wrapper_map[0][0],
fb_skill.fallback_handler)
self.assertEqual(len(FallbackSkillV1.wrapper_map), 1)

fb_skill.default_shutdown()
self.assertEqual(len(FallbackSkillV1.fallback_handlers), 0)
self.assertEqual(len(FallbackSkillV1.wrapper_map), 0)

def test_manual_removal(self):
"""
Test that the call to remove_fallback() removes the handler
"""
self.assertEqual(len(FallbackSkillV1.fallback_handlers), 0)

# Create skill adding a single handler
fb_skill = self.setup_fallback(SimpleFallback)
self.assertEqual(len(FallbackSkillV1.fallback_handlers), 1)

self.assertTrue(fb_skill.remove_fallback(fb_skill.fallback_handler))
# Both internal trackers of handlers should be cleared now
self.assertEqual(len(FallbackSkillV1.fallback_handlers), 0)
self.assertEqual(len(FallbackSkillV1.wrapper_map), 0)

# Removing after it's already been removed should fail
self.assertFalse(fb_skill.remove_fallback(fb_skill.fallback_handler))


class TestFallbackSkillV2(TestCase):
fallback_skill = FallbackSkillV2(FakeBus(), "test_fallback_v2")
fallback_skill = FallbackSkill(FakeBus(), "test_fallback_v2")

def test_class_inheritance(self):
from ovos_workshop.skills.ovos import OVOSSkill
self.assertIsInstance(self.fallback_skill, OVOSSkill)
self.assertIsInstance(self.fallback_skill, FallbackSkillV1)
self.assertIsInstance(self.fallback_skill, FallbackSkillV2)
self.assertIsInstance(self.fallback_skill, FallbackSkill)

def test_00_init(self):
from ovos_workshop.skills.ovos import OVOSSkill
self.assertIsInstance(self.fallback_skill, FallbackSkillV2)
self.assertIsInstance(self.fallback_skill, FallbackSkill)
self.assertIsInstance(self.fallback_skill, OVOSSkill)

def test_priority(self):
FallbackSkillV2.fallback_config = {}
FallbackSkill.fallback_config = {}

# No config or handlers
self.assertEqual(self.fallback_skill.priority, 101)
# Config override
FallbackSkillV2.fallback_config = \
FallbackSkill.fallback_config = \
{"fallback_priorities": {"test_fallback_v2": 10}}
self.assertEqual(self.fallback_skill.priority, 10,
self.fallback_skill.fallback_config)
Expand All @@ -195,11 +52,11 @@ def test_priority(self):
# Minimum handler
self.assertEqual(fallback_skill.priority, 10)
# Config override
FallbackSkillV2.fallback_config['fallback_priorities'][
FallbackSkill.fallback_config['fallback_priorities'][
fallback_skill.skill_id] = 80
self.assertEqual(fallback_skill.priority, 80)

FallbackSkillV2.fallback_config = {}
FallbackSkill.fallback_config = {}

def test_can_answer(self):
self.assertFalse(self.fallback_skill.can_answer([""], "en-us"))
Expand Down
Empty file.
Empty file.
Empty file.

This file was deleted.

This file was deleted.

Loading

0 comments on commit bdec136

Please sign in to comment.