Skip to content

Commit d1f01b9

Browse files
added tests for input files
1 parent f0d626e commit d1f01b9

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/diffpy/labpdfproc/tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,16 @@ def user_filesystem(tmp_path):
1515
existing_file = Path(tmp_path).resolve() / "existing_file.py"
1616
existing_file.touch()
1717

18+
input_directory = Path(tmp_path).resolve() / "input_directory"
19+
input_directory.mkdir(parents=True, exist_ok=True)
20+
21+
with open(os.path.join(input_directory, "good_data.chi"), "w") as f:
22+
f.write("1 2 \n 3 4 \n 5 6 \n 7 8")
23+
with open(os.path.join(input_directory, "good_data.xy"), "w") as f:
24+
f.write("1 2 \n 3 4 \n 5 6 \n 7 8")
25+
with open(os.path.join(input_directory, "unreadable_file.txt"), "w") as f:
26+
f.write("This is an unreadable file.")
27+
with open(os.path.join(input_directory, "binary.pkl"), "wb") as f:
28+
f.write(b"\x00\x01\x02\x03\x04")
29+
1830
yield tmp_path

src/diffpy/labpdfproc/tests/test_tools.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import argparse
2+
import os
23
import re
34
from pathlib import Path
45

56
import pytest
67

78
from diffpy.labpdfproc.tools import known_sources, set_input_directory, set_output_directory, set_wavelength
9+
from diffpy.utils.parsers.loaddata import loadData
810

911
params1 = [
1012
([None], ["."]),
@@ -29,7 +31,6 @@ def test_set_output_directory(inputs, expected, user_filesystem):
2931

3032

3133
def test_set_output_directory_bad(user_filesystem):
32-
# tmp_dir = user_filesystem
3334
actual_parser = argparse.ArgumentParser()
3435
actual_parser.add_argument("--output_directory")
3536
actual_args = actual_parser.parse_args(["--output_directory", "existing_file.py"])
@@ -60,6 +61,16 @@ def test_set_input_directory(inputs, expected, user_filesystem):
6061
assert actual_args.input_directory == expected_input_directory
6162

6263

64+
def test_input_files(user_filesystem):
65+
os.chdir("input_directory")
66+
xarray_chi, yarray_chi = loadData("good_data.chi", unpack=True)
67+
xarray_xy, yarray_xy = loadData("good_data.xy", unpack=True)
68+
with pytest.raises(ValueError):
69+
xarray_txt, yarray_txt = loadData("unreadable_file.txt", unpack=True)
70+
with pytest.raises(ValueError):
71+
xarray_pkl, yarray_pkl = loadData("binary.pkl", unpack=True)
72+
73+
6374
params2 = [
6475
([None, None], [0.71]),
6576
([None, "Ag"], [0.59]),

0 commit comments

Comments
 (0)