From 9963d0c3318caa931061d4e9b8c9f129f8860cce Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 4 Jan 2024 10:45:35 +0300 Subject: Rename test module While 'covar' files can contain cross information, they do not have to, and therefore, we need to test for cross information separately. --- tests/r_qtl/test_r_qtl2_covar.py | 36 ++++++++++++++++++++++++++++ tests/r_qtl/test_r_qtl2_cross_information.py | 36 ---------------------------- 2 files changed, 36 insertions(+), 36 deletions(-) create mode 100644 tests/r_qtl/test_r_qtl2_covar.py delete mode 100644 tests/r_qtl/test_r_qtl2_cross_information.py (limited to 'tests') diff --git a/tests/r_qtl/test_r_qtl2_covar.py b/tests/r_qtl/test_r_qtl2_covar.py new file mode 100644 index 0000000..c18ee74 --- /dev/null +++ b/tests/r_qtl/test_r_qtl2_covar.py @@ -0,0 +1,36 @@ +"""Test parsing of 'covar' files.""" +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,expected", + (("tests/r_qtl/test_files/test_covar.zip", + ({"id": "1", "sex": "m", "cross_direction": "(BxS)x(BxS)"}, + {"id": "2", "sex": "m", "cross_direction": "(BxS)x(BxS)"}, + {"id": "3", "sex": "m", "cross_direction": "(BxS)x(BxS)"}, + {"id": "146", "sex": "f", "cross_direction": "(BxS)x(BxS)"}, + {"id": "147", "sex": "f", "cross_direction": "(BxS)x(BxS)"}, + {"id": "148", "sex": "f", "cross_direction": "(BxS)x(BxS)"})), + ("tests/r_qtl/test_files/test_covar_transposed.zip", + ({"id": "1", "sex": "m", "cross_direction": "(BxS)x(BxS)"}, + {"id": "2", "sex": "m", "cross_direction": "(BxS)x(BxS)"}, + {"id": "3", "sex": "m", "cross_direction": "(BxS)x(BxS)"}, + {"id": "146", "sex": "f", "cross_direction": "(BxS)x(BxS)"}, + {"id": "147", "sex": "f", "cross_direction": "(BxS)x(BxS)"}, + {"id": "148", "sex": "f", "cross_direction": "(BxS)x(BxS)"})), + )) +def test_parse_covar_files(filepath, expected): + """Test parsing of 'covar' files from the R/qtl2 bundle. + + GIVEN: path to a R/qtl2 bundle + WHEN: the 'covar' file is parsed + THEN: verify the parsed data is as expected + """ + with ZipFile(Path(filepath).absolute(), "r") as zfile: + cdata = rqtl2.control_data(zfile) + assert tuple(rqtl2.file_data(zfile, "covar", cdata)) == expected diff --git a/tests/r_qtl/test_r_qtl2_cross_information.py b/tests/r_qtl/test_r_qtl2_cross_information.py deleted file mode 100644 index f004fd3..0000000 --- a/tests/r_qtl/test_r_qtl2_cross_information.py +++ /dev/null @@ -1,36 +0,0 @@ -"""Test parsing of cross-information files.""" -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,expected", - (("tests/r_qtl/test_files/test_covar.zip", - ({"id": "1", "sex": "m", "cross_direction": "(BxS)x(BxS)"}, - {"id": "2", "sex": "m", "cross_direction": "(BxS)x(BxS)"}, - {"id": "3", "sex": "m", "cross_direction": "(BxS)x(BxS)"}, - {"id": "146", "sex": "f", "cross_direction": "(BxS)x(BxS)"}, - {"id": "147", "sex": "f", "cross_direction": "(BxS)x(BxS)"}, - {"id": "148", "sex": "f", "cross_direction": "(BxS)x(BxS)"})), - ("tests/r_qtl/test_files/test_covar_transposed.zip", - ({"id": "1", "sex": "m", "cross_direction": "(BxS)x(BxS)"}, - {"id": "2", "sex": "m", "cross_direction": "(BxS)x(BxS)"}, - {"id": "3", "sex": "m", "cross_direction": "(BxS)x(BxS)"}, - {"id": "146", "sex": "f", "cross_direction": "(BxS)x(BxS)"}, - {"id": "147", "sex": "f", "cross_direction": "(BxS)x(BxS)"}, - {"id": "148", "sex": "f", "cross_direction": "(BxS)x(BxS)"})), - )) -def test_parse_covar_files(filepath, expected): - """Test parsing of 'covar' files from the R/qtl2 bundle. - - GIVEN: path to a R/qtl2 bundle - WHEN: the 'covar' file is parsed - THEN: verify the parsed data is as expected - """ - with ZipFile(Path(filepath).absolute(), "r") as zfile: - cdata = rqtl2.control_data(zfile) - assert tuple(rqtl2.file_data(zfile, "covar", cdata)) == expected -- cgit v1.2.3