Remove more test requirements (#7574)
* No longer require pyunify during tests * No longer require cast during tests * No longer required dependency for tests * No longer require pymochad for tests * Astral is a core dependency * Avoid having to install datadog dependency during tests * CMUS test doesn't test anything * Frontier Silicon doesn't test anything * No longer require mutagen * Update requirements_test_all.txt * Remove stale comment
This commit is contained in:
parent
206d02d531
commit
352cca1037
14 changed files with 223 additions and 257 deletions
|
@ -495,3 +495,38 @@ def mock_restore_cache(hass, states):
|
|||
"Duplicate entity_id? {}".format(states)
|
||||
hass.state = ha.CoreState.starting
|
||||
mock_component(hass, recorder.DOMAIN)
|
||||
|
||||
|
||||
class MockDependency:
|
||||
"""Decorator to mock install a dependency."""
|
||||
|
||||
def __init__(self, root, *args):
|
||||
"""Initialize decorator."""
|
||||
self.root = root
|
||||
self.submodules = args
|
||||
|
||||
def __call__(self, func):
|
||||
"""Apply decorator."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
def resolve(mock, path):
|
||||
"""Resolve a mock."""
|
||||
if not path:
|
||||
return mock
|
||||
|
||||
return resolve(getattr(mock, path[0]), path[1:])
|
||||
|
||||
def run_mocked(*args, **kwargs):
|
||||
"""Run with mocked dependencies."""
|
||||
base = MagicMock()
|
||||
to_mock = {
|
||||
"{}.{}".format(self.root, tom): resolve(base, tom.split('.'))
|
||||
for tom in self.submodules
|
||||
}
|
||||
to_mock[self.root] = base
|
||||
|
||||
with patch.dict('sys.modules', to_mock):
|
||||
args = list(args) + [base]
|
||||
func(*args, **kwargs)
|
||||
|
||||
return run_mocked
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue