1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
import contextlib
from contextlib import contextmanager
import pytest
import inline_snapshot._config as _config
import inline_snapshot._external as external
from inline_snapshot._global_state import state
from inline_snapshot._rewrite_code import ChangeRecorder
from inline_snapshot.testing._example import snapshot_env
__all__ = ("snapshot_env",)
@contextlib.contextmanager
def config(**args):
current_config = _config.config
_config.config = _config.Config(**args)
try:
yield
finally:
_config.config = current_config
@contextlib.contextmanager
def apply_changes():
recorder = ChangeRecorder()
yield recorder
recorder.fix_all()
@contextmanager
def useStorage(storage):
old_storage = state().storage
state().storage = storage
yield
state().storage = old_storage
@pytest.fixture()
def storage(tmp_path):
storage = external.DiscStorage(tmp_path / ".storage")
with useStorage(storage):
yield storage
|