Add support for separate settings for test
The json can now include a "settings" entry which will replace the skill's self.settings for that particular test.
@@ -42,6 +42,7 @@ from pyee import EventEmitter
from mycroft.messagebus.message import Message
from mycroft.skills.core import create_skill_descriptor, load_skill, \
MycroftSkill, FallbackSkill
+from mycroft.skills.settings import SkillSettings
MainModule = '__init__'
@@ -179,6 +180,28 @@ class InterceptEmitter(object):
pass
+class TestSettings(SkillSettings):
+ """ SkillSettings instance without saving/loading capability.
+ """
+ def save_skill_settings(self, skill_settings):
+ pass
+
+ def _poll_skill_settings(self):
+ pass
+
+ def _load_settings_meta(self):
+ return None
+
+ def update(self, settings_meta):
+ pass
+
+ def load_skill_settings_from_file(self):
+ pass
+
+ def store(self, force=False):
+ pass
+
+
class MockSkillsLoader(object):
"""Load a skill and set up emitter
"""
@@ -249,6 +272,15 @@ class SkillTest(object):
test_case = json.load(f)
print('Test:', json.dumps(test_case, indent=4, sort_keys=False))
+ original_settings = None
+ if 'settings' in test_case:
+ original_settings = s.settings
+ s.settings = TestSettings('/tmp/', self.test_case_file)
+ for key in test_case['settings']:
+ s.settings[key] = test_case['settings'][key]
+ print(color.YELLOW, 'will run test with custom settings:',
+ '\n{}'.format(s.settings), color.RESET)
+
if 'responses' in test_case:
def get_response(dialog='', data=None, announcement='',
validator=None, on_fail=None, num_retries=-1):
@@ -340,6 +372,8 @@ class SkillTest(object):
print(color.FAIL + "Failure:", self.failure_msg + color.RESET)
return False
+ if original_settings:
+ s.settings = original_settings
return True
