mirror of
https://github.com/p2p-ld/nwb-linkml.git
synced 2024-11-14 02:34:28 +00:00
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
import shutil
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def tmp_output_dir(request: pytest.FixtureRequest) -> Path:
|
|
path = Path(__file__).parent.resolve() / "__tmp__"
|
|
if path.exists():
|
|
if request.config.getoption("--clean"):
|
|
shutil.rmtree(path)
|
|
else:
|
|
for subdir in path.iterdir():
|
|
if subdir.name == "git":
|
|
# don't wipe out git repos every time, they don't rly change
|
|
continue
|
|
elif subdir.is_file() and subdir.parent != path:
|
|
continue
|
|
elif subdir.is_file():
|
|
subdir.unlink(missing_ok=True)
|
|
else:
|
|
shutil.rmtree(str(subdir))
|
|
path.mkdir(exist_ok=True)
|
|
|
|
return path
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def tmp_output_dir_func(tmp_output_dir) -> Path:
|
|
"""
|
|
tmp output dir that gets cleared between every function
|
|
cleans at the start rather than at cleanup in case the output is to be inspected
|
|
"""
|
|
subpath = tmp_output_dir / "__tmpfunc__"
|
|
if subpath.exists():
|
|
shutil.rmtree(str(subpath))
|
|
subpath.mkdir()
|
|
return subpath
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def tmp_output_dir_mod(tmp_output_dir) -> Path:
|
|
"""
|
|
tmp output dir that gets cleared between every function
|
|
cleans at the start rather than at cleanup in case the output is to be inspected
|
|
"""
|
|
subpath = tmp_output_dir / "__tmpmod__"
|
|
if subpath.exists():
|
|
shutil.rmtree(str(subpath))
|
|
subpath.mkdir()
|
|
return subpath
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def data_dir() -> Path:
|
|
path = Path(__file__).parent.resolve() / "data"
|
|
return path
|