Skip to content

Commit 9680c77

Browse files
committed
add test files as conftest fixture
1 parent 172fced commit 9680c77

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,102 @@ def temp_data_files(tmp_path):
269269
"""
270270
)
271271
yield tmp_path
272+
273+
274+
@pytest.fixture
275+
def parser_datafile(tmp_path):
276+
"""Create temporary data files with different column layouts and
277+
yield the directory."""
278+
279+
METADATA_HEADER = r"""# xPDFsuite Configuration #
280+
[PDF]
281+
wavelength = 0.1
282+
dataformat = QA
283+
inputfile = input.iq
284+
backgroundfile = backgroundfile.iq
285+
mode = xray
286+
bgscale = 1.0
287+
composition = TiSe2
288+
outputtype = gr
289+
qmaxinst = 25.0
290+
qmin = 0.1
291+
qmax = 25.0
292+
rmax = 140.0
293+
rmin = 0.0
294+
rstep = 0.01
295+
rpoly = 0.7
296+
297+
[Misc]
298+
inputdir = /my/data/dir
299+
savedir = /my/save/dir
300+
backgroundfilefull = /my/data/dir/backgroundfile.iq
301+
302+
#### start data
303+
#S 1
304+
"""
305+
306+
# Four-column standard
307+
(tmp_path / "four_col.gr").write_text(
308+
METADATA_HEADER
309+
+ r"""#L r($\AA$) G($\AA^{-2}$) dr($\AA$) dG($\AA^{-2}$)
310+
1.0 2.0 0.1 0.2
311+
1.1 2.1 0.3 0.4
312+
1.2 2.2 0.5 0.6"""
313+
)
314+
315+
# Three-column (x, y, dy)
316+
(tmp_path / "three_col.dat").write_text(
317+
METADATA_HEADER
318+
+ r"""#L r($\AA$) G($\AA^{-2}$) dG($\AA^{-2}$)
319+
1.0 2.0 0.2
320+
1.1 2.1 0.4
321+
1.2 2.2 0.6"""
322+
)
323+
324+
# Two-column (x, y)
325+
(tmp_path / "two_col.txt").write_text(
326+
METADATA_HEADER
327+
+ r"""#L r($\AA$) G($\AA^{-2}$)
328+
1.0 2.0
329+
1.1 2.1
330+
1.2 2.2"""
331+
)
332+
333+
# Four-column reordered (x, dx, y, dy)
334+
(tmp_path / "four_col_reordered.txt").write_text(
335+
METADATA_HEADER
336+
+ r"""#L r($\AA$) dr($\AA$) G($\AA^{-2}$) dG($\AA^{-2}$)
337+
1.0 0.1 2.0 0.2
338+
1.1 0.3 2.1 0.4
339+
1.2 0.5 2.2 0.6"""
340+
)
341+
342+
# Four-column with NaN/Inf
343+
(tmp_path / "four_col_nan_inf.gr").write_text(
344+
METADATA_HEADER
345+
+ r"""#L r($\AA$) G($\AA^{-2}$) dr($\AA$) dG($\AA^{-2}$)
346+
1.0 2.0 nan inf
347+
1.1 2.1 inf 1
348+
1.2 2.2 nan nan"""
349+
)
350+
351+
# One-column
352+
(tmp_path / "one_col.gr").write_text(
353+
METADATA_HEADER
354+
+ r"""#L r($\AA$)
355+
1.0
356+
1.1
357+
1.2"""
358+
)
359+
360+
# Five-column (extra column)
361+
(tmp_path / "five_col.gr").write_text(
362+
METADATA_HEADER
363+
+ r"""#L r($\AA$) G($\AA^{-2}$) dr($\AA$) dG($\AA^{-2}$) extra
364+
1.0 2.0 0.1 0.2 9.9
365+
1.1 2.1 0.3 0.4 9.8
366+
1.2 2.2 0.5 0.6 9.7"""
367+
)
368+
369+
# Yield the directory
370+
yield tmp_path

0 commit comments

Comments
 (0)