Skip to content

Commit

Permalink
Mock only a single method of the rose config object. (#291)
Browse files Browse the repository at this point in the history
Use a real RoseConfig to avoid need to mock objects.
  • Loading branch information
wxtim authored Jan 25, 2024
1 parent 0f69172 commit 1e3e97c
Showing 1 changed file with 7 additions and 7 deletions.
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

0 comments on commit 1e3e97c

Please sign in to comment.