From 369d8aa8303e959e255f0834710c974777a0146f Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Wed, 11 Oct 2023 15:35:42 -0700 Subject: [PATCH 01/12] Add test for #173 --- .github/workflows/unit_tests.yml | 5 ++++- requirements/test.txt | 5 +++++ test/integration/test_plugin_init.py | 13 +++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 requirements/test.txt create mode 100644 test/integration/test_plugin_init.py diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 472b5daf..33553cef 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -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 @@ -64,3 +64,6 @@ jobs: env: CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} uses: codecov/codecov-action@v2 + - name: Run integration tests + run: | + pytest test/integration \ No newline at end of file diff --git a/requirements/test.txt b/requirements/test.txt new file mode 100644 index 00000000..d8f52ad9 --- /dev/null +++ b/requirements/test.txt @@ -0,0 +1,5 @@ +pytest +pytest-timeout +pytest-cov +neon-lang-plugin-libretranslate~=0.2 +ovos-tts-plugin-espeakng@git+https://github.com/oppenvoiceos/ovos-tts-plugin-espeakng@ENHANCEMENT_expose-config \ No newline at end of file diff --git a/test/integration/test_plugin_init.py b/test/integration/test_plugin_init.py new file mode 100644 index 00000000..5ad1afa7 --- /dev/null +++ b/test/integration/test_plugin_init.py @@ -0,0 +1,13 @@ +import unittest +from unittest.mock import patch + + +class TestPluginInit(unittest.TestCase): + @patch("ovos_utils.log.LOG") + def test_init_logging(self, log): + from ovos_plugin_manager.tts import load_tts_plugin + plugin = load_tts_plugin("ovos-tts-plugin-espeakng") + log.reset_mock() + tts = plugin() + log.debug.assert_any_call(f"Amplitude: None") + log.debug.assert_any_call(tts.config) From f3bf7b05e996a6db4f6bdb8ea8c5444ba0cc4791 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Wed, 11 Oct 2023 15:37:48 -0700 Subject: [PATCH 02/12] Fix typo in test dependencies --- requirements/test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/test.txt b/requirements/test.txt index d8f52ad9..68e1fe26 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -2,4 +2,4 @@ pytest pytest-timeout pytest-cov neon-lang-plugin-libretranslate~=0.2 -ovos-tts-plugin-espeakng@git+https://github.com/oppenvoiceos/ovos-tts-plugin-espeakng@ENHANCEMENT_expose-config \ No newline at end of file +ovos-tts-plugin-espeakng@git+https://github.com/openvoiceos/ovos-tts-plugin-espeakng@ENHANCEMENT_expose-config \ No newline at end of file From a776150d6a0be4a7bab52c3d6e9ebfec79c46fb6 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 12 Oct 2023 11:38:07 -0700 Subject: [PATCH 03/12] Add test case for "normal" log init and expected log outputs --- test/integration/test_plugin_init.py | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/integration/test_plugin_init.py b/test/integration/test_plugin_init.py index 5ad1afa7..fe11fc3d 100644 --- a/test/integration/test_plugin_init.py +++ b/test/integration/test_plugin_init.py @@ -1,4 +1,7 @@ import unittest + +from os.path import join, dirname, isdir, isfile +from shutil import rmtree from unittest.mock import patch @@ -11,3 +14,33 @@ def test_init_logging(self, log): tts = plugin() log.debug.assert_any_call(f"Amplitude: None") log.debug.assert_any_call(tts.config) + + @patch("mycroft.Configuration") + def test_log_output(self, config): + from ovos_utils.log import LOG + from ovos_plugin_manager.tts import load_tts_plugin + + # Init log config + test_log_dir = join(dirname(__file__), "logs") + test_log_level = "DEBUG" + + # Mock config for `mycroft` module init + config.return_vaule = { + "log_level": test_log_level, + "logs": { + "path": test_log_dir + } + } + LOG.init({"path": test_log_dir, "level": test_log_level}) + + plugin = load_tts_plugin("ovos-tts-plugin-espeakng") + tts = plugin() + self.assertTrue(isdir(test_log_dir)) + self.assertTrue(isfile(join(test_log_dir, "ovos.log"))) + with open(join(test_log_dir, "ovos.log"), 'r') as f: + logs = f.read() + self.assertIn("Amplitude: ", logs) + self.assertIn(f"{tts.config}", logs) + + # Cleanup + rmtree(test_log_dir) \ No newline at end of file From d424b5c069142b48a538544187471d38c618841b Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 12 Oct 2023 11:43:36 -0700 Subject: [PATCH 04/12] Add ovos-core installation for integration tests --- .github/workflows/unit_tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 33553cef..c563e4da 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -64,6 +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 \ No newline at end of file From c584d19d63d7d5c32b604245787774ecbf1e3e25 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 12 Oct 2023 11:47:04 -0700 Subject: [PATCH 05/12] Add more test cases to troubleshoot GHA failures --- test/integration/test_plugin_init.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/integration/test_plugin_init.py b/test/integration/test_plugin_init.py index fe11fc3d..9cbb4bfb 100644 --- a/test/integration/test_plugin_init.py +++ b/test/integration/test_plugin_init.py @@ -35,6 +35,8 @@ def test_log_output(self, config): plugin = load_tts_plugin("ovos-tts-plugin-espeakng") tts = plugin() + self.assertEqual(LOG.base_path, test_log_dir) + self.assertEqual(LOG.level, test_log_level) self.assertTrue(isdir(test_log_dir)) self.assertTrue(isfile(join(test_log_dir, "ovos.log"))) with open(join(test_log_dir, "ovos.log"), 'r') as f: From 6ba6f4af1d8745799417cc86b4d46b1fe441a1c0 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 12 Oct 2023 13:02:36 -0700 Subject: [PATCH 06/12] Spec full log config to troubleshoot test failure --- test/integration/test_plugin_init.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/integration/test_plugin_init.py b/test/integration/test_plugin_init.py index 9cbb4bfb..cb607560 100644 --- a/test/integration/test_plugin_init.py +++ b/test/integration/test_plugin_init.py @@ -28,7 +28,10 @@ def test_log_output(self, config): config.return_vaule = { "log_level": test_log_level, "logs": { - "path": test_log_dir + "path": test_log_dir, + "max_bytes": 50000000, + "backup_count": 1, + "diagnostic": False } } LOG.init({"path": test_log_dir, "level": test_log_level}) From 964e1116bb688de09214412f11d78b236bc881a4 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 12 Oct 2023 13:08:21 -0700 Subject: [PATCH 07/12] Override default logging to troubleshoot test failures --- test/integration/test_plugin_init.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/integration/test_plugin_init.py b/test/integration/test_plugin_init.py index cb607560..4f2ba73a 100644 --- a/test/integration/test_plugin_init.py +++ b/test/integration/test_plugin_init.py @@ -1,9 +1,13 @@ 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_NAME"] = "test" +environ["OVOS_DEFAULT_LOG_LEVEL"] = "DEBUG" + class TestPluginInit(unittest.TestCase): @patch("ovos_utils.log.LOG") @@ -37,10 +41,13 @@ def test_log_output(self, config): LOG.init({"path": test_log_dir, "level": test_log_level}) 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) + tts = plugin() - self.assertEqual(LOG.base_path, test_log_dir) - self.assertEqual(LOG.level, test_log_level) - self.assertTrue(isdir(test_log_dir)) + self.assertEqual(LOG.base_path, test_log_dir, LOG.base_path) + self.assertEqual(LOG.level, test_log_level, LOG.level) + self.assertTrue(isdir(test_log_dir), test_log_dir) self.assertTrue(isfile(join(test_log_dir, "ovos.log"))) with open(join(test_log_dir, "ovos.log"), 'r') as f: logs = f.read() @@ -48,4 +55,4 @@ def test_log_output(self, config): self.assertIn(f"{tts.config}", logs) # Cleanup - rmtree(test_log_dir) \ No newline at end of file + rmtree(test_log_dir) From c7b23b796a91ade946ceb11dbf1c3b118dbcbfe8 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 12 Oct 2023 13:47:15 -0700 Subject: [PATCH 08/12] Add test case to troubleshoot GHA failures --- test/integration/test_plugin_init.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test/integration/test_plugin_init.py b/test/integration/test_plugin_init.py index 4f2ba73a..a2676793 100644 --- a/test/integration/test_plugin_init.py +++ b/test/integration/test_plugin_init.py @@ -3,7 +3,7 @@ from os import environ from os.path import join, dirname, isdir, isfile from shutil import rmtree -from unittest.mock import patch +from unittest.mock import patch, Mock environ["OVOS_DEFAULT_LOG_NAME"] = "test" environ["OVOS_DEFAULT_LOG_LEVEL"] = "DEBUG" @@ -19,6 +19,18 @@ def test_init_logging(self, log): log.debug.assert_any_call(f"Amplitude: None") log.debug.assert_any_call(tts.config) + def test_log_method_called(self): + from ovos_utils.log import LOG + from ovos_plugin_manager.tts import load_tts_plugin + real_debug = LOG.debug + LOG.debug = Mock() + plugin = load_tts_plugin("ovos-tts-plugin-espeakng") + tts = plugin() + LOG.debug.assert_any_call(f"Amplitude: None") + LOG.debug.assert_any_call(tts.config) + + LOG.debug = real_debug + @patch("mycroft.Configuration") def test_log_output(self, config): from ovos_utils.log import LOG @@ -27,6 +39,7 @@ def test_log_output(self, config): # Init log config test_log_dir = join(dirname(__file__), "logs") test_log_level = "DEBUG" + environ["OVOS_DEFAULT_LOG_NAME"] = "test" # Mock config for `mycroft` module init config.return_vaule = { @@ -45,11 +58,12 @@ def test_log_output(self, config): self.assertEqual(LOG.level, test_log_level, LOG.level) tts = plugin() + self.assertEqual(LOG.base_path, test_log_dir, LOG.base_path) self.assertEqual(LOG.level, test_log_level, LOG.level) self.assertTrue(isdir(test_log_dir), test_log_dir) - self.assertTrue(isfile(join(test_log_dir, "ovos.log"))) - with open(join(test_log_dir, "ovos.log"), 'r') as f: + 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) From 80188230961c6c20bdb0f245a5c30cd794691ba2 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 12 Oct 2023 13:53:08 -0700 Subject: [PATCH 09/12] Add log to troubleshoot GHA failures --- test/integration/test_plugin_init.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/test_plugin_init.py b/test/integration/test_plugin_init.py index a2676793..49db330f 100644 --- a/test/integration/test_plugin_init.py +++ b/test/integration/test_plugin_init.py @@ -26,6 +26,7 @@ def test_log_method_called(self): LOG.debug = Mock() plugin = load_tts_plugin("ovos-tts-plugin-espeakng") tts = plugin() + LOG.info(LOG.debug.call_args_list) LOG.debug.assert_any_call(f"Amplitude: None") LOG.debug.assert_any_call(tts.config) From e8030f4b85a5727565b4d7305221e0b64431ebe1 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 12 Oct 2023 14:03:18 -0700 Subject: [PATCH 10/12] Test failures are because the plugin module keeps a reference to the old `LOG` instance --- test/integration/test_plugin_init.py | 100 ++++++++++++++------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/test/integration/test_plugin_init.py b/test/integration/test_plugin_init.py index 49db330f..9559a212 100644 --- a/test/integration/test_plugin_init.py +++ b/test/integration/test_plugin_init.py @@ -1,4 +1,6 @@ import unittest +import importlib +import ovos_plugin_manager.tts from os import environ from os.path import join, dirname, isdir, isfile @@ -10,64 +12,68 @@ class TestPluginInit(unittest.TestCase): - @patch("ovos_utils.log.LOG") - def test_init_logging(self, log): - from ovos_plugin_manager.tts import load_tts_plugin - plugin = load_tts_plugin("ovos-tts-plugin-espeakng") - log.reset_mock() - tts = plugin() - log.debug.assert_any_call(f"Amplitude: None") - log.debug.assert_any_call(tts.config) + # @patch("ovos_utils.log.LOG") + # def test_init_logging(self, log): + # from ovos_plugin_manager.tts import load_tts_plugin + # plugin = load_tts_plugin("ovos-tts-plugin-espeakng") + # log.reset_mock() + # tts = plugin() + # log.debug.assert_any_call(f"Amplitude: None") + # log.debug.assert_any_call(tts.config) + # tts.shutdown() def test_log_method_called(self): from ovos_utils.log import LOG from ovos_plugin_manager.tts import load_tts_plugin real_debug = LOG.debug LOG.debug = Mock() + plugin = load_tts_plugin("ovos-tts-plugin-espeakng") tts = plugin() LOG.info(LOG.debug.call_args_list) LOG.debug.assert_any_call(f"Amplitude: None") LOG.debug.assert_any_call(tts.config) + tts.shutdown() LOG.debug = real_debug - @patch("mycroft.Configuration") - def test_log_output(self, config): - from ovos_utils.log import LOG - from ovos_plugin_manager.tts import load_tts_plugin - - # Init log config - test_log_dir = join(dirname(__file__), "logs") - test_log_level = "DEBUG" - environ["OVOS_DEFAULT_LOG_NAME"] = "test" - - # 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 - } - } - LOG.init({"path": test_log_dir, "level": test_log_level}) - - 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) - - tts = plugin() - - self.assertEqual(LOG.base_path, test_log_dir, LOG.base_path) - self.assertEqual(LOG.level, test_log_level, LOG.level) - 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 - rmtree(test_log_dir) + # @patch("mycroft.Configuration") + # def test_log_output(self, config): + # from ovos_utils.log import LOG + # from ovos_plugin_manager.tts import load_tts_plugin + # + # # Init log config + # test_log_dir = join(dirname(__file__), "logs") + # test_log_level = "DEBUG" + # environ["OVOS_DEFAULT_LOG_NAME"] = "test" + # + # # 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 + # } + # } + # LOG.init({"path": test_log_dir, "level": test_log_level}) + # + # 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) + # + # tts = plugin() + # + # self.assertEqual(LOG.base_path, test_log_dir, LOG.base_path) + # self.assertEqual(LOG.level, test_log_level, LOG.level) + # 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) From 9f7d57f97000f601395c6d2eb762bc50b7c8d444 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 12 Oct 2023 14:06:22 -0700 Subject: [PATCH 11/12] More testing --- test/integration/test_plugin_init.py | 96 ++++++++++++++-------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/test/integration/test_plugin_init.py b/test/integration/test_plugin_init.py index 9559a212..eb53a9f1 100644 --- a/test/integration/test_plugin_init.py +++ b/test/integration/test_plugin_init.py @@ -22,58 +22,58 @@ class TestPluginInit(unittest.TestCase): # log.debug.assert_any_call(tts.config) # tts.shutdown() - def test_log_method_called(self): + # def test_log_method_called(self): + # from ovos_utils.log import LOG + # from ovos_plugin_manager.tts import load_tts_plugin + # real_debug = LOG.debug + # LOG.debug = Mock() + # + # plugin = load_tts_plugin("ovos-tts-plugin-espeakng") + # tts = plugin() + # LOG.info(LOG.debug.call_args_list) + # LOG.debug.assert_any_call(f"Amplitude: None") + # LOG.debug.assert_any_call(tts.config) + # tts.shutdown() + # + # LOG.debug = real_debug + + @patch("mycroft.Configuration") + def test_log_output(self, config): from ovos_utils.log import LOG from ovos_plugin_manager.tts import load_tts_plugin - real_debug = LOG.debug - LOG.debug = Mock() + + # Init log config + test_log_dir = join(dirname(__file__), "logs") + test_log_level = "DEBUG" + environ["OVOS_DEFAULT_LOG_NAME"] = "test" + + # 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 + } + } + LOG.init({"path": test_log_dir, "level": test_log_level}) 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) + tts = plugin() - LOG.info(LOG.debug.call_args_list) - LOG.debug.assert_any_call(f"Amplitude: None") - LOG.debug.assert_any_call(tts.config) - tts.shutdown() - LOG.debug = real_debug + self.assertEqual(LOG.base_path, test_log_dir, LOG.base_path) + self.assertEqual(LOG.level, test_log_level, LOG.level) + 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) - # @patch("mycroft.Configuration") - # def test_log_output(self, config): - # from ovos_utils.log import LOG - # from ovos_plugin_manager.tts import load_tts_plugin - # - # # Init log config - # test_log_dir = join(dirname(__file__), "logs") - # test_log_level = "DEBUG" - # environ["OVOS_DEFAULT_LOG_NAME"] = "test" - # - # # 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 - # } - # } - # LOG.init({"path": test_log_dir, "level": test_log_level}) - # - # 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) - # - # tts = plugin() - # - # self.assertEqual(LOG.base_path, test_log_dir, LOG.base_path) - # self.assertEqual(LOG.level, test_log_level, LOG.level) - # 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) + # Cleanup + tts.shutdown() + rmtree(test_log_dir) From 865ceba4c680cd101cd61bccde9e88592fbe51db Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 12 Oct 2023 14:15:52 -0700 Subject: [PATCH 12/12] Fix test failures --- test/integration/test_plugin_init.py | 43 +++++++--------------------- 1 file changed, 10 insertions(+), 33 deletions(-) diff --git a/test/integration/test_plugin_init.py b/test/integration/test_plugin_init.py index eb53a9f1..b2cd80d9 100644 --- a/test/integration/test_plugin_init.py +++ b/test/integration/test_plugin_init.py @@ -1,51 +1,23 @@ import unittest -import importlib -import ovos_plugin_manager.tts from os import environ from os.path import join, dirname, isdir, isfile from shutil import rmtree -from unittest.mock import patch, Mock +from unittest.mock import patch -environ["OVOS_DEFAULT_LOG_NAME"] = "test" environ["OVOS_DEFAULT_LOG_LEVEL"] = "DEBUG" class TestPluginInit(unittest.TestCase): - # @patch("ovos_utils.log.LOG") - # def test_init_logging(self, log): - # from ovos_plugin_manager.tts import load_tts_plugin - # plugin = load_tts_plugin("ovos-tts-plugin-espeakng") - # log.reset_mock() - # tts = plugin() - # log.debug.assert_any_call(f"Amplitude: None") - # log.debug.assert_any_call(tts.config) - # tts.shutdown() - - # def test_log_method_called(self): - # from ovos_utils.log import LOG - # from ovos_plugin_manager.tts import load_tts_plugin - # real_debug = LOG.debug - # LOG.debug = Mock() - # - # plugin = load_tts_plugin("ovos-tts-plugin-espeakng") - # tts = plugin() - # LOG.info(LOG.debug.call_args_list) - # LOG.debug.assert_any_call(f"Amplitude: None") - # LOG.debug.assert_any_call(tts.config) - # tts.shutdown() - # - # LOG.debug = real_debug - @patch("mycroft.Configuration") def test_log_output(self, config): - from ovos_utils.log import LOG - from ovos_plugin_manager.tts import load_tts_plugin - # Init log config test_log_dir = join(dirname(__file__), "logs") test_log_level = "DEBUG" - environ["OVOS_DEFAULT_LOG_NAME"] = "test" + 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 = { @@ -57,16 +29,21 @@ def test_log_output(self, config): "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: