-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
enabled: False
config for plugins with validators (#35)
* Refactor plugin load logic to respect plugins disabled in config Adds unit test coverate for PHAL plugin load * Update default behavior for plugins without validators with unit test updates --------- Co-authored-by: Daniel McKnight <[email protected]>
- Loading branch information
1 parent
d9152b0
commit 28a2ca3
Showing
3 changed files
with
80 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import unittest | ||
from unittest.mock import patch, Mock | ||
|
||
from ovos_utils.fakebus import FakeBus | ||
|
||
_MOCK_CONFIG = { | ||
"admin": { | ||
"mock_admin_plugin": {}, | ||
"mock_admin_enabled": { | ||
"enabled": True | ||
}, | ||
"mock_admin_disabled": { | ||
"enabled": False | ||
} | ||
}, | ||
"mock_enabled_plugin": { | ||
"enabled": True | ||
}, | ||
"mock_disabled_plugin": { | ||
"enabled": False | ||
}, | ||
"mock_plugin": {} | ||
} | ||
|
||
|
||
class MockPlugin: | ||
def __init__(self, *args, **kwargs): | ||
pass | ||
|
||
|
||
class TestService(unittest.TestCase): | ||
def setUp(self): | ||
from ovos_PHAL.service import PHAL | ||
bus = FakeBus() | ||
self.service = PHAL(_MOCK_CONFIG, bus) | ||
|
||
@patch("ovos_PHAL.service.find_phal_plugins") | ||
def test_load_plugins(self, find_plugins): | ||
mock_plugins = {"mock_admin_plugin": Mock(), | ||
"mock_admin_enabled": Mock(), | ||
"mock_admin_disabled": Mock(), | ||
"mock_disabled_plugin": Mock(), | ||
"mock_plugin": MockPlugin, | ||
"mock_enabled_plugin": Mock()} | ||
|
||
find_plugins.return_value = mock_plugins | ||
|
||
# Test without validators | ||
self.service.load_plugins() | ||
self.assertEqual(set(self.service.drivers.keys()), | ||
{"mock_plugin", "mock_enabled_plugin"}) | ||
self.service.drivers = {} | ||
|
||
# Tests with passing validators | ||
mock_plugins["mock_plugin"] = Mock() | ||
mock_plugins["mock_plugin"].validator.validate = Mock(return_value=True) | ||
mock_plugins["mock_enabled_plugin"].validator.validate = Mock(return_value=True) | ||
mock_plugins["mock_disabled_plugin"].validator.validate = Mock(return_value=True) | ||
self.service.load_plugins() | ||
self.assertEqual(set(self.service.drivers.keys()), | ||
{"mock_plugin", "mock_enabled_plugin"}) | ||
self.service.drivers = {} | ||
|
||
# Tests with failing validators | ||
mock_plugins["mock_plugin"].validator.validate.return_value = False | ||
mock_plugins["mock_enabled_plugin"].validator.validate.return_value = False | ||
mock_plugins["mock_disabled_plugin"].validator.validate.return_value = False | ||
self.service.load_plugins() | ||
self.assertEqual(self.service.drivers, {}) |
This file was deleted.
Oops, something went wrong.