diff options
author | Alexander Kabui | 2021-04-03 13:12:59 +0300 |
---|---|---|
committer | Alexander Kabui | 2021-04-03 13:12:59 +0300 |
commit | d2e24157130ea28a8ac5e7a4511074bb82b6d634 (patch) | |
tree | 6328fc0a17e2df8d3095224d54313f69b7d01601 /tests/unit/computations/test_datasets.py | |
parent | e4cf6ac08a961f8d647f46a6d984d8d66d9f83ae (diff) | |
download | genenetwork3-d2e24157130ea28a8ac5e7a4511074bb82b6d634.tar.gz |
add tests for getting trait data
Diffstat (limited to 'tests/unit/computations/test_datasets.py')
-rw-r--r-- | tests/unit/computations/test_datasets.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/unit/computations/test_datasets.py b/tests/unit/computations/test_datasets.py index b169ba3..1b37d26 100644 --- a/tests/unit/computations/test_datasets.py +++ b/tests/unit/computations/test_datasets.py @@ -14,6 +14,8 @@ from gn3.computations.datasets import dataset_creator_store from gn3.computations.datasets import dataset_type_getter from gn3.computations.datasets import fetch_dataset_type_from_gn2_api from gn3.computations.datasets import fetch_dataset_sample_id +from gn3.computations.datasets import divide_into_chunks +from gn3.computations.datasets import get_traits_data class TestDatasets(TestCase): @@ -179,3 +181,29 @@ class TestDatasets(TestCase): samplelist=strain_list, database=database_instance, species="mouse") self.assertEqual(results, expected_results) + + @mock.patch("gn3.computations.datasets.fetch_from_db_sample_data") + @mock.patch("gn3.computations.datasets.divide_into_chunks") + def test_get_traits_data(self, mock_divide_into_chunks, mock_fetch_samples): + """test for for function to get data\ + of traits in dataset""" + + expected_results = {'AT_DSAFDS': [ + 12, 14, 13, 23, 12, 14, 13, 23, 12, 14, 13, 23]} + database = mock.Mock() + sample_id = [1, 2, 7, 3, 22, 8] + mock_divide_into_chunks.return_value = [ + [1, 2, 7], [3, 22, 8], [5, 22, 333]] + mock_fetch_samples.return_value = ("AT_DSAFDS", 12, 14, 13, 23) + results = get_traits_data(sample_id, database, "HC_M2", "Publish") + + self.assertEqual(expected_results, dict(results)) + + def test_divide_into_chunks(self): + """test for dividing a list into given number of\ + chunks for example""" + results = divide_into_chunks([1, 2, 7, 3, 22, 8, 5, 22, 333], 3) + + expected_results = [[1, 2, 7], [3, 22, 8], [5, 22, 333]] + + self.assertEqual(results, expected_results) |