aboutsummaryrefslogtreecommitdiff
path: root/tests/r_qtl/test_r_qtl2_nonexistent_file.py
blob: c783a76ba3715bb114cc2a5eee642388c54a9bc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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))