core/modules: switch away from using override_config to tmp_config in some tests & faka data generators
This commit is contained in:
parent
5ac5636e7f
commit
0e884fe166
5 changed files with 48 additions and 25 deletions
|
@ -28,7 +28,7 @@ F = TypeVar('F')
|
|||
from contextlib import contextmanager
|
||||
from typing import Iterator
|
||||
@contextmanager
|
||||
def override_config(config: F) -> Iterator[F]:
|
||||
def _override_config(config: F) -> Iterator[F]:
|
||||
'''
|
||||
Temporary override for config's parameters, useful for testing/fake data/etc.
|
||||
'''
|
||||
|
@ -82,7 +82,7 @@ def tmp_config(*, modules: Optional[ModuleRegex]=None, config=None):
|
|||
assert config is not None
|
||||
|
||||
import my.config
|
||||
with ExitStack() as module_reload_stack, override_config(my.config) as new_config:
|
||||
with ExitStack() as module_reload_stack, _override_config(my.config) as new_config:
|
||||
if config is not None:
|
||||
overrides = {k: v for k, v in vars(config).items() if not k.startswith('__')}
|
||||
for k, v in overrides.items():
|
||||
|
@ -104,3 +104,8 @@ def test_tmp_config() -> None:
|
|||
# todo hmm. not sure what should do about new properties??
|
||||
assert not hasattr(c, 'extra')
|
||||
assert c.google != 'whatever'
|
||||
|
||||
|
||||
###
|
||||
# todo properly deprecate, this isn't really meant for public use
|
||||
override_config = _override_config
|
||||
|
|
|
@ -123,8 +123,8 @@ from contextlib import contextmanager as ctx
|
|||
@ctx
|
||||
def _reset_config() -> Iterator[Config]:
|
||||
# todo maybe have this decorator for the whole of my.config?
|
||||
from .cfg import override_config
|
||||
with override_config(config) as cc:
|
||||
from .cfg import _override_config
|
||||
with _override_config(config) as cc:
|
||||
cc.enabled_modules = None
|
||||
cc.disabled_modules = None
|
||||
cc.cache_dir = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue