2024-09-02 20:40:46 +00:00
|
|
|
import shutil
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def tmp_output_dir(request: pytest.FixtureRequest) -> Path:
|
2024-09-03 07:54:56 +00:00
|
|
|
path = Path(__file__).parents[1].resolve() / "__tmp__"
|
2024-09-02 20:40:46 +00:00
|
|
|
if path.exists():
|
2024-09-02 20:41:04 +00:00
|
|
|
if request.config.getoption("--clean"):
|
2024-09-02 20:40:46 +00:00
|
|
|
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
|