Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion ovos_utils/network_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ def is_connected_dns(host: Optional[str] = None, port: int = 53,
return is_connected_dns(cfg.get("dns_primary") or _DEFAULT_TEST_CONFIG['dns_primary']) or \
is_connected_dns(cfg.get("dns_secondary") or _DEFAULT_TEST_CONFIG['dns_secondary'])

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
# connect to the host -- tells us if the host is actually reachable
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(timeout)
s.connect((host, port))
return True
except OSError:
pass
finally:
s.close()
return False


Expand Down
47 changes: 33 additions & 14 deletions test/unittests/dialog/test_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,27 @@
import pathlib
import json

import pytest

from ovos_utils.dialog import MustacheDialogRenderer, load_dialogs, get_dialog

# ovos_utils.dialog is a deprecated shim; this module deliberately keeps
# exercising it for coverage, filtered per-module rather than dropped.
pytestmark = [
pytest.mark.filterwarnings(
"ignore:MustacheDialogRenderer is deprecated; use the OVOS-INTENT-2:DeprecationWarning"
),
pytest.mark.filterwarnings(
"ignore:get_dialog is deprecated; use the OVOS-INTENT-2:DeprecationWarning"
),
pytest.mark.filterwarnings(
"ignore:load_dialogs is deprecated; use 'ovos_spec_tools.LocaleResources':DeprecationWarning"
),
pytest.mark.filterwarnings(
"ignore:EventSchedulerInterface moved to ovos_bus_client:DeprecationWarning"
),
]


# TODO - move to ovos-workshop
class DialogTest(unittest.TestCase):
Expand All @@ -33,13 +51,15 @@ def test_general_dialog(self):
for file in template_path.iterdir():
if file.suffix == '.dialog':
self.stache.load_template_file(file.name, str(file.absolute()))
context = json.load(
file.with_suffix('.context.json').open(
'r', encoding='utf-8'))
with file.with_suffix('.context.json').open(
'r', encoding='utf-8') as f:
context = json.load(f)
with file.with_suffix('.result').open(
'r', encoding='utf-8') as f:
expected = f.read()
self.assertEqual(
self.stache.render(file.name, context),
file.with_suffix('.result').open('r',
encoding='utf-8').read())
expected)

def test_unknown_dialog(self):
""" Test for returned file name literals in case of unkown dialog """
Expand All @@ -55,13 +75,12 @@ def test_multiple_dialog(self):
for file in template_path.iterdir():
if file.suffix == '.dialog':
self.stache.load_template_file(file.name, str(file.absolute()))
context = json.load(
file.with_suffix('.context.json').open(
'r', encoding='utf-8'))
results = [
line.strip() for line in file.with_suffix('.result').open(
'r', encoding='utf-8')
]
with file.with_suffix('.context.json').open(
'r', encoding='utf-8') as f:
context = json.load(f)
with file.with_suffix('.result').open(
'r', encoding='utf-8') as fh:
results = [line.strip() for line in fh]
# Try all lines
for index, line in enumerate(results):
self.assertEqual(
Expand All @@ -82,8 +101,8 @@ def test_comment_dialog(self):
for f in template_path.iterdir():
if f.suffix == '.dialog':
self.stache.load_template_file(f.name, str(f.absolute()))
results = [line.strip()
for line in f.with_suffix('.result').open('r')]
with f.with_suffix('.result').open('r') as fh:
results = [line.strip() for line in fh]
# Try all lines
for index, line in enumerate(results):
self.assertEqual(self.stache.render(f.name, index=index),
Expand Down
8 changes: 8 additions & 0 deletions test/unittests/test_bracket_expansion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import unittest

import pytest

from ovos_utils.bracket_expansion import expand_template, expand_slots

# expand_template is a deprecated shim (use ovos_spec_tools.expand); this
# module deliberately keeps exercising it for coverage, filtered per-module.
pytestmark = pytest.mark.filterwarnings(
"ignore:expand_template is deprecated; import 'expand' from 'ovos_spec_tools':DeprecationWarning"
)


class TestTemplateExpansion(unittest.TestCase):

Expand Down
10 changes: 8 additions & 2 deletions test/unittests/test_device_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@
import sys
import types
import unittest
import warnings
from unittest import mock
from unittest.mock import Mock, MagicMock, patch

# distutils was removed in Python 3.12+; provide a minimal stub if missing
# distutils was removed in Python 3.12+; provide a minimal stub if missing.
# On older interpreters it still exists but is itself deprecated -- that's
# the stdlib's own noise, not ours to fix here, so it's suppressed locally.
try:
import distutils.spawn
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning,
message="The distutils package is deprecated")
import distutils.spawn
except ImportError:
distutils_stub = types.ModuleType("distutils")
spawn_stub = types.ModuleType("distutils.spawn")
Expand Down
17 changes: 17 additions & 0 deletions test/unittests/test_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@
import unittest
from unittest.mock import patch, MagicMock

import pytest

# ovos_utils.dialog is a deprecated shim (superseded by ovos_spec_tools'
# dialog renderer); this module deliberately keeps exercising it for
# coverage, filtered per-module rather than dropped.
pytestmark = [
pytest.mark.filterwarnings(
"ignore:MustacheDialogRenderer is deprecated; use the OVOS-INTENT-2:DeprecationWarning"
),
pytest.mark.filterwarnings(
"ignore:get_dialog is deprecated; use the OVOS-INTENT-2:DeprecationWarning"
),
pytest.mark.filterwarnings(
"ignore:load_dialogs is deprecated; use 'ovos_spec_tools.LocaleResources':DeprecationWarning"
),
]


class TestMustacheDialogRenderer(unittest.TestCase):
"""Tests for MustacheDialogRenderer class."""
Expand Down
3 changes: 3 additions & 0 deletions test/unittests/test_event_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import unittest
from unittest.mock import MagicMock, patch

import pytest

from ovos_bus_client.util.scheduler import EventScheduler
from ovos_utils.events import EventSchedulerInterface
from ovos_utils.fakebus import FakeBus
Expand Down Expand Up @@ -102,6 +104,7 @@ def test_send_event(self, mock_open, mock_dump, mock_load, mock_thread):
es.shutdown()


@pytest.mark.filterwarnings("ignore:EventSchedulerInterface moved to ovos_bus_client:DeprecationWarning")
class TestEventSchedulerInterface(unittest.TestCase):
def test_shutdown(self):
def f(message):
Expand Down
22 changes: 21 additions & 1 deletion test/unittests/test_events.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import inspect
import unittest
import datetime
import warnings

from os.path import join, dirname
from threading import Event
from time import time
from unittest.mock import Mock

import pytest

from ovos_utils.fakebus import FakeBus, FakeMessage as Message

# EventSchedulerInterface is a deprecated shim (moved to ovos_bus_client);
# these classes deliberately keep exercising it for coverage.
_ignore_event_scheduler_moved = pytest.mark.filterwarnings(
"ignore:EventSchedulerInterface moved to ovos_bus_client:DeprecationWarning"
)


class TestEvents(unittest.TestCase):
bus = FakeBus()
Expand Down Expand Up @@ -182,10 +191,20 @@ def test_event_container(self):
self.assertEqual(bus.ee.listeners(event_name), [])


@_ignore_event_scheduler_moved
class TestEventSchedulerInterface(unittest.TestCase):
from ovos_utils.events import EventSchedulerInterface
bus = FakeBus()
interface = EventSchedulerInterface(bus=bus, skill_id="test")
# class-body instantiation runs at collection/import time, before the
# pytest filterwarnings mark above applies to test items -- silence
# the deprecated-shim noise locally instead.
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
message="EventSchedulerInterface moved to ovos_bus_client",
category=DeprecationWarning,
)
interface = EventSchedulerInterface(bus=bus, skill_id="test")

def test_00_init(self):
from ovos_utils.events import EventContainer
Expand Down Expand Up @@ -513,6 +532,7 @@ def remove(self, item):
self.assertTrue(result)


@_ignore_event_scheduler_moved
class TestEventSchedulerInterfaceExtended(unittest.TestCase):
"""Additional tests for EventSchedulerInterface uncovered methods."""

Expand Down
9 changes: 9 additions & 0 deletions test/unittests/test_fakebus_intent_topic_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@
import unittest
from unittest.mock import patch

import pytest

from ovos_utils.fakebus import AsyncFakeBus, FakeBus, Message, INTENT_COMPAT_TWIN_KEY

# ovos_utils.fakebus.Message is a deprecated shim (use ovos_spec_tools.Message
# or ovos_bus_client.Message); this module deliberately keeps exercising it
# for coverage, filtered per-module.
pytestmark = pytest.mark.filterwarnings(
"ignore:ovos_utils.fakebus.Message is deprecated:DeprecationWarning"
)


def _run(coro):
return asyncio.run(coro)
Expand Down
9 changes: 9 additions & 0 deletions test/unittests/test_fakebus_namespace_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
import unittest
from unittest.mock import patch

import pytest

from ovos_utils.fakebus import AsyncFakeBus, FakeBus, Message

# ovos_utils.fakebus.Message is a deprecated shim (use ovos_spec_tools.Message
# or ovos_bus_client.Message); this module deliberately keeps exercising it
# for coverage, filtered per-module.
pytestmark = pytest.mark.filterwarnings(
"ignore:ovos_utils.fakebus.Message is deprecated:DeprecationWarning"
)


def _run(coro):
return asyncio.run(coro)
Expand Down
8 changes: 8 additions & 0 deletions test/unittests/test_lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
import unittest.mock
from unittest.mock import patch

import pytest


@pytest.mark.filterwarnings(
"ignore:standardize_lang_tag is deprecated; use 'standardize_lang' from 'ovos_spec_tools' instead:DeprecationWarning"
)
class TestStandardizeLangTag(unittest.TestCase):
"""Tests for standardize_lang_tag."""

Expand Down Expand Up @@ -61,6 +66,9 @@ def test_fallback_without_langcodes(self) -> None:
standardize_lang_tag("EN", macro=False), "en")


@pytest.mark.filterwarnings(
"ignore:get_language_dir is deprecated; use 'closest_lang' from 'ovos_spec_tools':DeprecationWarning"
)
class TestGetLanguageDir(unittest.TestCase):
"""Tests for get_language_dir."""

Expand Down
3 changes: 3 additions & 0 deletions test/unittests/test_network_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import unittest
from time import sleep

import pytest


class TestNetworkUtils(unittest.TestCase):
def test_get_network_tests_config(self):
Expand Down Expand Up @@ -34,6 +36,7 @@ def test_is_connected_http(self):
self.assertIsInstance(is_connected_http(), bool)
# TODO

@pytest.mark.filterwarnings("ignore:use is_connected_http or is_connected_dns:DeprecationWarning")
def test_is_connected(self):
from ovos_utils.network_utils import is_connected
self.assertIsInstance(is_connected(), bool)
Expand Down
Loading