aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexanderlacuna2020-11-11 23:09:01 +0300
committerAlexanderlacuna2020-11-11 23:09:01 +0300
commite63e85868ed7b63bbe784368b3c1babf0d1f2088 (patch)
treea551478b67f548ed2575d7b10f961e1ed44ee563
parent8f85c96b2094a9ce722b93a0e375ec3de90c959a (diff)
downloadgenenetwork2-e63e85868ed7b63bbe784368b3c1babf0d1f2088.tar.gz
add tests for marker_regression/rqtl_mapping.py
-rw-r--r--wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py55
1 files changed, 55 insertions, 0 deletions
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)
+
+
+
+
+
+
+