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

Mock only a single method of the rose config object. #291

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tests/functional/test_rose_stem.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
from shlex import split
from types import SimpleNamespace
from uuid import uuid4
from unittest.mock import MagicMock

from cylc.flow.pathutil import get_workflow_run_dir
from cylc.flow.hostuserutil import get_host
Expand Down Expand Up @@ -118,13 +117,14 @@ def mock_global_cfg(monkeymodule):
conf: A fake rose global config as a string.
"""
def _inner(target, conf):
"""Mock a config object with a config node."""
node = ConfigLoader().load(StringIO(conf))

# Create a fake class imitating ConfigTree with .get_conf method:
config = MagicMock(spec=['get_conf'], get_conf=lambda: node)
"""Get the ResourceLocator.default and patch its get_conf method
"""
obj = ResourceLocator.default()
monkeymodule.setattr(
obj, 'get_conf', lambda: ConfigLoader().load(StringIO(conf))
)

monkeymodule.setattr(target, lambda *_, **__: config)
monkeymodule.setattr(target, lambda *_, **__: obj)

yield _inner

Expand Down
Loading