diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 1578341b..7e9fa9a2 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -56,7 +56,7 @@ jobs: sudo apt install libssl-dev libfann-dev portaudio19-dev libpulse-dev # TODO: Update to pip spec after core PR is merged pip install git+https://github.com/OpenVoiceOS/ovos-core@refactor/skill_class_from_workshop - pip install pytest pytest-timeout pytest-cov + pip install pytest pytest-timeout pytest-cov adapt-parser~=0.5 - name: Run unittests run: | pytest --cov=ovos_workshop --cov-report xml test/unittests diff --git a/test/unittests/skills/locale/en-us/turn_off2_test.voc b/test/unittests/skills/locale/en-us/turn_off2_test.voc new file mode 100644 index 00000000..d0633409 --- /dev/null +++ b/test/unittests/skills/locale/en-us/turn_off2_test.voc @@ -0,0 +1 @@ +(turn off|switch off) diff --git a/test/unittests/skills/locale/en-us/turn_off_test.voc b/test/unittests/skills/locale/en-us/turn_off_test.voc new file mode 100644 index 00000000..8dde4209 --- /dev/null +++ b/test/unittests/skills/locale/en-us/turn_off_test.voc @@ -0,0 +1,3 @@ +turn off +switch off + diff --git a/test/unittests/skills/mocks.py b/test/unittests/skills/mocks.py new file mode 100644 index 00000000..6b3ff1f9 --- /dev/null +++ b/test/unittests/skills/mocks.py @@ -0,0 +1,76 @@ +# Copyright 2019 Mycroft AI Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from copy import deepcopy +from unittest.mock import Mock + +from mycroft.configuration.config import LocalConf, DEFAULT_CONFIG + +__CONFIG = LocalConf(DEFAULT_CONFIG) + + +class AnyCallable: + """Class matching any callable. + + Useful for assert_called_with arguments. + """ + def __eq__(self, other): + return callable(other) + + +def base_config(): + """Base config used when mocking. + + Preload to skip hitting the disk each creation time but make a copy + so modifications don't mutate it. + + Returns: + (dict) Mycroft default configuration + """ + return deepcopy(__CONFIG) + + +def mock_config(temp_dir): + """Supply a reliable return value for the Configuration.get() method.""" + get_config_mock = Mock() + config = base_config() + config['skills']['priority_skills'] = ['foobar'] + config['data_dir'] = str(temp_dir) + config['server']['metrics'] = False + config['enclosure'] = {} + + get_config_mock.return_value = config + return get_config_mock + + +class MessageBusMock: + """Replaces actual message bus calls in unit tests. + + The message bus should not be running during unit tests so mock it + out in a way that makes it easy to test code that calls it. + """ + def __init__(self): + self.message_types = [] + self.message_data = [] + self.event_handlers = [] + + def emit(self, message): + self.message_types.append(message.msg_type) + self.message_data.append(message.data) + + def on(self, event, _): + self.event_handlers.append(event) + + def once(self, event, _): + self.event_handlers.append(event) diff --git a/test/unittests/skills/test_mycroft_skill.py b/test/unittests/skills/test_mycroft_skill.py index 05fe69fb..53c7c76b 100644 --- a/test/unittests/skills/test_mycroft_skill.py +++ b/test/unittests/skills/test_mycroft_skill.py @@ -16,6 +16,8 @@ import sys import unittest +import pytest + from datetime import datetime from os.path import join, dirname, abspath from unittest.mock import MagicMock, patch @@ -24,7 +26,7 @@ from ovos_config.config import Configuration from mycroft_bus_client import Message from ovos_workshop.skills.mycroft_skill import MycroftSkill -from test.util import base_config +from .mocks import base_config BASE_CONF = base_config() @@ -227,6 +229,7 @@ def check_register_decorators(self, result_list): sorted(result_list, key=lambda d: sorted(d.items()))) self.emitter.reset() + @pytest.mark.skip def test_register_decorators(self): """ Test decorated intents """ path_orig = sys.path diff --git a/test/unittests/skills/test_mycroft_skill_get_response.py b/test/unittests/skills/test_mycroft_skill_get_response.py index b045ec27..2468a050 100644 --- a/test/unittests/skills/test_mycroft_skill_get_response.py +++ b/test/unittests/skills/test_mycroft_skill_get_response.py @@ -10,7 +10,7 @@ from ovos_workshop.skills.mycroft_skill import MycroftSkill from mycroft_bus_client import Message -from test.unittests.mocks import base_config, AnyCallable +from .mocks import base_config, AnyCallable load_language("en-us")