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 logging tests #186

Draft
wants to merge 12 commits into
base: dev
Choose a base branch
from
8 changes: 7 additions & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
pip install .
- name: Install test dependencies
run: |
pip install pytest pytest-timeout pytest-cov neon-lang-plugin-libretranslate
pip install -r requirements/test.txt
- name: Run unittests
run: |
pytest --cov=ovos_plugin_manager --cov-report xml test/unittests
Expand All @@ -64,3 +64,9 @@ jobs:
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
uses: codecov/codecov-action@v2
- name: Install ovos-core for integration testing
run: |
pip install ovos-core
- name: Run integration tests
run: |
pytest test/integration
5 changes: 5 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pytest
pytest-timeout
pytest-cov
neon-lang-plugin-libretranslate~=0.2
ovos-tts-plugin-espeakng@git+https://github.com/openvoiceos/ovos-tts-plugin-espeakng@ENHANCEMENT_expose-config
56 changes: 56 additions & 0 deletions test/integration/test_plugin_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import unittest

from os import environ
from os.path import join, dirname, isdir, isfile
from shutil import rmtree
from unittest.mock import patch

environ["OVOS_DEFAULT_LOG_LEVEL"] = "DEBUG"


class TestPluginInit(unittest.TestCase):
@patch("mycroft.Configuration")
def test_log_output(self, config):
# Init log config
test_log_dir = join(dirname(__file__), "logs")
test_log_level = "DEBUG"
test_log_name = "test"

from ovos_utils.log import LOG
from ovos_plugin_manager.tts import load_tts_plugin

# Mock config for `mycroft` module init
config.return_vaule = {
"log_level": test_log_level,
"logs": {
"path": test_log_dir,
"max_bytes": 50000000,
"backup_count": 1,
"diagnostic": False
}
}

# This is basically what `init_service_logger` does but with test config
LOG.init({"path": test_log_dir, "level": test_log_level})
LOG.name = test_log_name

plugin = load_tts_plugin("ovos-tts-plugin-espeakng")
self.assertEqual(LOG.base_path, test_log_dir, LOG.base_path)
self.assertEqual(LOG.level, test_log_level, LOG.level)
self.assertEqual(LOG.name, test_log_name, LOG.name)

tts = plugin()

self.assertEqual(LOG.base_path, test_log_dir, LOG.base_path)
self.assertEqual(LOG.level, test_log_level, LOG.level)
self.assertEqual(LOG.name, test_log_name, LOG.name)
self.assertTrue(isdir(test_log_dir), test_log_dir)
self.assertTrue(isfile(join(test_log_dir, "test.log")))
with open(join(test_log_dir, "test.log"), 'r') as f:
logs = f.read()
self.assertIn("Amplitude: ", logs)
self.assertIn(f"{tts.config}", logs)

# Cleanup
tts.shutdown()
rmtree(test_log_dir)