diff options
author | BonfaceKilz | 2022-04-12 12:07:13 +0300 |
---|---|---|
committer | BonfaceKilz | 2022-04-12 13:26:57 +0300 |
commit | ca8a18f00b06a7c6ca4b022223f381ddaebbf930 (patch) | |
tree | 1ce666d38009e739e60005c1f8430235f8aaca29 /tests/unit | |
parent | 48cc775e5cbcb9cf8e97b966c86527c5344fa6ea (diff) | |
download | genenetwork3-ca8a18f00b06a7c6ca4b022223f381ddaebbf930.tar.gz |
Test that a carriage return is removed when generating csv
* tests/unit/db/test_sample_data.py: import "get_trait_csv_sample_data".
(test_get_trait_csv_sample_data): New test function.
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/db/test_sample_data.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/unit/db/test_sample_data.py b/tests/unit/db/test_sample_data.py index f631239..0fc20f4 100644 --- a/tests/unit/db/test_sample_data.py +++ b/tests/unit/db/test_sample_data.py @@ -7,6 +7,7 @@ from gn3.db.sample_data import delete_sample_data from gn3.db.sample_data import get_case_attributes from gn3.db.sample_data import insert_sample_data from gn3.db.sample_data import update_sample_data +from gn3.db.sample_data import get_trait_csv_sample_data @pytest.mark.unit_test @@ -245,3 +246,55 @@ def test_get_case_attributes(mocker): "Condition (4)": "Description A", "Condition (5)": "Description B", } + + +@pytest.mark.unit_test +def test_get_trait_csv_sample_data(mocker): + """Test fetching trait sample data""" + mock_conn = mocker.MagicMock() + with mock_conn.cursor() as cursor: + cursor.fetchall.return_value = [ + ["JL00005,896.000000,x,x", "Age", "896"], + ["JL00005,896.000000,x,x", "DOB", "4/22/04"], + ["JL00005,896.000000,x,x", "Date Geno", "x"], + ["JL00005,896.000000,x,x", "Drug/Site", "4OHPBN_J"], + ["JL00005,896.000000,x,x", "MOD", "Oct"], + ["JL00005,896.000000,x,x", "Platform", "x"], + [ + "JL00005,896.000000,x,x", + "SNP", + """0 +""", + ], + ["JL00005,896.000000,x,x", "Sex", "M"], + ["JL00005,896.000000,x,x", "Site", "JL"], + ["JL00005,896.000000,x,x", "Tx", "1"], + ["JL00005,896.000000,x,x", "Year", "2004"], + ["JL00058,686.000000,x,x", "Age", "686"], + ["JL00058,686.000000,x,x", "DOB", "4/22/04"], + ["JL00058,686.000000,x,x", "Date Geno", "2017.06"], + ["JL00058,686.000000,x,x", "Drug/Site", "Cont_04_J"], + ["JL00058,686.000000,x,x", "MOD", "Mar"], + ["JL00058,686.000000,x,x", "Platform", "M"], + [ + "JL00058,686.000000,x,x", + "SNP", + """2 +""", + ], + ["JL00058,686.000000,x,x", "Sex", "M"], + ["JL00058,686.000000,x,x", "Site", "JL"], + ["JL00058,686.000000,x,x", "Tx", "0"], + ["JL00058,686.000000,x,x", "Year", "2004"], + ] + assert get_trait_csv_sample_data( + conn=mock_conn, trait_name=10007, phenotype_id=35 + ) == ( + "Strain Name,Value,SE,Count,Age,DOB," + "Date Geno,Drug/Site,MOD," + "Platform,SNP,Sex,Site,Tx,Year\n" + "JL00005,896.000000,x,x," + "896,4/22/04,x,4OHPBN_J,Oct,x,0,M,JL,1,2004\n" + "JL00058,686.000000,x,x," + "686,4/22/04,2017.06,Cont_04_J,Mar,M,2,M,JL,0,2004\n" + ) |