Skip to content

Commit

Permalink
implement explicit type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuhl-uni committed Feb 16, 2024
1 parent f60e623 commit 815e885
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pyerrors/input/sfcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,14 @@ def read_sfcf_multi(path, prefix, name_list, quarks_list=['.*'], corr_type_list=
if "files" in kwargs:
files = kwargs.get("files")
if isinstance(files, list):
if isinstance(files[0], list):
if all(isinstance(f, list) for f in files):
files = files[i]
elif all(isinstance(f, str) for f in files):
files = files
else:
raise TypeError("files has to be of type list[list[str]] or list[str]!")
else:
raise TypeError("files has to be of type list[list[str]] or list[str]!")

else:
files = []
Expand Down Expand Up @@ -313,7 +319,10 @@ def read_sfcf_multi(path, prefix, name_list, quarks_list=['.*'], corr_type_list=
w = specs[3]
w2 = specs[4]
if "files" in kwargs:
name_ls = kwargs.get("files")
if isinstance(kwargs.get("files"), list) and all(isinstance(f, str) for f in kwargs.get("files")):
name_ls = kwargs.get("files")
else:
raise TypeError("In append mode, files has to be of type list[str]!")
else:
name_ls = ls
for exc in name_ls:
Expand Down
14 changes: 14 additions & 0 deletions tests/sfcf_in_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ def test_c_bi_files(tmp_path):
assert f_A[2].value == -41.025094911185185


def test_c_bi_files_int_fail(tmp_path):
build_test_environment(str(tmp_path), "c", 10, 3)
with pytest.raises(TypeError):
sfin.read_sfcf(str(tmp_path) + "/data_c", "data_c", "f_A", quarks="lquark lquark", wf=0, version="2.0c",
files=[[range(1, 11, 2)], [range(2, 11, 2)], [range(1, 11, 2)]])


def test_c_bib(tmp_path):
build_test_environment(str(tmp_path), "c", 5, 3)
f_V0 = sfin.read_sfcf(str(tmp_path) + "/data_c", "data_c", "F_V0", quarks="lquark lquark", wf=0, wf2=0, version="2.0c", corr_type="bib")
Expand Down Expand Up @@ -291,6 +298,13 @@ def test_a_bi_files(tmp_path):
assert f_A[2].value == -41.025094911185185


def test_a_bi_files_int_fail(tmp_path):
build_test_environment(str(tmp_path), "a", 10, 3)
with pytest.raises(TypeError):
sfin.read_sfcf(str(tmp_path) + "/data_a", "data_a", "f_A", quarks="lquark lquark", wf=0, version="2.0a",
files=[[range(1, 11, 2)], [range(2, 11, 2)], [range(1, 11, 2)]])


def test_a_bib(tmp_path):
build_test_environment(str(tmp_path), "a", 5, 3)
f_V0 = sfin.read_sfcf(str(tmp_path) + "/data_a", "data_a", "F_V0", quarks="lquark lquark", wf=0, wf2=0, version="2.0a", corr_type="bib")
Expand Down

0 comments on commit 815e885

Please sign in to comment.