-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
58 lines (43 loc) · 1.42 KB
/
Copy pathconftest.py
File metadata and controls
58 lines (43 loc) · 1.42 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
import os
import typing as ty
import logging
from pathlib import Path
import tempfile
import pytest
try:
from pydra import set_input_validator
set_input_validator(True)
except ImportError:
pass
from fileformats.core.utils import include_testing_package
include_testing_package(True)
# Set DEBUG logging for unittests
log_level = logging.WARNING
logger = logging.getLogger("fileformats")
logger.setLevel(log_level)
sch = logging.StreamHandler()
sch.setLevel(log_level)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
sch.setFormatter(formatter)
logger.addHandler(sch)
# For debugging in IDE's don't catch raised exceptions and let the IDE
# break at it
if os.getenv("_PYTEST_RAISE", "0") != "0":
@pytest.hookimpl(tryfirst=True)
def pytest_exception_interact(call: pytest.CallInfo[ty.Any]) -> None:
if call.excinfo is not None:
raise call.excinfo.value
@pytest.hookimpl(tryfirst=True)
def pytest_internalerror(excinfo: pytest.ExceptionInfo[BaseException]) -> None:
raise excinfo.value
@pytest.fixture
def work_dir() -> Path:
work_dir = tempfile.mkdtemp()
return Path(work_dir)
def write_test_file(
fpath: Path, contents: ty.Union[str, bytes] = "some contents", binary: bool = False
) -> Path:
fpath.parent.mkdir(exist_ok=True, parents=True)
with open(fpath, "wb" if binary else "w") as f:
f.write(contents)
return fpath