Skip to content

Commit 396c4d0

Browse files
committed
chore: use consistent test data path
1 parent 3f69015 commit 396c4d0

4 files changed

Lines changed: 34 additions & 21 deletions

File tree

tests/helper.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,14 @@ def run_ni_example():
126126

127127

128128
def run_multi_contribution_example():
129-
ciffile_ni = Path(__file__).parent / "data/ni.cif"
130-
ciffile_si = Path(__file__).parent / "data/si.cif"
131-
xdata_ni = Path(__file__).parent / "data/ni-q27r60-xray.gr"
132-
ndata_ni = Path(__file__).parent / "data/ni-q27r100-neutron.gr"
133-
xdata_si = Path(__file__).parent / "data/si-q27r60-xray.gr"
134-
xdata_sini = Path(__file__).parent / "data/si90ni10-q27r60-xray.gr"
129+
ciffile_ni = str(Path(__file__).parent / "data" / "ni.cif")
130+
ciffile_si = str(Path(__file__).parent / "data" / "si.cif")
131+
xdata_ni = str(Path(__file__).parent / "data" / "ni-q27r60-xray.gr")
132+
ndata_ni = str(Path(__file__).parent / "data" / "ni-q27r100-neutron.gr")
133+
xdata_si = str(Path(__file__).parent / "data" / "si-q27r60-xray.gr")
134+
xdata_sini = str(
135+
Path(__file__).parent / "data" / "si90ni10-q27r60-xray.gr"
136+
)
135137

136138
def makeProfile(datafile):
137139
profile = Profile()

tests/test_parametric_model.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pathlib import Path
2+
13
import numpy
24
import pytest
35

@@ -10,6 +12,8 @@
1012
)
1113
from diffpy.srfit.pdf import PDFParser
1214

15+
_DATA_DIR = Path(__file__).parent / "data"
16+
1317

1418
def test_parametric_model_graph():
1519
# C1: Create a nested parametric model
@@ -59,14 +63,14 @@ def test_parametric_model_evaluation(nested_sine_model, A, a, x, expected):
5963
def test_parametric_pdf_model_parameters():
6064
# C1: Create a ParametricModelPDF for Ni
6165
# Expect the model to be initialized correctly with all parameters
62-
profile_path = "tests/data/Ni.gr"
66+
profile_path = str(_DATA_DIR / "Ni.gr")
6367
profile = Profile()
6468
parser = PDFParser()
6569
parser.parse_file(profile_path)
6670
profile.load_parsed_data(parser)
6771
profile.set_calculation_range(xmax=20)
6872
pdf_model = ParametricModelPDF(
69-
"ni", structure_file_path="tests/data/Ni.cif"
73+
"ni", structure_file_path=str(_DATA_DIR / "Ni.cif")
7074
)
7175
parameter_names = [
7276
"ni.phase.lattice.a",

tests/test_refinement_server.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
from pathlib import Path
2+
13
import numpy
24
import pytest
35
from helper import run_ni_example
46
from mcp import Client
57

68
from diffpy.apps.refinebase.refinement_server import mcp
79

10+
_DATA_DIR = Path(__file__).parent / "data"
11+
812

913
@pytest.fixture
1014
def anyio_backend():
@@ -22,7 +26,7 @@ async def test_refine_sine():
2226
"add_profile_from_file",
2327
{
2428
"profile_name": "sine_profile",
25-
"profile_path": "tests/data/sine.dat",
29+
"profile_path": str(_DATA_DIR / "sine.dat"),
2630
},
2731
)
2832
assert "sine_profile" in session.profiles_dict
@@ -67,7 +71,7 @@ async def test_refine_ni():
6771
"add_profile_from_file",
6872
{
6973
"profile_name": "ni_profile",
70-
"profile_path": "tests/data/Ni.gr",
74+
"profile_path": str(_DATA_DIR / "Ni.gr"),
7175
},
7276
)
7377
await mcp_client.call_tool(
@@ -90,7 +94,7 @@ async def test_refine_ni():
9094
"add_pdf_model",
9195
{
9296
"model_name": "pdf",
93-
"structure_file_path": "tests/data/Ni.cif",
97+
"structure_file_path": str(_DATA_DIR / "Ni.cif"),
9498
},
9599
)
96100
await mcp_client.call_tool(

tests/test_refinement_session.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from pathlib import Path
2+
13
import numpy
2-
from helper import run_multi_contribution_example, run_ni_example
34

45
from diffpy.apps.refinebase.refinement_session import RefinementSession
6+
from helper import run_multi_contribution_example, run_ni_example
7+
8+
_DATA_DIR = Path(__file__).parent / "data"
59

610

711
def test_refine_sine(sine_profile):
@@ -42,7 +46,7 @@ def test_refine_ni():
4246
# obtained using diffpy.srfit script
4347
session = RefinementSession()
4448
session.add_profile_from_file(
45-
profile_name="ni_profile", profile_path="tests/data/Ni.gr"
49+
profile_name="ni_profile", profile_path=str(_DATA_DIR / "Ni.gr")
4650
)
4751
session.set_profile_calculation_range(
4852
profile_name="ni_profile",
@@ -56,7 +60,7 @@ def test_refine_ni():
5660
)
5761
session.add_pdf_model(
5862
model_name="pdf",
59-
structure_file_path="tests/data/Ni.cif",
63+
structure_file_path=str(_DATA_DIR / "Ni.cif"),
6064
)
6165
session.constrain_pdf_model_space_group_symmetry(
6266
model_name="pdf", space_group="Fm-3m"
@@ -149,29 +153,28 @@ def test_refine_ni():
149153
def test_refine_multi_contribution():
150154
session = RefinementSession()
151155
session.add_profile_from_file(
152-
profile_path="tests/data/ni-q27r60-xray.gr",
156+
profile_path=str(_DATA_DIR / "ni-q27r60-xray.gr"),
153157
profile_name="ni_xray",
154158
)
155159
session.add_profile_from_file(
156-
profile_path="tests/data/ni-q27r100-neutron.gr",
160+
profile_path=str(_DATA_DIR / "ni-q27r100-neutron.gr"),
157161
profile_name="ni_neutron",
158162
)
159163
session.add_profile_from_file(
160-
profile_path="tests/data/si-q27r60-xray.gr",
164+
profile_path=str(_DATA_DIR / "si-q27r60-xray.gr"),
161165
profile_name="si_xray",
162166
)
163167
session.add_profile_from_file(
164-
profile_path="tests/data/si90ni10-q27r60-xray.gr",
168+
profile_path=str(_DATA_DIR / "si90ni10-q27r60-xray.gr"),
165169
profile_name="total_xray",
166170
)
167171
session.set_profile_calculation_range(profile_name="ni_xray", xmax=20)
168172
session.set_profile_calculation_range(profile_name="ni_neutron", xmax=20)
169173
session.set_profile_calculation_range(profile_name="si_xray", xmax=20)
170174
session.set_profile_calculation_range(profile_name="total_xray", xmax=20)
171175
session.add_pdf_model(
172-
structure_file_path="tests/data/ni.cif",
176+
structure_file_path=str(_DATA_DIR / "Ni.cif"),
173177
model_name="pdf_ni",
174-
# structure_lib="PyObjcryst",
175178
)
176179
session.constrain_pdf_model_space_group_symmetry("pdf_ni")
177180
session.add_pdf_model(
@@ -183,7 +186,7 @@ def test_refine_multi_contribution():
183186
model_name="pdf_ni_partial",
184187
)
185188
session.add_pdf_model(
186-
structure_file_path="tests/data/si.cif",
189+
structure_file_path=str(_DATA_DIR / "si.cif"),
187190
model_name="pdf_si",
188191
structure_lib="PyObjcryst",
189192
)

0 commit comments

Comments
 (0)