forked from diffpy/diffpy.pdffit2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
50 lines (36 loc) · 1.18 KB
/
conftest.py
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
import io
import json
from pathlib import Path
import pytest
import diffpy.pdffit2
import diffpy.pdffit2.output # assuming this is the correct import path
@pytest.fixture
def user_filesystem(tmp_path):
base_dir = Path(tmp_path)
home_dir = base_dir / "home_dir"
home_dir.mkdir(parents=True, exist_ok=True)
cwd_dir = base_dir / "cwd_dir"
cwd_dir.mkdir(parents=True, exist_ok=True)
home_config_data = {"username": "home_username", "email": "[email protected]"}
with open(home_dir / "diffpyconfig.json", "w") as f:
json.dump(home_config_data, f)
yield tmp_path
@pytest.fixture
def datafile():
"""Fixture to dynamically load any test file."""
def _load(filename):
return "tests/testdata/" + filename
return _load
@pytest.fixture
def capture_output():
"""Capture output from pdffit2 engine produced in function call."""
def _capture(f, *args, **kwargs):
savestdout = diffpy.pdffit2.output.stdout
fp = io.StringIO()
diffpy.pdffit2.redirect_stdout(fp)
try:
f(*args, **kwargs)
finally:
diffpy.pdffit2.redirect_stdout(savestdout)
return fp.getvalue()
return _capture