aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests
diff options
context:
space:
mode:
authorAlexanderkabui2020-12-18 15:18:19 +0300
committerBonfaceKilz2021-01-06 01:29:02 +0300
commit5a73d56fdbe197e99b476d49d4adce9403c8daeb (patch)
tree52b370bf254a76213fb57012c037806925e92149 /wqflask/tests
parent868b8cba1cda983d8d401e60e30794529b557c80 (diff)
downloadgenenetwork2-5a73d56fdbe197e99b476d49d4adce9403c8daeb.tar.gz
refactor tests and pep8 formatting
Diffstat (limited to 'wqflask/tests')
-rw-r--r--wqflask/tests/unit/utility/test_type_checking.py93
-rw-r--r--wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py120
2 files changed, 112 insertions, 101 deletions
diff --git a/wqflask/tests/unit/utility/test_type_checking.py b/wqflask/tests/unit/utility/test_type_checking.py
index 1ea11695..48d110c7 100644
--- a/wqflask/tests/unit/utility/test_type_checking.py
+++ b/wqflask/tests/unit/utility/test_type_checking.py
@@ -5,53 +5,50 @@ from utility.type_checking import is_str
from utility.type_checking import get_float
from utility.type_checking import get_int
from utility.type_checking import get_string
-class TestTypeChecking(unittest.TestCase):
- def test_is_float(self):
- floats=[2,1.2,'3.1']
- not_floats=["String",None,[],()]
- for flt in floats:
- results=is_float(flt)
- self.assertTrue(results)
- for nflt in not_floats:
- results=is_float(nflt)
- self.assertFalse(results)
-
- def test_is_int(self):
- int_values=[1,1.1]
- not_int_values=["1sdf",None,[],"1.1"]
- for int_val in int_values:
- results=is_int(int_val)
- self.assertTrue(results)
- for not_int in not_int_values:
- results=is_int(not_int)
- self.assertFalse(results)
-
- def test_is_str(self):
- string_values=[1,False,[],{},"string_value"]
- falsey_values=[None]
- for string_val in string_values:
- results=is_str(string_val)
- self.assertTrue(results)
- for non_string in falsey_values:
- results=is_str(non_string)
- self.assertFalse(results)
-
-
- def test_get_float(self):
- vars_object={"min_value":"12"}
- results=get_float(vars_object,"min_value")
- self.assertEqual(results,12.0)
-
- def test_get_int(self):
- vars_object={"lx_value":"1"}
- results=get_int(vars_object,"lx_value")
- self.assertEqual(results,1)
-
- def test_get_string(self):
- string_object={"mx_value":1}
- results=get_string(string_object,"mx_value")
- self.assertEqual(results,"1")
-
-
+class TestTypeChecking(unittest.TestCase):
+ def test_is_float(self):
+ floats = [2, 1.2, '3.1']
+ not_floats = ["String", None, [], ()]
+ for flt in floats:
+ results = is_float(flt)
+ self.assertTrue(results)
+ for nflt in not_floats:
+ results = is_float(nflt)
+ self.assertFalse(results)
+
+ def test_is_int(self):
+ int_values = [1, 1.1]
+ not_int_values = ["string", None, [], "1.1"]
+ for int_val in int_values:
+ results = is_int(int_val)
+ self.assertTrue(results)
+ for not_int in not_int_values:
+ results = is_int(not_int)
+ self.assertFalse(results)
+
+ def test_is_str(self):
+ string_values = [1, False, [], {}, "string_value"]
+ falsey_values = [None]
+ for string_val in string_values:
+ results = is_str(string_val)
+ self.assertTrue(results)
+ for non_string in falsey_values:
+ results = is_str(non_string)
+ self.assertFalse(results)
+
+ def test_get_float(self):
+ vars_object = {"min_value": "12"}
+ results = get_float(vars_object, "min_value")
+ self.assertEqual(results, 12.0)
+
+ def test_get_int(self):
+ vars_object = {"lx_value": "1"}
+ results = get_int(vars_object, "lx_value")
+ self.assertEqual(results, 1)
+
+ def test_get_string(self):
+ string_object = {"mx_value": 1}
+ results = get_string(string_object, "mx_value")
+ self.assertEqual(results, "1") \ No newline at end of file
diff --git a/wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py b/wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py
index 9ec32c78..496d228f 100644
--- a/wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py
+++ b/wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py
@@ -7,6 +7,7 @@ from wqflask.snp_browser.snp_browser import check_if_in_gene
from wqflask.snp_browser.snp_browser import get_browser_sample_lists
from wqflask.snp_browser.snp_browser import get_header_list
+
class TestSnpBrowser(unittest.TestCase):
def setUp(self):
self.app_context = app.app_context()
@@ -16,70 +17,83 @@ class TestSnpBrowser(unittest.TestCase):
self.app_context.pop()
def test_get_header_list(self):
- empty_columns={"snp_source":"false","conservation_score":"true","gene_name":"false","transcript":"false","exon":"false","domain_2":"true","function":"false","function_details":"true"}
- strains={"mouse":["S1","S2","S3","S4","S5"],"rat":[]}
- expected_results=([['Index', 'SNP ID', 'Chr', 'Mb', 'Alleles', 'ConScore', 'Domain 1', 'Domain 2', 'Details'], ['S1', 'S2', 'S3', 'S4', 'S5']], 5)
-
- results_with_snp=get_header_list(variant_type="SNP",strains=strains,species="Mouse",empty_columns=empty_columns)
- results_with_indel=get_header_list(variant_type="InDel",strains=strains,species="rat",empty_columns=[])
- expected_results_with_indel=(['Index', 'ID', 'Type', 'InDel Chr', 'Mb Start', 'Mb End', 'Strand', 'Size', 'Sequence', 'Source'],0)
-
- self.assertEqual(expected_results,results_with_snp)
- self.assertEqual(results_with_indel,expected_results_with_indel)
-
+ empty_columns = {"snp_source": "false", "conservation_score": "true", "gene_name": "false",
+ "transcript": "false", "exon": "false", "domain_2": "true", "function": "false", "function_details": "true"}
+ strains = {"mouse": ["S1", "S2", "S3", "S4", "S5"], "rat": []}
+ expected_results = ([['Index', 'SNP ID', 'Chr', 'Mb', 'Alleles', 'ConScore',
+ 'Domain 1', 'Domain 2', 'Details'], ['S1', 'S2', 'S3', 'S4', 'S5']], 5)
+
+ results_with_snp = get_header_list(
+ variant_type="SNP", strains=strains, species="Mouse", empty_columns=empty_columns)
+ results_with_indel = get_header_list(
+ variant_type="InDel", strains=strains, species="rat", empty_columns=[])
+ expected_results_with_indel = (
+ ['Index', 'ID', 'Type', 'InDel Chr', 'Mb Start',
+ 'Mb End', 'Strand', 'Size', 'Sequence', 'Source'], 0)
+
+ self.assertEqual(expected_results, results_with_snp)
+ self.assertEqual(results_with_indel, expected_results_with_indel)
@mock.patch("wqflask.snp_browser.snp_browser.g")
def test_get_gene_id(self, mock_db):
mock_db.db.execute.return_value.fetchone.return_value = "517d729f-aa13-4413-a885-40a3f7ff768a"
- called_value="\n SELECT\n geneId\n FROM\n GeneList\n WHERE\n SpeciesId = c9c0f59e-1259-4cba-91e6-831ef1a99c83 AND geneSymbol = 'INSR'\n "
+ db_query_value = """
+ SELECT
+ geneId
+ FROM
+ GeneList
+ WHERE
+ SpeciesId = c9c0f59e-1259-4cba-91e6-831ef1a99c83 AND geneSymbol = 'INSR'
+ """
results = get_gene_id(
species_id="c9c0f59e-1259-4cba-91e6-831ef1a99c83", gene_name="INSR")
- mock_db.db.execute.assert_called_once_with(called_value)
+ mock_db.db.execute.assert_called_once_with(db_query_value)
self.assertEqual(results, "517d729f-aa13-4413-a885-40a3f7ff768a")
@mock.patch("wqflask.snp_browser.snp_browser.g")
- def test_gene_id_name_dict(self,mock_db):
- no_gene_names=[]
- self.assertEqual("",get_gene_id_name_dict(species_id="fregb343bui43g4",gene_name_list=no_gene_names))
- gene_name_list=["GH1","GH2","GH3"]
- mock_db.db.execute.return_value.fetchall.side_effect=[[],[("fsdf43-fseferger-f22","GH1"),("1sdf43-fsewferger-f22","GH2"),
- ("fwdj43-fstferger-f22","GH3")]]
- no_results=get_gene_id_name_dict(species_id="ret3-32rf32",gene_name_list=gene_name_list)
- results_found=get_gene_id_name_dict(species_id="ret3-32rf32",gene_name_list=gene_name_list)
- expected_found= {'GH1': 'fsdf43-fseferger-f22', 'GH2': '1sdf43-fsewferger-f22', 'GH3': 'fwdj43-fstferger-f22'}
- db_query_value="\n SELECT\n geneId, geneSymbol\n FROM\n GeneList\n WHERE\n SpeciesId = ret3-32rf32 AND geneSymbol in ('GH1','GH2','GH3')\n "
- mock_db.db.execute.assert_called_with(db_query_value)
- self.assertEqual(results_found,expected_found)
- self.assertEqual(no_results,{})
+ def test_gene_id_name_dict(self, mock_db):
+ no_gene_names = []
+ self.assertEqual("", get_gene_id_name_dict(
+ species_id="fregb343bui43g4", gene_name_list=no_gene_names))
+ gene_name_list = ["GH1", "GH2", "GH3"]
+ mock_db.db.execute.return_value.fetchall.side_effect = [[], [("fsdf43-fseferger-f22", "GH1"), ("1sdf43-fsewferger-f22", "GH2"),
+ ("fwdj43-fstferger-f22", "GH3")]]
+ no_results = get_gene_id_name_dict(
+ species_id="ret3-32rf32", gene_name_list=gene_name_list)
+ results_found = get_gene_id_name_dict(
+ species_id="ret3-32rf32", gene_name_list=gene_name_list)
+ expected_found = {'GH1': 'fsdf43-fseferger-f22',
+ 'GH2': '1sdf43-fsewferger-f22', 'GH3': 'fwdj43-fstferger-f22'}
+ db_query_value = """
+ SELECT
+ geneId, geneSymbol
+ FROM
+ GeneList
+ WHERE
+ SpeciesId = ret3-32rf32 AND geneSymbol in ('GH1','GH2','GH3')
+ """
+ mock_db.db.execute.assert_called_with(db_query_value)
+ self.assertEqual(results_found, expected_found)
+ self.assertEqual(no_results, {})
@mock.patch("wqflask.snp_browser.snp_browser.g")
- def test_check_if_in_gene(self,mock_db):
- mock_db.db.execute.return_value.fetchone.side_effect=[("fsdf-232sdf-sdf","GHA"),""]
- results_found=check_if_in_gene(species_id="517d729f-aa13-4413-a885-40a3f7ff768a",chr="CH1",mb=12.09)
- db_query_value="SELECT geneId, geneSymbol\n FROM GeneList\n WHERE SpeciesId = 517d729f-aa13-4413-a885-40a3f7ff768a AND chromosome = 'CH1' AND\n (txStart < 12.09 AND txEnd > 12.09); "
- gene_not_found=check_if_in_gene(species_id="517d729f-aa13-4413-a885-40a3f7ff768a",chr="CH1",mb=12.09)
- mock_db.db.execute.assert_called_with(db_query_value)
- self.assertEqual(gene_not_found,"")
+ def test_check_if_in_gene(self, mock_db):
+ mock_db.db.execute.return_value.fetchone.side_effect = [
+ ("fsdf-232sdf-sdf", "GHA"), ""]
+ results_found = check_if_in_gene(
+ species_id="517d729f-aa13-4413-a885-40a3f7ff768a", chr="CH1", mb=12.09)
+ db_query_value = """SELECT geneId, geneSymbol
+ FROM GeneList
+ WHERE SpeciesId = 517d729f-aa13-4413-a885-40a3f7ff768a AND chromosome = 'CH1' AND
+ (txStart < 12.09 AND txEnd > 12.09); """
+ gene_not_found = check_if_in_gene(
+ species_id="517d729f-aa13-4413-a885-40a3f7ff768a", chr="CH1", mb=12.09)
+ mock_db.db.execute.assert_called_with(db_query_value)
+ self.assertEqual(gene_not_found, "")
@mock.patch("wqflask.snp_browser.snp_browser.g")
- def test_get_browser_sample_lists(self,mock_db):
- mock_db.db.execute.return_value.fetchall.return_value=[]
-
- results=get_browser_sample_lists(species_id="12")
- self.assertEqual(results, {'mouse': [], 'rat': []})
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ def test_get_browser_sample_lists(self, mock_db):
+ mock_db.db.execute.return_value.fetchall.return_value = []
+ results = get_browser_sample_lists(species_id="12")
+ self.assertEqual(results, {'mouse': [], 'rat': []})