aboutsummaryrefslogtreecommitdiff
path: root/tests/r_qtl
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-09 09:50:18 +0300
committerFrederick Muriuki Muriithi2024-01-09 09:50:18 +0300
commit5491da18dda8c6f55bc2bc5d95f21b86908cd382 (patch)
tree6f8224a9056e18b855a2240ae0b8dd24c02f10a5 /tests/r_qtl
parentb3f5a89aca45a3e803e7bc3b2ee1a3d048801eee (diff)
downloadgn-uploader-5491da18dda8c6f55bc2bc5d95f21b86908cd382.tar.gz
Raise exception on reading non-existing file
The validation checks ensure that whatever files are listed in the control file exist in the zip file bundle. It is still possible, however, that the code tries to read a file that does not exist in the file and is not listed in the control file. In those cases, raise the appropriate exception.
Diffstat (limited to 'tests/r_qtl')
-rw-r--r--tests/r_qtl/test_files/nonexistent.zipbin0 -> 380 bytes
-rw-r--r--tests/r_qtl/test_r_qtl2_nonexistent_file.py29
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/r_qtl/test_files/nonexistent.zip b/tests/r_qtl/test_files/nonexistent.zip
new file mode 100644
index 0000000..4a31bf1
--- /dev/null
+++ b/tests/r_qtl/test_files/nonexistent.zip
Binary files differ
diff --git a/tests/r_qtl/test_r_qtl2_nonexistent_file.py b/tests/r_qtl/test_r_qtl2_nonexistent_file.py
new file mode 100644
index 0000000..c783a76
--- /dev/null
+++ b/tests/r_qtl/test_r_qtl2_nonexistent_file.py
@@ -0,0 +1,29 @@
+"""Test accessing nonexistent member."""
+from pathlib import Path
+
+import pytest
+from zipfile import ZipFile
+
+from r_qtl import r_qtl2 as rqtl2
+
+@pytest.mark.unit_test
+@pytest.mark.parametrize(
+ "filepath,memberkey",
+ (("tests/r_qtl/test_files/nonexistent.zip", "geno"),
+ ("tests/r_qtl/test_files/nonexistent.zip", "founder_geno"),
+ ("tests/r_qtl/test_files/nonexistent.zip", "pheno"),
+ ("tests/r_qtl/test_files/nonexistent.zip", "covar"),
+ ("tests/r_qtl/test_files/nonexistent.zip", "phenocovar"),
+ ("tests/r_qtl/test_files/nonexistent.zip", "gmap"),
+ ("tests/r_qtl/test_files/nonexistent.zip", "pmap")))
+def test_loading_nonexistent_file(filepath, memberkey):
+ """
+ GIVEN: A zipfile with a valid control file, but some files mentioned in the
+ control file do not exist in the zipfile
+ WHEN: access is made to such missing files
+ THEN: raise an exception
+ """
+ with (ZipFile(Path(filepath).absolute(), "r") as zfile,
+ pytest.raises(rqtl2.InvalidFormat)):
+ cdata = rqtl2.control_data(zfile)
+ tuple(rqtl2.file_data(zfile, memberkey, cdata))