From e63e85868ed7b63bbe784368b3c1babf0d1f2088 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Wed, 11 Nov 2020 23:09:01 +0300 Subject: add tests for marker_regression/rqtl_mapping.py --- .../wqflask/marker_regression/test_rqtl_mapping.py | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py (limited to 'wqflask/tests') diff --git a/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py b/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py new file mode 100644 index 00000000..641644cc --- /dev/null +++ b/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py @@ -0,0 +1,55 @@ +import unittest +from unittest import mock +from wqflask import app +from wqflask.marker_regression.rqtl_mapping import get_trait_data_type +from wqflask.marker_regression.rqtl_mapping import sanitize_rqtl_phenotype +from wqflask.marker_regression.rqtl_mapping import sanitize_rqtl_names + +class TestRqtlMapping(unittest.TestCase): + + def setUp(self): + self.app_context=app.app_context() + self.app_context.push() + + def tearDown(self): + self.app_context.pop() + + + @mock.patch("wqflask.marker_regression.rqtl_mapping.g") + @mock.patch("wqflask.marker_regression.rqtl_mapping.logger") + def test_get_trait_data_type_found(self,mock_logger,mock_db): + caller_value="""SELECT value FROM TraitMetadata WHERE type='trait_data_type'""" + mock_db.db.execute.return_value.fetchone.return_value=["""{"type":"trait_data_type","name":"T1","traid_id":"fer434f"}"""] + results=get_trait_data_type("traid_id") + mock_db.db.execute.assert_called_with(caller_value) + self.assertEqual(results,"fer434f") + + + @mock.patch("wqflask.marker_regression.rqtl_mapping.g") + @mock.patch("wqflask.marker_regression.rqtl_mapping.logger") + def test_get_trait_data_type_not_found(self,mock_logger,mock_db): + caller_value="""SELECT value FROM TraitMetadata WHERE type='trait_data_type'""" + mock_db.db.execute.return_value.fetchone.return_value=["""{"type":"trait_data_type","name":"T1","traid_id":"fer434f"}"""] + results=get_trait_data_type("other") + mock_db.db.execute.assert_called_with(caller_value) + self.assertEqual(results,"numeric") + + def test_sanitize_rqtl_phenotype(self): + vals=['f',"x","r","x","x"] + results=sanitize_rqtl_phenotype(vals) + expected_phenotype_string='c(f,NA,r,NA,NA)' + + self.assertEqual(results,expected_phenotype_string) + + def test_sanitize_rqtl_names(self): + vals=['f',"x","r","x","x"] + expected_sanitized_name="c('f',NA,'r',NA,NA)" + results=sanitize_rqtl_names(vals) + self.assertEqual(expected_sanitized_name,results) + + + + + + + -- cgit v1.2.3