Skip to content

Commit

Permalink
Skill Compatibility (#478)
Browse files Browse the repository at this point in the history
* Extend OVOSSkill to troubleshoot missing attributes and compat.

* Refactor compatibility methods
Add unit tests for expected skill methods

---------

Co-authored-by: Daniel McKnight <daniel@neon.ai>
  • Loading branch information
NeonDaniel and NeonDaniel authored Oct 10, 2023
1 parent ca23b2b commit 54058fc
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 15 deletions.
75 changes: 66 additions & 9 deletions neon_utils/skills/neon_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@
from ovos_utils.skills import get_non_properties
from ovos_utils.xdg_utils import xdg_cache_home
from ovos_utils.skills.settings import save_settings, get_local_settings
from ovos_utils.log import deprecated
from ovos_utils.log import deprecated, log_deprecation
from neon_utils.location_utils import to_system_time
from neon_utils.logger import LOG
from neon_utils.message_utils import dig_for_message, resolve_message, get_message_user
from neon_utils.cache_utils import LRUCache
from neon_utils.file_utils import resolve_neon_resource_file
from neon_utils.user_utils import get_user_prefs
from ovos_workshop.skills.base import BaseSkill

try:
from neon_utils.mq_utils import send_mq_request
except ImportError:
Expand Down Expand Up @@ -105,6 +106,22 @@ def initialize(self):
self.schedule_event(self._write_cache_on_disk, CACHE_TIME_OFFSET,
name="neon.load_cache_on_disk")

@property
def settings_path(self):
# TODO: Deprecate backwards-compat. wrapper after ovos-workshop 0.0.13
try:
return super().settings_path
except AttributeError:
return super()._settings_path

@property
def resources(self):
# TODO: Deprecate backwards-compat. wrapper after ovos-workshop 0.0.13
try:
return super().resources
except AttributeError:
return super()._resources

@property
# @deprecated("Call `dateutil.tz.gettz` directly", "2.0.0")
def sys_tz(self):
Expand Down Expand Up @@ -523,14 +540,6 @@ def location(self):
from neon_utils.configuration_utils import get_mycroft_compatible_location
return get_mycroft_compatible_location(get_user_prefs()["location"])

@property
def settings_path(self):
# TODO: Deprecate backwards-compat. wrapper after ovos-workshop 0.0.13
try:
return super().settings_path
except AttributeError:
return super()._settings_path

def _init_settings(self):
"""
Extends the default method to handle settingsmeta defaults locally
Expand Down Expand Up @@ -835,3 +844,51 @@ def converse(message):
LOG.warning("Timed out waiting for user response")
self.converse = default_converse
return converse.response

# renamed in base class for naming consistency
# refactored to use new resource utils
def translate(self, text: str, data: Optional[dict] = None):
"""
Deprecated method for translating a dialog file.
use self._resources.render_dialog(text, data) instead
"""
log_deprecation("Use `resources.render_dialog`", "2.0.0")
return self._resources.render_dialog(text, data)

# renamed in base class for naming consistency
# refactored to use new resource utils
def translate_namedvalues(self, name: str, delim: str = ','):
"""
Deprecated method for translating a name/value file.
use self._resources.load_named_value_filetext, data) instead
"""
log_deprecation("Use `resources.load_named_value_file`", "2.0.0")
return self._resources.load_named_value_file(name, delim)

# renamed in base class for naming consistency
# refactored to use new resource utils
def translate_list(self, list_name: str, data: Optional[dict] = None):
"""
Deprecated method for translating a list.
use delf._resources.load_list_file(text, data) instead
"""
log_deprecation("Use `resources.load_list_file`", "2.0.0")
return self._resources.load_list_file(list_name, data)

# renamed in base class for naming consistency
# refactored to use new resource utils
def translate_template(self, template_name: str,
data: Optional[dict] = None):
"""
Deprecated method for translating a template file
use delf._resources.template_file(text, data) instead
"""
log_deprecation("Use `resources.template_file`", "2.0.0")
return self._resources.load_template_file(template_name, data)

def init_dialog(self, root_directory: Optional[str] = None):
"""
DEPRECATED: use load_dialog_files instead
"""
log_deprecation("Use `load_dialog_files`", "2.0.0")
self.load_dialog_files(root_directory)
39 changes: 33 additions & 6 deletions tests/neon_skill_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,36 +95,36 @@ class SkillObjectTests(unittest.TestCase):

def test_common_message_skill_init(self):
skill = create_skill(TestCMS)
self.assertIsInstance(skill, MycroftSkill)
# self.assertIsInstance(skill, MycroftSkill)
self.assertIsInstance(skill, NeonSkill)
self.assertIsInstance(skill, CommonMessageSkill)
self.assertEqual(skill.name, "Test Common Message Skill")

def test_common_play_skill_init(self):
skill = create_skill(TestCPS)
self.assertIsInstance(skill, MycroftSkill)
# self.assertIsInstance(skill, MycroftSkill)
self.assertIsInstance(skill, NeonSkill)
self.assertIsInstance(skill, CommonPlaySkill)
self.assertEqual(skill.name, "Test Common Play Skill")

def test_common_query_skill_init(self):
skill = create_skill(TestCQS)
self.assertIsInstance(skill, MycroftSkill)
# self.assertIsInstance(skill, MycroftSkill)
self.assertIsInstance(skill, NeonSkill)
self.assertIsInstance(skill, CommonQuerySkill)
self.assertEqual(skill.name, "Test Common Query Skill")

def test_fallback_skill_init(self):
skill = create_skill(TestFBS)
self.assertIsInstance(skill, MycroftSkill)
# self.assertIsInstance(skill, MycroftSkill)
self.assertIsInstance(skill, NeonSkill)
self.assertIsInstance(skill, NeonFallbackSkill)
# self.assertIsInstance(skill, FallbackSkill)
self.assertEqual(skill.name, "Test Fallback Skill")

def test_neon_skill_init(self):
skill = create_skill(TestNeonSkill)
self.assertIsInstance(skill, MycroftSkill)
# self.assertIsInstance(skill, MycroftSkill)
self.assertIsInstance(skill, NeonSkill)
self.assertEqual(skill.name, "Test Neon Skill")

Expand All @@ -149,9 +149,36 @@ def test_neon_skill_init(self):
self.assertIsInstance(skill.preference_skill(), dict)
self.assertEqual(skill.settings, skill.preference_skill())
self.assertIsInstance(skill.file_system.path, str)
# self.assertIsNotNone(skill.settings_meta)
# self.assertEqual(skill.file_system.path, skill.settings_write_path)
# self.assertNotEqual(os.path.basename(skill.file_system.path),
# skill.name)
expected_methods = ['init_dialog', 'make_active', 'translate',
'translate_namedvalues', 'translate_list',
'translate_template', 'bind',
'handle_settings_change', 'detach',
'get_intro_message', 'converse', 'get_response',
'ask_yesno', 'ask_selection', 'voc_match',
'report_metric', 'send_email',
'register_resting_screen', 'find_resource',
'add_event', 'remove_event', 'register_intent',
'register_intent_file', 'register_entity_file',
'handle_enable_intent', 'handle_disable_intent',
'disable_intent', 'enable_intent', 'set_context',
'remove_context', 'handle_set_cross_context',
'handle_remove_cross_context',
'set_cross_skill_context',
'remove_cross_skill_context', 'register_vocabulary',
'register_regex', 'speak', 'speak_dialog',
'load_dialog_files', 'load_data_files',
'load_vocab_files', 'load_regex_files', 'stop',
'shutdown', 'default_shutdown', 'schedule_event',
'schedule_repeating_event',
'update_scheduled_event', 'cancel_scheduled_event',
'get_scheduled_event_status',
'cancel_all_repeating_events']
for method in expected_methods:
self.assertTrue(hasattr(skill, method), method)

def test_patched_mycroft_skill_init(self):
skill = create_skill(TestPatchedSkill)
Expand All @@ -163,7 +190,7 @@ def test_patched_mycroft_skill_init(self):

def test_instructor_skill_init(self):
skill = create_skill(TestInstructorSkill)
self.assertIsInstance(skill, MycroftSkill)
# self.assertIsInstance(skill, MycroftSkill)
self.assertEqual(skill.name, "Test Instructor Skill")


Expand Down

0 comments on commit 54058fc

Please sign in to comment.