-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconftest.py
More file actions
71 lines (57 loc) · 2.19 KB
/
conftest.py
File metadata and controls
71 lines (57 loc) · 2.19 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Fixtures for markdown-docs tests of .md files (run by lib/stardag package tests)."""
import os
import typing
from pathlib import Path
import pytest
from stardag.target import (
InMemoryFileTarget,
LocalFileTarget,
target_factory_provider,
)
from stardag.target._factory import TargetFactory
from stardag.utils.testing.env import temp_env_vars
@pytest.fixture(scope="function")
def default_local_target_tmp_path(
tmp_path: Path,
) -> typing.Generator[Path, None, None]:
import json
default_root = tmp_path.absolute() / "default-root"
default_root.mkdir(parents=True, exist_ok=False)
# Set env var so subprocesses (multiprocessing) can pick it up
target_roots = {"default": str(default_root)}
with temp_env_vars({"STARDAG_TARGET_ROOTS": json.dumps(target_roots)}):
with target_factory_provider.override(
TargetFactory(
target_roots=target_roots,
prefix_to_target_prototype={"/": LocalFileTarget},
)
):
yield default_root
@pytest.fixture(scope="session")
def default_in_memory_fs_target_prefix():
return "in-memory://"
@pytest.fixture(scope="function")
def _default_in_memory_fs_target_factory(
default_in_memory_fs_target_prefix,
) -> typing.Generator[TargetFactory, None, None]:
with target_factory_provider.override(
TargetFactory(
target_roots={"default": default_in_memory_fs_target_prefix},
prefix_to_target_prototype={
default_in_memory_fs_target_prefix: InMemoryFileTarget
},
)
) as target_factory:
with InMemoryFileTarget.cleared():
yield target_factory
@pytest.fixture(scope="function")
def default_in_memory_fs_target(
_default_in_memory_fs_target_factory,
) -> typing.Type[InMemoryFileTarget]:
return InMemoryFileTarget
@pytest.fixture(scope="function", autouse=True)
def cleared_stardag_env_vars() -> typing.Generator[None, None, None]:
"""Clear STARDAG_* environment variables for the duration of the test."""
stardag_env_vars = [var for var in os.environ if var.startswith("STARDAG_")]
with temp_env_vars({var: None for var in stardag_env_vars}):
yield