Skip to content

Commit

Permalink
unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Oct 14, 2024
1 parent 63e38e2 commit 6248292
Show file tree
Hide file tree
Showing 82 changed files with 292 additions and 508 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Run UnitTests
on:
pull_request:
branches:
- dev
paths-ignore:
- 'ovos_core/version.py'
- 'examples/**'
- '.github/**'
- '.gitignore'
- 'LICENSE'
- 'CHANGELOG.md'
- 'MANIFEST.in'
- 'readme.md'
- 'scripts/**'
push:
branches:
- master
paths-ignore:
- 'ovos_core/version.py'
- 'requirements/**'
- 'examples/**'
- '.github/**'
- '.gitignore'
- 'LICENSE'
- 'CHANGELOG.md'
- 'MANIFEST.in'
- 'readme.md'
- 'scripts/**'
workflow_dispatch:

jobs:
integration_tests:
strategy:
max-parallel: 3
matrix:
python-version: [3.9]
runs-on: ubuntu-latest
timeout-minutes: 35
steps:
- uses: actions/checkout@v2
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt install python3-dev swig libssl-dev portaudio19-dev libpulse-dev
python -m pip install build wheel
- name: Install test dependencies
run: |
pip install -r requirements/tests.txt
pip install ./test/unittests/common_query/ovos_tskill_fakewiki
- name: Install core repo
run: |
pip install -e .[mycroft,plugins]
- name: Run integration tests
run: |
pytest --cov-append --cov=ovos_core --cov-report xml test/integrationtests
- name: Upload coverage
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage/reports/
fail_ci_if_error: true
files: ./coverage.xml,!./cache
flags: integrationtests
name: codecov-integrationtests
verbose: true
71 changes: 71 additions & 0 deletions .github/workflows/mycroft_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Run UnitTests
on:
pull_request:
branches:
- dev
paths-ignore:
- 'ovos_core/version.py'
- 'examples/**'
- '.github/**'
- '.gitignore'
- 'LICENSE'
- 'CHANGELOG.md'
- 'MANIFEST.in'
- 'readme.md'
- 'scripts/**'
push:
branches:
- master
paths-ignore:
- 'ovos_core/version.py'
- 'requirements/**'
- 'examples/**'
- '.github/**'
- '.gitignore'
- 'LICENSE'
- 'CHANGELOG.md'
- 'MANIFEST.in'
- 'readme.md'
- 'scripts/**'
workflow_dispatch:

jobs:
mycroft_tests:
strategy:
max-parallel: 3
matrix:
python-version: [3.9]
runs-on: ubuntu-latest
timeout-minutes: 35
steps:
- uses: actions/checkout@v2
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt install python3-dev swig libssl-dev portaudio19-dev libpulse-dev
python -m pip install build wheel
- name: Install test dependencies
run: |
pip install -r requirements/tests.txt
- name: Install core repo
run: |
pip install -e .[mycroft,plugins]
- name: Run mycroft compat tests
run: |
pytest --cov=ovos_core --cov-report xml test/backwards_compat
- name: Upload coverage
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage/reports/
fail_ci_if_error: true
files: ./coverage.xml,!./cache
flags: mycrofttests
name: codecov-unittests
verbose: true
7 changes: 0 additions & 7 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,12 @@ jobs:
- name: Install test dependencies
run: |
pip install -r requirements/tests.txt
pip install ./test/unittests/common_query/ovos_tskill_fakewiki
- name: Install core repo
run: |
pip install -e .[mycroft,plugins]
- name: Run unittests
run: |
pytest --cov=ovos_core --cov-report xml test/unittests
# NOTE: additional pytest invocations should also add the --cov-append flag
# or they will overwrite previous invocations' coverage reports
# (for an example, see OVOS Skill Manager's workflow)
- name: Run integration tests
run: |
pytest --cov-append --cov=ovos_core --cov-report xml test/integrationtests
- name: Install padatious
run: |
sudo apt install libfann-dev
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@
from unittest import TestCase, skip
import mycroft.configuration
from os.path import dirname, isfile
from mycroft.configuration import LocalConf
from ovos_config import LocalConf


class TestConfiguration(TestCase):
def test_get(self):
d1 = {'a': 1, 'b': {'c': 1, 'd': 2}}
d2 = {'b': {'d': 'changed'}}
d = mycroft.configuration.Configuration.get([d1, d2])
self.assertEqual(d['a'], d1['a'])
self.assertEqual(d['b']['d'], d2['b']['d'])
self.assertEqual(d['b']['c'], d1['b']['c'])

@patch('ovos_backend_client.config.RemoteConfigManager')
@patch('ovos_backend_client.pairing.is_paired')
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_continuous_dialog(self):

self.assertEqual(self.bus.emitted_msgs[-2]["type"], "speak")
self.assertEqual(self.bus.emitted_msgs[-2]["data"]["meta"],
{'data': {}, 'dialog': 'thats all', 'skill': 'wiki.test'})
{'skill': 'wiki.test'})

# removal of context to disable "tell me more"
self.assertEqual(self.bus.emitted_msgs[-1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from ovos_utils.messagebus import FakeBus
from ovos_tskill_fakewiki import FakeWikiSkill
from mycroft.skills import CommonQuerySkill
from ovos_workshop.skills.common_query_skill import CommonQuerySkill


class TestSkill(unittest.TestCase):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import unittest
import pathlib
import json
import pathlib
import unittest

from mycroft.dialog import MustacheDialogRenderer, load_dialogs, get
from mycroft.util import resolve_resource_file
from mycroft.dialog import get
from ovos_utils.dialog import MustacheDialogRenderer, load_dialogs
from ovos_utils.file_utils import resolve_resource_file


# TODO - move to ovos-workshop
# TODO - move to ovos-utils
class DialogTest(unittest.TestCase):
def setUp(self):
self.stache = MustacheDialogRenderer()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from unittest import TestCase, mock

# TODO - move test to ovos-bus-client
from ovos_bus_client.message import Message
from mycroft.skills.audioservice import AudioService
from ovos_bus_client.apis.ocp import ClassicAudioServiceInterface as AudioService


class TestAudioServiceControls(TestCase):
Expand Down
12 changes: 11 additions & 1 deletion test/integrationtests/test_common_query_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

from ovos_bus_client.message import Message

from test.unittests.mocks import AnyCallable
from ovos_workshop.skills.common_query_skill import CommonQuerySkill

# TODO - move test to ovos-workshop

class AnyCallable:
"""Class matching any callable.
Useful for assert_called_with arguments.
"""
def __eq__(self, other):
return callable(other)



class TestCommonQuerySkill(TestCase):
def setUp(self):
self.skill = CQSTest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import unittest

from ovos_workshop.intents import IntentBuilder
from mycroft.skills.intent_service_interface import IntentServiceInterface
# TODO - move test to ovos-workshop
from ovos_workshop.intents import IntentBuilder, IntentServiceInterface


class MockEmitter:
Expand Down
5 changes: 3 additions & 2 deletions test/integrationtests/test_mycroft_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
from ovos_workshop.intents import IntentBuilder, open_intent_envelope
from ovos_workshop.skills.mycroft_skill import MycroftSkill
from ovos_workshop.skills.ovos import OVOSSkill
from test.util import base_config
from copy import deepcopy
from ovos_config import LocalConf, DEFAULT_CONFIG

# TODO - move test to ovos-workshop

BASE_CONF = base_config()
BASE_CONF = deepcopy(LocalConf(DEFAULT_CONFIG))


class MockEmitter(object):
Expand Down
51 changes: 3 additions & 48 deletions test/integrationtests/test_skill_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
import json
import unittest
from pathlib import Path
from time import time
from unittest.mock import Mock

# TODO - move test to ovos-workshop
from ovos_workshop.skills.mycroft_skill import MycroftSkill
from ovos_workshop.skill_launcher import SkillLoader
from ovos_utils import classproperty
from ovos_utils.messagebus import FakeBus
from ovos_utils.process_utils import RuntimeRequirements
from ovos_workshop.skill_launcher import SkillLoader
# TODO - move test to ovos-workshop
from ovos_workshop.skills.mycroft_skill import MycroftSkill

ONE_MINUTE = 60

Expand Down Expand Up @@ -95,40 +94,6 @@ class TestSkillLoader(unittest.TestCase):
for file_name in ('__init__.py', 'bar.py', '.foobar', 'bar.pyc'):
skill_directory.joinpath(file_name).touch()

def test_skill_already_loaded(self):
"""The loader should take to action for an already loaded skill."""
bus.msgs = []
loader = SkillLoader(bus, str(self.skill_directory))
loader.instance = Mock
loader.instance.reload_skill = True
loader.loaded = True
loader.last_loaded = time() + ONE_MINUTE

self.assertFalse(loader.reload_needed())

def test_skill_reloading_blocked(self):
"""The loader should skip reloads for skill that doesn't allow it."""
bus.msgs = []
loader = SkillLoader(bus, str(self.skill_directory))
loader.instance = Mock()
loader.instance.reload_skill = False
loader.active = True
loader.loaded = True

self.assertFalse(loader.reload_needed())

def test_skill_reloading_deactivated(self):
"""The loader should skip reloads for skill that aren't active."""
bus.msgs = []
loader = SkillLoader(bus, str(self.skill_directory))
loader.instance = Mock()
loader.name = "MySkill"
loader.instance.reload_skill = True
loader.active = False
loader.loaded = False

self.assertFalse(loader.reload_needed())

def test_skill_reload(self):
"""Test reloading a skill that was modified."""
bus.msgs = []
Expand Down Expand Up @@ -197,16 +162,6 @@ def _update_skill_instance(*args, **kwargs):
)
loader._create_skill_instance = real_create_skill_instance

def test_reload_modified(self):
loader = SkillLoader(bus, str(self.skill_directory))
bus.msgs = []
loader.last_modified = 0
loader.reload = Mock()

loader._handle_filechange(self.skill_directory)
loader.reload.assert_called_once_with()
self.assertNotEqual(loader.last_modified, 0)

def test_skill_load_blacklisted(self):
"""Skill should not be loaded if it is blacklisted"""
loader = SkillLoader(bus, str(self.skill_directory))
Expand Down
11 changes: 9 additions & 2 deletions test/integrationtests/util/test_audio_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@

from unittest import TestCase, mock

from test.util import Anything
from mycroft.util import (play_ogg, play_mp3, play_wav, play_audio_file)
from mycroft.util.file_utils import get_temp_path

class Anything:
"""Class matching any object.
Useful for assert_called_with arguments.
"""
def __eq__(self, other):
return True


test_config = {
'play_wav_cmdline': 'mock_wav %1',
Expand Down
Loading

0 comments on commit 6248292

Please sign in to comment.