From 2c2e1dc3d4be635dbf73aab380e22acca6a2014b Mon Sep 17 00:00:00 2001 From: zsloan Date: Thu, 27 May 2021 20:18:36 +0000 Subject: Improved test_rqtl_mapping.py with Bonface's recommendation of uses dataclasses --- .../wqflask/marker_regression/test_rqtl_mapping.py | 23 ++++++++++------------ 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py b/wqflask/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py index 6853c021..bd97b2d2 100644 --- a/wqflask/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py +++ b/wqflask/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py @@ -2,17 +2,17 @@ import unittest from unittest import mock from wqflask.marker_regression.rqtl_mapping import run_rqtl -class AttributeSetter: - def __init__(self, obj): - for key, val in obj.items(): - setattr(self, key, val) +@dataclass +class MockGroup: + name: str, + genofile: str -class MockGroup(AttributeSetter): - def get_samplelist(self): - return None +@dataclass +class MockDataset: + group: MockGroup class TestRqtlMapping(unittest.TestCase): - + """Tests for functions in rqtl_mapping.py""" @mock.patch("wqflask.marker_regression.rqtl_mapping.process_rqtl_results") @mock.patch("wqflask.marker_regression.rqtl_mapping.process_perm_results") @mock.patch("wqflask.marker_regression.rqtl_mapping.requests.post") @@ -22,15 +22,12 @@ class TestRqtlMapping(unittest.TestCase): """Test for run_rqtl with permutations > 0""" dataset_group = MockGroup( {"name": "GP1", "genofile": "file_geno"}) - - dataset = AttributeSetter({"group": dataset_group}) + dataset = MockDataset(dataset_group) mock_write_pheno_file.return_value = "pheno_filename" mock_locate.return_value = "geno_filename" - mock_post.return_value = {"output_file": "output_filename", "rqtl_cmd": "the_command"} - mock_process_perm.return_value = [[], 3, 4] mock_process_rqtl.return_value = [] @@ -44,4 +41,4 @@ class TestRqtlMapping(unittest.TestCase): mock_post.assert_called_once() mock_process_perm.assert_called_once() mock_process_rqtl.assert_called_once() - self.assertEqual(results, ([], 3, 4, [])) \ No newline at end of file + self.assertEqual(results, ([], 3, 4, [])) -- cgit v1.2.3