Skip to content

Commit

Permalink
Merge pull request #280 from OpenVoiceOS/release-0.5.4a1
Browse files Browse the repository at this point in the history
Release 0.5.4a1
  • Loading branch information
JarbasAl authored Oct 24, 2024
2 parents 0cdde42 + 50d115d commit c4d0d26
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 53 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Changelog

## [0.5.3a1](https://github.com/OpenVoiceOS/ovos-plugin-manager/tree/0.5.3a1) (2024-10-23)
## [0.5.4a1](https://github.com/OpenVoiceOS/ovos-plugin-manager/tree/0.5.4a1) (2024-10-24)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-plugin-manager/compare/0.5.2...0.5.3a1)
[Full Changelog](https://github.com/OpenVoiceOS/ovos-plugin-manager/compare/0.5.3...0.5.4a1)

**Merged pull requests:**

- fix:deprecate G2P [\#277](https://github.com/OpenVoiceOS/ovos-plugin-manager/pull/277) ([JarbasAl](https://github.com/JarbasAl))
- fix:missing import [\#279](https://github.com/OpenVoiceOS/ovos-plugin-manager/pull/279) ([JarbasAl](https://github.com/JarbasAl))



Expand Down
24 changes: 10 additions & 14 deletions ovos_plugin_manager/microphone.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from ovos_plugin_manager.utils import PluginTypes
from ovos_config import Configuration
from ovos_utils.log import LOG, deprecated

from ovos_plugin_manager.templates.microphone import Microphone
from ovos_utils.log import LOG
from ovos_plugin_manager.utils import PluginTypes


def find_microphone_plugins() -> dict:
Expand All @@ -22,6 +24,7 @@ def load_microphone_plugin(module_name: str) -> type(Microphone):
return load_plugin(module_name, PluginTypes.MIC)


@deprecated("get_microphone_config is deprecated, use Configuration() directly", "1.0.0")
def get_microphone_config(config=None):
"""
Get relevant configuration for factory methods
Expand All @@ -45,7 +48,7 @@ def get_class(config=None):
"module": <engine_name>
}
"""
config = get_microphone_config(config)
config = config or Configuration().get("listener", {}).get("microphone", {})
microphone_module = config.get("module")
return load_microphone_plugin(microphone_module)

Expand All @@ -60,19 +63,12 @@ def create(cls, config=None):
"module": <engine_name>
}
"""
config = config or Configuration()
if "microphone" in config:
config = config["microphone"]
microphone_config = get_microphone_config(config)
microphone_module = microphone_config.get('module')
config = config or Configuration().get("listener", {}).get("microphone", {})
microphone_module = config.get('module')
microphone_config = config.get(microphone_module, {})
fallback = microphone_config.get("fallback_module")
try:
clazz = OVOSMicrophoneFactory.get_class(microphone_config)
# Note that configuration is expanded for this class of plugins
# since they are dataclasses and don't have the same init signature
# as other plugin types
microphone_config.pop('lang')
microphone_config.pop('module')
clazz = OVOSMicrophoneFactory.get_class(config)
if fallback:
microphone_config.pop('fallback_module')
microphone = clazz(**microphone_config)
Expand Down
4 changes: 2 additions & 2 deletions ovos_plugin_manager/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# START_VERSION_BLOCK
VERSION_MAJOR = 0
VERSION_MINOR = 5
VERSION_BUILD = 3
VERSION_ALPHA = 0
VERSION_BUILD = 4
VERSION_ALPHA = 1
# END_VERSION_BLOCK
39 changes: 5 additions & 34 deletions test/unittests/test_microphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,6 @@ def test_load_plugin(self, load_plugin):
load_microphone_plugin("test_mod")
load_plugin.assert_called_once_with("test_mod", self.PLUGIN_TYPE)

@patch("ovos_plugin_manager.utils.config.get_plugin_config")
def test_get_config(self, get_config):
from ovos_plugin_manager.microphone import get_microphone_config
get_microphone_config(self.TEST_CONFIG)
get_config.assert_called_once_with(self.TEST_CONFIG,
self.CONFIG_SECTION)


class TestMicrophoneFactory(unittest.TestCase):
def test_create_microphone(self):
Expand All @@ -154,11 +147,9 @@ def _copy_args(*args):
mock_get_class = Mock(side_effect=_copy_args)
OVOSMicrophoneFactory.get_class = mock_get_class

OVOSMicrophoneFactory.create(config=_TEST_CONFIG)
OVOSMicrophoneFactory.create(config=_TEST_CONFIG['microphone'])
mock_get_class.assert_called_once()
self.assertEqual(call_args, ({**_TEST_CONFIG['microphone']['dummy'],
**{"module": "dummy",
"lang": "en-US"}},))
self.assertEqual(call_args, ({**_TEST_CONFIG['microphone']},))
mock_class.assert_called_once_with(**_TEST_CONFIG['microphone']['dummy'])
OVOSMicrophoneFactory.get_class = real_get_class

Expand All @@ -171,7 +162,7 @@ def test_create_microphone_fallback(self):

def _copy_args(*args):
nonlocal call_args, bad_call_args
if args[0]["module"] == "bad":
if args[0].get("module", "") == "bad":
bad_call_args = deepcopy(args)
return None
call_args = deepcopy(args)
Expand All @@ -180,7 +171,7 @@ def _copy_args(*args):
mock_get_class = Mock(side_effect=_copy_args)
OVOSMicrophoneFactory.get_class = mock_get_class

OVOSMicrophoneFactory.create(config=_FALLBACK_CONFIG)
OVOSMicrophoneFactory.create(config=_FALLBACK_CONFIG['microphone'])
mock_get_class.assert_called()
self.assertEqual(call_args[0]["module"], 'dummy')
self.assertEqual(bad_call_args[0]["module"], 'bad')
Expand All @@ -193,27 +184,7 @@ def test_get_class(self, load_plugin):
load_plugin.return_value = mock
from ovos_plugin_manager.microphone import OVOSMicrophoneFactory
# Test valid module
module = OVOSMicrophoneFactory.get_class(_TEST_CONFIG)
module = OVOSMicrophoneFactory.get_class(_TEST_CONFIG['microphone'])
load_plugin.assert_called_once_with("dummy",
PluginTypes.MIC)
self.assertEqual(mock, module)

def test_get_microphone_config(self):
from ovos_plugin_manager.microphone import get_microphone_config
config = copy(_TEST_CONFIG)
dummy_config = get_microphone_config(config)
self.assertEqual(dummy_config, {**_TEST_CONFIG['microphone']['dummy'],
**{'module': 'dummy',
'lang': 'en-US'}})
config = copy(_TEST_CONFIG)
config['microphone']['module'] = 'ovos-microphone-plugin-alsa'
alsa_config = get_microphone_config(config)
self.assertEqual(alsa_config,
{**_TEST_CONFIG['microphone']
['ovos-microphone-plugin-alsa'],
**{'module': 'ovos-microphone-plugin-alsa',
'lang': 'en-US'}})
config = copy(_TEST_CONFIG)
config['microphone']['module'] = 'fake'
fake_config = get_microphone_config(config)
self.assertEqual(fake_config, {'module': 'fake', 'lang': 'en-US'})

0 comments on commit c4d0d26

Please sign in to comment.