Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test coverage for SkillApi #145

Merged
merged 3 commits into from
May 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions test/unittests/test_skills.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@
from os import environ
from os.path import isdir, join, dirname, basename
from unittest.mock import patch

from ovos_utils.messagebus import FakeBus, Message
from ovos_utils.skills.locations import get_skill_directories
from ovos_utils.skills.locations import get_default_skills_directory
from ovos_utils.skills.locations import get_installed_skill_ids
from ovos_utils.skills.locations import get_plugin_skills

try:
import ovos_config
except ImportError:
ovos_config = None


def _api_method_1(message: Message) -> str:
return message.serialize()


def _api_method_2(**kwargs) -> int:
return len(kwargs)


class TestSkills(unittest.TestCase):
def test_get_non_properties(self):
from ovos_utils.skills import get_non_properties
Expand Down Expand Up @@ -164,3 +175,20 @@ def test_get_plugin_skills(self):
for s in ids:
self.assertIsInstance(s, str)
self.assertEqual(len(dirs), len(ids))


class TestSkillApi(unittest.TestCase):
bus = FakeBus()

def test_skill_api_init(self):
from ovos_utils.skills.api import SkillApi

test_api = SkillApi({"serialize": _api_method_1,
"get_length": _api_method_2})
test_api.connect_bus(self.bus)
self.assertEqual(test_api.bus, self.bus)
self.assertEqual(SkillApi.bus, self.bus)
self.assertIsNotNone(test_api.serialize)
self.assertIsNotNone(test_api.get_length)

# TODO: Test SkillApi.get