From d080436fa5640522c45b1d8bb90e9ca20ba06d5d Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 17 Dec 2020 01:26:47 +0300 Subject: remove test for parse_gemma_output and modify run_gemma tests (#533) --- .../marker_regression/test_gemma_mapping.py | 32 ++-------------------- 1 file changed, 2 insertions(+), 30 deletions(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/marker_regression/test_gemma_mapping.py b/wqflask/tests/unit/wqflask/marker_regression/test_gemma_mapping.py index b8c13ab4..eab6afe6 100644 --- a/wqflask/tests/unit/wqflask/marker_regression/test_gemma_mapping.py +++ b/wqflask/tests/unit/wqflask/marker_regression/test_gemma_mapping.py @@ -5,7 +5,6 @@ from unittest import mock from wqflask.marker_regression.gemma_mapping import run_gemma from wqflask.marker_regression.gemma_mapping import gen_pheno_txt_file from wqflask.marker_regression.gemma_mapping import gen_covariates_file -from wqflask.marker_regression.gemma_mapping import parse_gemma_output from wqflask.marker_regression.gemma_mapping import parse_loco_output @@ -69,11 +68,9 @@ class TestGemmaMapping(unittest.TestCase): mock_parse_loco.return_value = [] results = run_gemma(this_trait=trait, this_dataset=dataset, samples=[ ], vals=[], covariates="", use_loco=True) - system_calls = [mock.call('ghc --json -- -debug -g /home/genotype/bimbam/file_geno.txt -p /home/user/data//gn2/trait1_dataset1_name_pheno.txt -a /home/genotype/bimbam/file_snps.txt -gk > /home/user/data//gn2/GP1_K_RRRRRR.json'), - mock.call('ghc --json --input /home/user/data//gn2/GP1_K_RRRRRR.json -- -debug -a /home/genotype/bimbam/file_snps.txt -lmm 2 -g /home/genotype/bimbam/file_geno.txt -p /home/user/data//gn2/trait1_dataset1_name_pheno.txt > /home/user/data//gn2/GP1_GWA_RRRRRR.json')] - mock_os.system.assert_has_calls(system_calls) + self.assertEqual(mock_os.system.call_count,2) mock_gen_pheno_txt.assert_called_once() - mock_parse_loco.assert_called_once_with(dataset, "GP1_GWA_RRRRRR") + mock_parse_loco.assert_called_once_with(dataset, "GP1_GWA_RRRRRR",True) mock_os.path.isfile.assert_called_once_with( ('/home/user/imgfile_output.assoc.txt')) self.assertEqual(mock_flat_files.call_count, 4) @@ -138,31 +135,6 @@ class TestGemmaMapping(unittest.TestCase): filehandler.write.assert_has_calls([mock.call( '-9\t'), mock.call('-9\t'), mock.call('-9\t'), mock.call('-9\t'), mock.call('\n')]) - @mock.patch("wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img/") - def test_parse_gemma_output(self): - """add test for generating gemma output with obj returned""" - file = """X/Y\t gn2\t21\tQ\tE\tA\tP\tMMB\tCDE\t0.5 -X/Y\tgn2\t21322\tQ\tE\tA\tP\tMMB\tCDE\t0.5 -chr\tgn1\t12312\tQ\tE\tA\tP\tMMB\tCDE\t0.7 -X\tgn7\t2324424\tQ\tE\tA\tP\tMMB\tCDE\t0.4 -125\tgn9\t433575\tQ\tE\tA\tP\tMMB\tCDE\t0.67 -""" - with mock.patch("builtins.open", mock.mock_open(read_data=file)) as mock_open: - results = parse_gemma_output(genofile_name="gema_file") - expected = [{'name': ' gn2', 'chr': 'X/Y', 'Mb': 2.1e-05, 'p_value': 0.5, 'lod_score': 0.3010299956639812}, {'name': 'gn2', 'chr': 'X/Y', 'Mb': 0.021322, 'p_value': 0.5, 'lod_score': 0.3010299956639812}, - {'name': 'gn7', 'chr': 'X', 'Mb': 2.324424, 'p_value': 0.4, 'lod_score': 0.3979400086720376}, {'name': 'gn9', 'chr': 125, 'Mb': 0.433575, 'p_value': 0.67, 'lod_score': 0.17392519729917352}] - mock_open.assert_called_once_with( - "/home/user/img/gema_file_output.assoc.txt") - self.assertEqual(results, expected) - - @mock.patch("wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img") - def test_parse_gemma_output_with_empty_return(self): - """add tests for parse gemma output where nothing returned""" - output_file_results = """chr\t today""" - with mock.patch("builtins.open", mock.mock_open(read_data=output_file_results)) as mock_open: - results = parse_gemma_output(genofile_name="gema_file") - self.assertEqual(results, []) - @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/tmp") @mock.patch("wqflask.marker_regression.gemma_mapping.os") @mock.patch("wqflask.marker_regression.gemma_mapping.json") -- cgit v1.2.3 From dd2c510ea09ea3169cac3685b299640226d5606a Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Sun, 27 Dec 2020 23:17:36 +0300 Subject: update tests for run gemma --- .../wqflask/marker_regression/test_gemma_mapping.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/marker_regression/test_gemma_mapping.py b/wqflask/tests/unit/wqflask/marker_regression/test_gemma_mapping.py index eab6afe6..fe2569b8 100644 --- a/wqflask/tests/unit/wqflask/marker_regression/test_gemma_mapping.py +++ b/wqflask/tests/unit/wqflask/marker_regression/test_gemma_mapping.py @@ -144,21 +144,26 @@ class TestGemmaMapping(unittest.TestCase): "files": [["file_name", "user", "~/file1"], ["file_name", "user", "~/file2"]] } - return_file_1 = """X/Y\t L1\t21\tQ\tE\tA\tP\tMMB\tCDE\t0.5 -X/Y\tL2\t21322\tQ\tE\tA\tP\tMMB\tCDE\t0.5 -chr\tL3\t12312\tQ\tE\tA\tP\tMMB\tCDE\t0.7""" - return_file_2 = """chr\tother\t21322\tQ\tE\tA\tP\tMMB\tCDE\t0.5""" + return_file="""X/Y\tM1\t28.457155\tQ\tE\tA\tMMB\t23.3\tW\t0.9\t0.85\t +chr4\tM2\t12\tQ\tE\tMMB\tR\t24\tW\t0.87\t0.5 +Y\tM4\t12\tQ\tE\tMMB\tR\t11.6\tW\t0.21\t0.7 +X\tM5\t12\tQ\tE\tMMB\tR\t21.1\tW\t0.65\t0.6""" + + return_file_2 = """chr\tother\t21322\tQ\tE\tA\tP\tMMB\tCDE\t0.5\t0.4""" mock_os.path.isfile.return_value = True file_to_write = """{"files":["file_1","file_2"]}""" with mock.patch("builtins.open") as mock_open: handles = (mock.mock_open(read_data="gwas").return_value, mock.mock_open( - read_data=return_file_1).return_value, mock.mock_open(read_data=return_file_2).return_value) + read_data=return_file).return_value, mock.mock_open(read_data=return_file_2).return_value) mock_open.side_effect = handles results = parse_loco_output( this_dataset={}, gwa_output_filename=".xw/") - expected_results = [{'name': ' L1', 'chr': 'X/Y', 'Mb': 2.1e-05, 'p_value': 0.5, 'lod_score': 0.3010299956639812}, { - 'name': 'L2', 'chr': 'X/Y', 'Mb': 0.021322, 'p_value': 0.5, 'lod_score': 0.3010299956639812}] + expected_results= [ + {'name': 'M1', 'chr': 'X/Y', 'Mb': 2.8457155e-05, 'p_value': 0.85, 'additive': 23.3, 'lod_score': 0.07058107428570727}, + {'name': 'M2', 'chr': 4, 'Mb': 1.2e-05, 'p_value': 0.5, 'additive': 24.0, 'lod_score': 0.3010299956639812}, + {'name': 'M4', 'chr': 'Y', 'Mb': 1.2e-05, 'p_value': 0.7, 'additive': 11.6, 'lod_score': 0.1549019599857432}, + {'name': 'M5', 'chr': 'X', 'Mb': 1.2e-05, 'p_value': 0.6, 'additive': 21.1, 'lod_score': 0.22184874961635637}] self.assertEqual(expected_results, results) -- cgit v1.2.3 From 7032f7b05deac0bbd2e868ffd3fe42dd1c97fb7d Mon Sep 17 00:00:00 2001 From: uditgulati Date: Tue, 5 Jan 2021 13:14:08 -0600 Subject: add server side class unit tests --- wqflask/tests/unit/wqflask/test_server_side.py | 31 ++++++++++++++++++++++++++ wqflask/wqflask/server_side.py | 16 ++++++------- 2 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 wqflask/tests/unit/wqflask/test_server_side.py (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/test_server_side.py b/wqflask/tests/unit/wqflask/test_server_side.py new file mode 100644 index 00000000..4f91d8ca --- /dev/null +++ b/wqflask/tests/unit/wqflask/test_server_side.py @@ -0,0 +1,31 @@ +import unittest + +from wqflask.server_side import ServerSideTable + + +class TestServerSideTableTests(unittest.TestCase): + """ + Test the ServerSideTable class + + test table: + first, second, third + 'd', 4, 'zz' + 'b', 2, 'aa' + 'c', 1, 'ss' + """ + + def test_get_page(self): + rows_count = 3 + table_rows = [ + {'first': 'd', 'second': 4, 'third': 'zz'}, + {'first': 'b', 'second': 2, 'third': 'aa'}, + {'first': 'c', 'second': 1, 'third': 'ss'}, + ] + headers = ['first', 'second', 'third'] + request_args = {'sEcho': '1', 'iSortCol_0': '1', 'iSortingCols': '1', 'sSortDir_0': 'asc', 'iDisplayStart': '0', 'iDisplayLength': '3'} + + test_page = ServerSideTable(rows_count, table_rows, headers, request_args).get_page() + self.assertEqual(test_page['sEcho'], '1') + self.assertEqual(test_page['iTotalRecords'], 'nan') + self.assertEqual(test_page['iTotalDisplayRecords'], '3') + self.assertEqual(test_page['data'], [{'first': 'b', 'second': 2, 'third': 'aa'}, {'first': 'c', 'second': 1, 'third': 'ss'}, {'first': 'd', 'second': 4, 'third': 'zz'}]) diff --git a/wqflask/wqflask/server_side.py b/wqflask/wqflask/server_side.py index 824b00aa..5f764767 100644 --- a/wqflask/wqflask/server_side.py +++ b/wqflask/wqflask/server_side.py @@ -3,7 +3,7 @@ class ServerSideTable(object): - ''' + """ This class is used to do server-side processing on the DataTables table such as paginating, sorting, filtering(not implemented) etc. This takes the load off @@ -22,7 +22,7 @@ class ServerSideTable(object): Have a look at snp_browser_table() function in wqflask/wqflask/views.py for reference use. - ''' + """ def __init__(self, rows_count, table_rows, header_data_names, request_values): self.request_values = request_values @@ -36,12 +36,12 @@ class ServerSideTable(object): self.paginate_rows() def sort_rows(self): - ''' + """ Sorts the rows taking in to account the column (or columns) that the user has selected. - ''' + """ def is_reverse(str_direction): - ''' Maps the 'desc' and 'asc' words to True or False. ''' + """ Maps the 'desc' and 'asc' words to True or False. """ return True if str_direction == 'desc' else False if (self.request_values['iSortCol_0'] != "") and (int(self.request_values['iSortingCols']) > 0): @@ -54,12 +54,12 @@ class ServerSideTable(object): reverse=is_reverse(sort_direction)) def paginate_rows(self): - ''' + """ Selects a subset of the filtered and sorted data based on if the table has pagination, the current page and the size of each page. - ''' + """ def requires_pagination(): - ''' Check if the table is going to be paginated ''' + """ Check if the table is going to be paginated """ if self.request_values['iDisplayStart'] != "": if int(self.request_values['iDisplayLength']) != -1: return True -- cgit v1.2.3 From 2bd74f8f4e4e72a11c77d4f3e8532c303503ca11 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Mon, 16 Nov 2020 13:46:57 +0300 Subject: add unit tests for api/mapping.py --- wqflask/tests/unit/wqflask/api/test_mapping.py | 114 +++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 wqflask/tests/unit/wqflask/api/test_mapping.py (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/api/test_mapping.py b/wqflask/tests/unit/wqflask/api/test_mapping.py new file mode 100644 index 00000000..87b18e84 --- /dev/null +++ b/wqflask/tests/unit/wqflask/api/test_mapping.py @@ -0,0 +1,114 @@ +import unittest +from unittest import mock +from wqflask.api.mapping import initialize_parameters + + +class AttributeSetter: + def __init__(self,obj): + for key,value in obj.items(): + setattr(self,key,value) + +class MockGroup(AttributeSetter): + def get_marker(self): + return None +class TestMock(unittest.TestCase): + + # @mock.patch("wqflask.api.mapping.gemma_mapping") + # @mock.patch("wqflask.api.mapping.nitialize_parameters") + # @mock.patch("wqflask.api.mapping.retrieve_sample_data") + # @mock.patch("wqflask.api.mapping.create_trait") + # @mock.patch("wqflask.api.mapping.data_set") + # def test_do_mapping_for_api(self,mock_dataset,mock_create_trait,mock_retrieve_data,mock_gemma): + + # start_vars={ + # "db":"sql_uri/db_web1", + # "trait_id":"idsui332rh3ui2t", + # "limit_to":32.1, + # } + # group_samplelist=["S1","S2","S3","S4"] + # dataset_group=MockGroup({"samplelist":group_samplelist}) + # dataset=AttributeSetter({"type":"Temp","group":dataset_group}) + + # this_trait_data={ + # "Item1":AttributeSetter({ + # "name":"S1", + # "value":"V1" + # }), + + # "Item2":AttributeSetter({ + # "name":"S2", + # "value":"V2" + # }), + + # "Item3":AttributeSetter({ + # "name":"SX", + # "value":"VX" + # }) + # } + + # this_trait=AttributeSetter({"data":this_trait_data}) + + + # mock_dataset.create_dataset.return_value=dataset + + # mock_create_trait.return_value=this_trait + # mock_retrieve_data.return_value=this_trait + + # mock_initialize_params={ + # "format":"json", + # "limit_to":32.1, + # "mapping_method":"gemma", + # "maf":0.01, + # "use_loco":True, + # "num_perm":0, + # "perm_check":False + + # } + + # mock_gemma.return_value=[ ,"filename"] + # pass + + def test_initialize_parameters(self): + expected_results={ + "format":"json", + "limit_to":False, + "mapping_method":"gemma", + "maf":0.01, + "use_loco":True, + "num_perm":0, + "perm_check":False + } + + results=initialize_parameters(start_vars={},dataset={},this_trait={}) + self.assertEqual(results,expected_results) + + start_vars={ + "format":"F1", + "limit_to":"1", + "mapping_method":"rqtl", + "control_marker":True, + "pair_scan":"true", + "interval_mapping":"true", + "use_loco":"true", + "num_perm":"14" + + } + + results_2=initialize_parameters(start_vars=start_vars,dataset={},this_trait={}) + expected_results={ + "format":"F1", + "limit_to":1, + "mapping_method":"gemma", + "maf":0.01, + "use_loco":True, + "num_perm":14, + "perm_check":"ON" + } + + self.assertEqual(results_2,expected_results) + + + + + + -- cgit v1.2.3 From df2c3f9ee43dd055f7766eedee32d76090ad80b2 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Mon, 16 Nov 2020 13:47:40 +0300 Subject: add unit testsfor api/correlation.py --- wqflask/tests/unit/wqflask/api/test_correlation.py | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 wqflask/tests/unit/wqflask/api/test_correlation.py (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/api/test_correlation.py b/wqflask/tests/unit/wqflask/api/test_correlation.py new file mode 100644 index 00000000..482dec67 --- /dev/null +++ b/wqflask/tests/unit/wqflask/api/test_correlation.py @@ -0,0 +1,83 @@ +import unittest +from unittest import mock +from wqflask import app +from wqflask.api.correlation import init_corr_params +from wqflask.api.correlation import convert_to_mouse_gene_id +from wqflask.api.correlation import do_literature_correlation_for_all_traits + + +class AttributeSetter: + def __init__(self, obj): + for k, v in obj.items(): + setattr(self, k, v) + + +class TestCorrelations(unittest.TestCase): + def setUp(self): + self.app_context = app.app_context() + self.app_context.push() + + def tearDown(self): + self.app_context.pop() + + def test_init_corr_params(self): + start_vars = { + "return_count": "3", + "type": "T1", + "method": "spearman" + } + + corr_params_results = init_corr_params(start_vars=start_vars) + expected_results = { + "return_count": 3, + "type": "T1", + "method": "spearman" + } + + self.assertEqual(corr_params_results, expected_results) + + @mock.patch("wqflask.api.correlation.g") + def test_convert_to_mouse_gene_id(self, mock_db): + + results = convert_to_mouse_gene_id(species="Other", gene_id="") + self.assertEqual(results, None) + + rat_species_results = convert_to_mouse_gene_id( + species="rat", gene_id="GH1") + + mock_db.db.execute.return_value.fetchone.side_effect = [AttributeSetter({"mouse": "MG-1"}),AttributeSetter({"mouse":"MG-2"})] + + self.assertEqual(convert_to_mouse_gene_id( + species="mouse", gene_id="MG-4"), "MG-4") + self.assertEqual(convert_to_mouse_gene_id( + species="rat", gene_id="R1"), "MG-1") + self.assertEqual(convert_to_mouse_gene_id( + species="human", gene_id="H1"), "MG-2") + + + + @mock.patch("wqflask.api.correlation.g") + @mock.patch("wqflask.api.correlation.convert_to_mouse_gene_id") + def test_do_literature_correlation_for_all_traits(self,mock_convert_to_mouse_geneid,mock_db): + mock_convert_to_mouse_geneid.side_effect=["MG-1","MG-2;","MG-3","MG-4"] + + + trait_geneid_dict={ + "TT-1":"GH-1", + "TT-2":"GH-2", + "TT-3":"GH-3" + + } + mock_db.db.execute.return_value.fetchone.side_effect=[AttributeSetter({"value":"V1"}),AttributeSetter({"value":"V2"}),AttributeSetter({"value":"V3"})] + + + this_trait=AttributeSetter({"geneid":"GH-1"}) + + target_dataset=AttributeSetter({"group":AttributeSetter({"species":"rat"})}) + results=do_literature_correlation_for_all_traits(this_trait=this_trait,target_dataset=target_dataset,trait_geneid_dict=trait_geneid_dict,corr_params={}) + + expected_results={'TT-1': ['GH-1', 0], 'TT-2': ['GH-2', 'V1'], 'TT-3': ['GH-3', 'V2']} + self.assertEqual(results,expected_results) + + + -- cgit v1.2.3 From 3eda2b13e10937cbd661d6d411286c5b84bcd7cf Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Sat, 28 Nov 2020 15:00:00 +0300 Subject: add correlation test --- .../correlation/test_correlation_functions.py | 21 +++++ .../wqflask/correlation/test_show_corr_results.py | 95 ++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 wqflask/tests/unit/wqflask/correlation/test_correlation_functions.py create mode 100644 wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/correlation/test_correlation_functions.py b/wqflask/tests/unit/wqflask/correlation/test_correlation_functions.py new file mode 100644 index 00000000..db449eb1 --- /dev/null +++ b/wqflask/tests/unit/wqflask/correlation/test_correlation_functions.py @@ -0,0 +1,21 @@ +import unittest +from unittest import mock +from wqflask.correlation.correlation_functions import get_trait_symbol_and_tissue_values +from wqflask.correlation.correlation_functions import cal_zero_order_corr_for_tiss + + +class TestCorrelationFunctions(unittest.TestCase): + + + @mock.patch("wqflask.correlation.correlation_functions.MrnaAssayTissueData") + def test_get_trait_symbol_and_tissue_values(self, mock_class): + """test for getting trait symbol and tissue_values""" + mock_class_instance = mock_class.return_value + mock_class_instance.gene_symbols = ["k1", "k2", "k3"] + mock_class_instance.get_symbol_values_pairs.return_value = { + "k1": ["v1", "v2", "v3"], "k2": ["v2", "v3"], "k3": ["k3"]} + results = get_trait_symbol_and_tissue_values( + symbol_list=["k1", "k2", "k3"]) + mock_class.assert_called_with(gene_symbols=['k1', 'k2', 'k3']) + self.assertEqual({"k1": ["v1", "v2", "v3"], "k2": [ + "v2", "v3"], "k3": ["k3"]}, results) diff --git a/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py b/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py new file mode 100644 index 00000000..4e63207e --- /dev/null +++ b/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py @@ -0,0 +1,95 @@ +import unittest +from unittest import mock +from wqflask.correlation.show_corr_results import get_header_fields +from wqflask.correlation.show_corr_results import generate_corr_json +from wqflask.correlation.show_corr_results import do_bicor + + +class Trait: + def __init__(self,trait_obj): + for key,value in trait_obj.items(): + setattr(self,key,value) + +class TestShowCorrResults(unittest.TestCase): + + def test_process_samples(self): + pass + def test_get_header_fields(self): + expected=[ + ['Index', + 'Record', + 'Symbol', + 'Description', + 'Location', + 'Mean', + 'Sample rho', + 'N', + 'Sample p(rho)', + 'Lit rho', + 'Tissue rho', + 'Tissue p(rho)', + 'Max LRS', + 'Max LRS Location', + 'Additive Effect'], + + ['Index', + 'ID', + 'Location', + 'Sample r', + 'N', + 'Sample p(r)'] + + ] + result1=get_header_fields("ProbeSet","spearman") + result2=get_header_fields("Other","Other") + self.assertEqual(result1,expected[0]) + self.assertEqual(result2,expected[1]) + + + + + def test_generate_corr_json(self): + this_trait=Trait({"name":"trait_test"}) + dataset=Trait({"name":"the_name"}) + target_dataset=Trait({"type":"Publish"}) + + trait_with_publish={ + "description_display":"Trait 2 description", + "authors":"trait_2 ", + "pubmed_id":"34n4nn31hn43", + "lrs_location":"N/A", + "additive":"", + "sample_r":100, + "num_overlap":3.2, + "view":True, + "name":"trait_1", + "pubmed_text":"2016", + "additive":"", + "sample_r":10.5, + "LRS_score_repr":"N/A", + "LRS_location_repr":"N/A", + "sample_p":5, + "num_overlap":"num_1" + + + + } + expected_results="""[{"trait_id": "trait_1", "description": "Trait 2 description", "authors": "trait_2 ", "pubmed_id": "34n4nn31hn43", "year": "2016", "lrs_score": "N/A", "lrs_location": "N/A", "additive": "N/A", "sample_r": "10.500", "num_overlap": "num_1", "sample_p": "5.000e+00"}]""" + + corr_results=[Trait(trait_with_publish)] + results=generate_corr_json(corr_results=corr_results,this_trait=this_trait,dataset=dataset,target_dataset=target_dataset,for_api=True) + self.assertEqual(results,expected_results) + + + + def test_generate_corr_json_view_false(self): + trait=Trait({"view":False}) + corr_results=[trait] + this_trait=Trait({"name":"trait_test"}) + dataset=Trait({"name":"the_name"}) + + + results_where_view_is_false=generate_corr_json(corr_results=corr_results,this_trait=this_trait,dataset={},target_dataset={},for_api=False) + + # self.assertEqual(results,[]) + self.assertEqual(results_where_view_is_false,"[]") \ No newline at end of file -- cgit v1.2.3 From 1666f8d50df090e9a14dbf0f4f195bac079de058 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Sat, 28 Nov 2020 15:11:06 +0300 Subject: add test in api/mapping --- wqflask/tests/unit/wqflask/api/test_mapping.py | 55 -------------------------- 1 file changed, 55 deletions(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/api/test_mapping.py b/wqflask/tests/unit/wqflask/api/test_mapping.py index 87b18e84..4da1725f 100644 --- a/wqflask/tests/unit/wqflask/api/test_mapping.py +++ b/wqflask/tests/unit/wqflask/api/test_mapping.py @@ -13,61 +13,6 @@ class MockGroup(AttributeSetter): return None class TestMock(unittest.TestCase): - # @mock.patch("wqflask.api.mapping.gemma_mapping") - # @mock.patch("wqflask.api.mapping.nitialize_parameters") - # @mock.patch("wqflask.api.mapping.retrieve_sample_data") - # @mock.patch("wqflask.api.mapping.create_trait") - # @mock.patch("wqflask.api.mapping.data_set") - # def test_do_mapping_for_api(self,mock_dataset,mock_create_trait,mock_retrieve_data,mock_gemma): - - # start_vars={ - # "db":"sql_uri/db_web1", - # "trait_id":"idsui332rh3ui2t", - # "limit_to":32.1, - # } - # group_samplelist=["S1","S2","S3","S4"] - # dataset_group=MockGroup({"samplelist":group_samplelist}) - # dataset=AttributeSetter({"type":"Temp","group":dataset_group}) - - # this_trait_data={ - # "Item1":AttributeSetter({ - # "name":"S1", - # "value":"V1" - # }), - - # "Item2":AttributeSetter({ - # "name":"S2", - # "value":"V2" - # }), - - # "Item3":AttributeSetter({ - # "name":"SX", - # "value":"VX" - # }) - # } - - # this_trait=AttributeSetter({"data":this_trait_data}) - - - # mock_dataset.create_dataset.return_value=dataset - - # mock_create_trait.return_value=this_trait - # mock_retrieve_data.return_value=this_trait - - # mock_initialize_params={ - # "format":"json", - # "limit_to":32.1, - # "mapping_method":"gemma", - # "maf":0.01, - # "use_loco":True, - # "num_perm":0, - # "perm_check":False - - # } - - # mock_gemma.return_value=[ ,"filename"] - # pass - def test_initialize_parameters(self): expected_results={ "format":"json", -- cgit v1.2.3 From e535eeeff92bcfa6d6524e44591164de72d38482 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Fri, 4 Dec 2020 18:43:35 +0300 Subject: add test for map_api in api/test_mapping.py --- wqflask/tests/unit/wqflask/api/test_mapping.py | 145 +++++++++++++++++-------- 1 file changed, 99 insertions(+), 46 deletions(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/api/test_mapping.py b/wqflask/tests/unit/wqflask/api/test_mapping.py index 4da1725f..5455b215 100644 --- a/wqflask/tests/unit/wqflask/api/test_mapping.py +++ b/wqflask/tests/unit/wqflask/api/test_mapping.py @@ -1,57 +1,110 @@ import unittest from unittest import mock from wqflask.api.mapping import initialize_parameters +from wqflask.api.mapping import do_mapping_for_api class AttributeSetter: - def __init__(self,obj): - for key,value in obj.items(): - setattr(self,key,value) + def __init__(self,obj): + for key,value in obj.items(): + setattr(self,key,value) class MockGroup(AttributeSetter): - def get_marker(self): - return None -class TestMock(unittest.TestCase): - - def test_initialize_parameters(self): - expected_results={ - "format":"json", - "limit_to":False, - "mapping_method":"gemma", - "maf":0.01, - "use_loco":True, - "num_perm":0, - "perm_check":False - } - - results=initialize_parameters(start_vars={},dataset={},this_trait={}) - self.assertEqual(results,expected_results) - - start_vars={ - "format":"F1", - "limit_to":"1", - "mapping_method":"rqtl", - "control_marker":True, - "pair_scan":"true", - "interval_mapping":"true", - "use_loco":"true", - "num_perm":"14" - - } - - results_2=initialize_parameters(start_vars=start_vars,dataset={},this_trait={}) - expected_results={ - "format":"F1", - "limit_to":1, - "mapping_method":"gemma", - "maf":0.01, - "use_loco":True, - "num_perm":14, - "perm_check":"ON" - } - - self.assertEqual(results_2,expected_results) - + def get_marker(self): + self.markers=[] +class TestMapping(unittest.TestCase): + + def test_initialize_parameters(self): + expected_results={ + "format":"json", + "limit_to":False, + "mapping_method":"gemma", + "maf":0.01, + "use_loco":True, + "num_perm":0, + "perm_check":False + } + + results=initialize_parameters(start_vars={},dataset={},this_trait={}) + self.assertEqual(results,expected_results) + + start_vars={ + "format":"F1", + "limit_to":"1", + "mapping_method":"rqtl", + "control_marker":True, + "pair_scan":"true", + "interval_mapping":"true", + "use_loco":"true", + "num_perm":"14" + + } + + results_2=initialize_parameters(start_vars=start_vars,dataset={},this_trait={}) + expected_results={ + "format":"F1", + "limit_to":1, + "mapping_method":"gemma", + "maf":0.01, + "use_loco":True, + "num_perm":14, + "perm_check":"ON" + } + + self.assertEqual(results_2,expected_results) + + + @mock.patch("wqflask.api.mapping.rqtl_mapping.run_rqtl_geno") + @mock.patch("wqflask.api.mapping.gemma_mapping.run_gemma") + @mock.patch("wqflask.api.mapping.initialize_parameters") + @mock.patch("wqflask.api.mapping.retrieve_sample_data") + @mock.patch("wqflask.api.mapping.create_trait") + @mock.patch("wqflask.api.mapping.data_set.create_dataset") + def test_do_mapping_for_api(self,mock_create_dataset,mock_trait,mock_retrieve_sample,mock_param,run_gemma + ,run_rqtl_geno): + start_vars={ + "db":"Temp", + "trait_id":"dewf3232rff2", + "format":"F1", + "mapping_method":"gemma", + "use_loco":True + + } + sampleList=["S1","S2","S3","S4"] + samplelist=["S1","S2","S4"] + dataset=AttributeSetter({"group":samplelist}) + this_trait=AttributeSetter({}) + trait_data=AttributeSetter({ + "data":{ + "item1":AttributeSetter({"name":"S1","value":"S1_value"}), + "item2":AttributeSetter({"name":"S2","value":"S2_value"}), + "item3":AttributeSetter({"name":"S3","value":"S3_value"}), + + } + }) + trait=AttributeSetter({ + "data":trait_data + }) + + dataset.return_value=dataset + mock_trait.return_value=this_trait + + mock_retrieve_sample.return_value=trait + mock_param.return_value={ + "format":"F1", + "limit_to":False, + "mapping_method":"gemma", + "maf":0.01, + "use_loco":"True", + "num_perm":14, + "perm_check":"ON" + } + + run_gemma.return_value=["results"] + results=do_mapping_for_api(start_vars=start_vars) + self.assertEqual(results,("results",None)) + + -- cgit v1.2.3 From e80e793455d2fc6b51dbe95414a3ba8e72652a83 Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Sat, 12 Dec 2020 21:21:53 +0300 Subject: add tests for getting sample_r and p values --- wqflask/tests/unit/wqflask/api/test_correlation.py | 38 ++++++++++++++++++++++ .../wqflask/correlation/test_show_corr_results.py | 2 -- 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/api/test_correlation.py b/wqflask/tests/unit/wqflask/api/test_correlation.py index 482dec67..077f7fa9 100644 --- a/wqflask/tests/unit/wqflask/api/test_correlation.py +++ b/wqflask/tests/unit/wqflask/api/test_correlation.py @@ -4,6 +4,7 @@ from wqflask import app from wqflask.api.correlation import init_corr_params from wqflask.api.correlation import convert_to_mouse_gene_id from wqflask.api.correlation import do_literature_correlation_for_all_traits +from wqflask.api.correlation import get_sample_r_and_p_values class AttributeSetter: @@ -79,5 +80,42 @@ class TestCorrelations(unittest.TestCase): expected_results={'TT-1': ['GH-1', 0], 'TT-2': ['GH-2', 'V1'], 'TT-3': ['GH-3', 'V2']} self.assertEqual(results,expected_results) + @mock.patch("wqflask.api.correlation.corr_result_helpers.normalize_values") + def test_get_sample_r_and_p_values(self,mock_normalize): + + group=AttributeSetter({"samplelist":["S1","S2","S3","S4","S5","S6","S7"]}) + target_dataset=AttributeSetter({"group":group}) + + target_vals=[3.4, 6.2, 4.1,3.4,1.2,5.6] + trait_data={"S1":AttributeSetter({"value":2.3}),"S2":AttributeSetter({"value":1.1}),"S3":AttributeSetter({"value":6.3}),"S4":AttributeSetter({"value":3.6}),"S5":AttributeSetter({"value":4.1}),"S6":AttributeSetter({"value":5.0})} + this_trait=AttributeSetter({"data":trait_data}) + mock_normalize.return_value=([2.3,1.1,6.3,3.6,4.1,5.0], [3.4,6.2,4.1,3.4,1.2,5.6], 6) + mock_normalize.side_effect=[([2.3,1.1,6.3,3.6,4.1,5.0], [3.4,6.2,4.1,3.4,1.2,5.6], 6),([2.3,1.1,6.3,3.6,4.1,5.0], [3.4,6.2,4.1,3.4,1.2,5.6], 6),([2.3,1.1,1.4], [3.4,6.2,4.1], 3)] + + results_pearsonr=get_sample_r_and_p_values(this_trait=this_trait,this_dataset={},target_vals=target_vals,target_dataset=target_dataset,type="pearson") + results_spearmanr=get_sample_r_and_p_values(this_trait=this_trait,this_dataset={},target_vals=target_vals,target_dataset=target_dataset,type="spearman") + results_num_overlap=get_sample_r_and_p_values(this_trait=this_trait,this_dataset={},target_vals=target_vals,target_dataset=target_dataset,type="pearson") + self.assertEqual(mock_normalize.call_count,3) + + self.assertEqual(results_pearsonr,[-0.21618688834430866, 0.680771605997119, 6]) + self.assertEqual(results_spearmanr,[-0.11595420713048969, 0.826848213385815, 6]) + self.assertEqual(results_num_overlap,None) + + def test_calculate_results(self): + corr_params={ + "type":"pearson" + } + trait_data={ + "T1":3.4, + "T2":6.2, + "T3":4.1, + "T4":3.4, + "T5":1.2, + "T6":5.6 + } + target_vals=[3.4, 6.2, 4.1,3.4,1.2,5.6] + + + diff --git a/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py b/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py index 4e63207e..969a84f5 100644 --- a/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py +++ b/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py @@ -12,8 +12,6 @@ class Trait: class TestShowCorrResults(unittest.TestCase): - def test_process_samples(self): - pass def test_get_header_fields(self): expected=[ ['Index', -- cgit v1.2.3 From 0adae692f2f0ce509b32d6654438213deb3da89b Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Sat, 12 Dec 2020 23:09:04 +0300 Subject: add test for calculating correlation results --- wqflask/tests/unit/wqflask/api/test_correlation.py | 44 +++++++++++++++------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/api/test_correlation.py b/wqflask/tests/unit/wqflask/api/test_correlation.py index 077f7fa9..11c7d82b 100644 --- a/wqflask/tests/unit/wqflask/api/test_correlation.py +++ b/wqflask/tests/unit/wqflask/api/test_correlation.py @@ -1,10 +1,12 @@ import unittest from unittest import mock from wqflask import app +from collections import OrderedDict from wqflask.api.correlation import init_corr_params from wqflask.api.correlation import convert_to_mouse_gene_id from wqflask.api.correlation import do_literature_correlation_for_all_traits from wqflask.api.correlation import get_sample_r_and_p_values +from wqflask.api.correlation import calculate_results class AttributeSetter: @@ -12,6 +14,17 @@ class AttributeSetter: for k, v in obj.items(): setattr(self, k, v) +class MockDataset(AttributeSetter): + def get_trait_data(self): + return None + def retrieve_genes(self,id=None): + return { + "TT-1":"GH-1", + "TT-2":"GH-2", + "TT-3":"GH-3" + + } + class TestCorrelations(unittest.TestCase): def setUp(self): @@ -101,19 +114,24 @@ class TestCorrelations(unittest.TestCase): self.assertEqual(results_spearmanr,[-0.11595420713048969, 0.826848213385815, 6]) self.assertEqual(results_num_overlap,None) - def test_calculate_results(self): - corr_params={ - "type":"pearson" - } - trait_data={ - "T1":3.4, - "T2":6.2, - "T3":4.1, - "T4":3.4, - "T5":1.2, - "T6":5.6 - } - target_vals=[3.4, 6.2, 4.1,3.4,1.2,5.6] + @mock.patch("wqflask.api.correlation.do_literature_correlation_for_all_traits") + def test_calculate_results(self,literature_correlation): + + literature_correlation.return_value={'TT-1': ['GH-1', 0], 'TT-2': ['GH-2', 3], 'TT-3': ['GH-3', 1]} + + + + this_dataset=MockDataset({"group":AttributeSetter({"species":"rat"})}) + target_dataset=MockDataset({"group":AttributeSetter({"species":"rat"})}) + this_trait=AttributeSetter({"geneid":"GH-1"}) + corr_params={"type":"literature"} + sorted_results=calculate_results(this_trait=this_trait,this_dataset=this_dataset,target_dataset=target_dataset,corr_params=corr_params) + expected_results={'TT-2': ['GH-2', 3], 'TT-3': ['GH-3', 1], 'TT-1': ['GH-1', 0]} + + self.assertTrue(isinstance(sorted_results,OrderedDict)) + self.assertEqual(type(sorted_results),OrderedDict) + + -- cgit v1.2.3 From b7e2d17536febbeb47dc91015781cc6fc4647905 Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Sat, 12 Dec 2020 23:36:27 +0300 Subject: replace assertEqual with assertAlmostEqual for floats --- wqflask/tests/unit/wqflask/api/test_correlation.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/api/test_correlation.py b/wqflask/tests/unit/wqflask/api/test_correlation.py index 11c7d82b..9fa848a4 100644 --- a/wqflask/tests/unit/wqflask/api/test_correlation.py +++ b/wqflask/tests/unit/wqflask/api/test_correlation.py @@ -108,10 +108,12 @@ class TestCorrelations(unittest.TestCase): results_pearsonr=get_sample_r_and_p_values(this_trait=this_trait,this_dataset={},target_vals=target_vals,target_dataset=target_dataset,type="pearson") results_spearmanr=get_sample_r_and_p_values(this_trait=this_trait,this_dataset={},target_vals=target_vals,target_dataset=target_dataset,type="spearman") results_num_overlap=get_sample_r_and_p_values(this_trait=this_trait,this_dataset={},target_vals=target_vals,target_dataset=target_dataset,type="pearson") - self.assertEqual(mock_normalize.call_count,3) - - self.assertEqual(results_pearsonr,[-0.21618688834430866, 0.680771605997119, 6]) - self.assertEqual(results_spearmanr,[-0.11595420713048969, 0.826848213385815, 6]) + expected_pearsonr=[-0.21618688834430866, 0.680771605997119, 6] + expected_spearmanr=[-0.11595420713048969, 0.826848213385815, 6] + for i,val in enumerate(expected_pearsonr): + self.assertAlmostEqual(val,results_pearsonr[i]) + for i,val in enumerate(expected_spearmanr): + self.assertAlmostEqual(val,results_spearmanr[i]) self.assertEqual(results_num_overlap,None) @mock.patch("wqflask.api.correlation.do_literature_correlation_for_all_traits") @@ -133,7 +135,6 @@ class TestCorrelations(unittest.TestCase): - -- cgit v1.2.3 From c3bfc7c07bba06c9334350111df0b9444b85b31b Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Sat, 12 Dec 2020 23:56:26 +0300 Subject: modify tests for calculate correlation results --- wqflask/tests/unit/wqflask/api/test_correlation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/api/test_correlation.py b/wqflask/tests/unit/wqflask/api/test_correlation.py index 9fa848a4..cbcd006d 100644 --- a/wqflask/tests/unit/wqflask/api/test_correlation.py +++ b/wqflask/tests/unit/wqflask/api/test_correlation.py @@ -131,7 +131,7 @@ class TestCorrelations(unittest.TestCase): expected_results={'TT-2': ['GH-2', 3], 'TT-3': ['GH-3', 1], 'TT-1': ['GH-1', 0]} self.assertTrue(isinstance(sorted_results,OrderedDict)) - self.assertEqual(type(sorted_results),OrderedDict) + self.assertEqual(dict(sorted_results),expected_results) -- cgit v1.2.3 From d10b6a9bc3ed4d3f824a0dfd115f05ed647aa8c3 Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Mon, 14 Dec 2020 20:08:41 +0300 Subject: pep8 formatting and refactoring tests --- wqflask/tests/unit/wqflask/api/test_correlation.py | 145 +++++++++++---------- 1 file changed, 79 insertions(+), 66 deletions(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/api/test_correlation.py b/wqflask/tests/unit/wqflask/api/test_correlation.py index cbcd006d..d0264b87 100644 --- a/wqflask/tests/unit/wqflask/api/test_correlation.py +++ b/wqflask/tests/unit/wqflask/api/test_correlation.py @@ -1,7 +1,7 @@ import unittest from unittest import mock from wqflask import app -from collections import OrderedDict +from collections import OrderedDict from wqflask.api.correlation import init_corr_params from wqflask.api.correlation import convert_to_mouse_gene_id from wqflask.api.correlation import do_literature_correlation_for_all_traits @@ -14,14 +14,16 @@ class AttributeSetter: for k, v in obj.items(): setattr(self, k, v) + class MockDataset(AttributeSetter): def get_trait_data(self): return None - def retrieve_genes(self,id=None): + + def retrieve_genes(self, id=None): return { - "TT-1":"GH-1", - "TT-2":"GH-2", - "TT-3":"GH-3" + "TT-1": "GH-1", + "TT-2": "GH-2", + "TT-3": "GH-3" } @@ -59,8 +61,9 @@ class TestCorrelations(unittest.TestCase): rat_species_results = convert_to_mouse_gene_id( species="rat", gene_id="GH1") - mock_db.db.execute.return_value.fetchone.side_effect = [AttributeSetter({"mouse": "MG-1"}),AttributeSetter({"mouse":"MG-2"})] - + mock_db.db.execute.return_value.fetchone.side_effect = [ + AttributeSetter({"mouse": "MG-1"}), AttributeSetter({"mouse": "MG-2"})] + self.assertEqual(convert_to_mouse_gene_id( species="mouse", gene_id="MG-4"), "MG-4") self.assertEqual(convert_to_mouse_gene_id( @@ -68,73 +71,83 @@ class TestCorrelations(unittest.TestCase): self.assertEqual(convert_to_mouse_gene_id( species="human", gene_id="H1"), "MG-2") - - @mock.patch("wqflask.api.correlation.g") @mock.patch("wqflask.api.correlation.convert_to_mouse_gene_id") - def test_do_literature_correlation_for_all_traits(self,mock_convert_to_mouse_geneid,mock_db): - mock_convert_to_mouse_geneid.side_effect=["MG-1","MG-2;","MG-3","MG-4"] - - - trait_geneid_dict={ - "TT-1":"GH-1", - "TT-2":"GH-2", - "TT-3":"GH-3" + def test_do_literature_correlation_for_all_traits(self, mock_convert_to_mouse_geneid, mock_db): + mock_convert_to_mouse_geneid.side_effect = [ + "MG-1", "MG-2;", "MG-3", "MG-4"] - } - mock_db.db.execute.return_value.fetchone.side_effect=[AttributeSetter({"value":"V1"}),AttributeSetter({"value":"V2"}),AttributeSetter({"value":"V3"})] + trait_geneid_dict = { + "TT-1": "GH-1", + "TT-2": "GH-2", + "TT-3": "GH-3" + } + mock_db.db.execute.return_value.fetchone.side_effect = [AttributeSetter( + {"value": "V1"}), AttributeSetter({"value": "V2"}), AttributeSetter({"value": "V3"})] - this_trait=AttributeSetter({"geneid":"GH-1"}) + this_trait = AttributeSetter({"geneid": "GH-1"}) - target_dataset=AttributeSetter({"group":AttributeSetter({"species":"rat"})}) - results=do_literature_correlation_for_all_traits(this_trait=this_trait,target_dataset=target_dataset,trait_geneid_dict=trait_geneid_dict,corr_params={}) + target_dataset = AttributeSetter( + {"group": AttributeSetter({"species": "rat"})}) + results = do_literature_correlation_for_all_traits( + this_trait=this_trait, target_dataset=target_dataset, trait_geneid_dict=trait_geneid_dict, corr_params={}) - expected_results={'TT-1': ['GH-1', 0], 'TT-2': ['GH-2', 'V1'], 'TT-3': ['GH-3', 'V2']} - self.assertEqual(results,expected_results) + expected_results = {'TT-1': ['GH-1', 0], + 'TT-2': ['GH-2', 'V1'], 'TT-3': ['GH-3', 'V2']} + self.assertEqual(results, expected_results) @mock.patch("wqflask.api.correlation.corr_result_helpers.normalize_values") - def test_get_sample_r_and_p_values(self,mock_normalize): - - group=AttributeSetter({"samplelist":["S1","S2","S3","S4","S5","S6","S7"]}) - target_dataset=AttributeSetter({"group":group}) - - target_vals=[3.4, 6.2, 4.1,3.4,1.2,5.6] - trait_data={"S1":AttributeSetter({"value":2.3}),"S2":AttributeSetter({"value":1.1}),"S3":AttributeSetter({"value":6.3}),"S4":AttributeSetter({"value":3.6}),"S5":AttributeSetter({"value":4.1}),"S6":AttributeSetter({"value":5.0})} - this_trait=AttributeSetter({"data":trait_data}) - mock_normalize.return_value=([2.3,1.1,6.3,3.6,4.1,5.0], [3.4,6.2,4.1,3.4,1.2,5.6], 6) - mock_normalize.side_effect=[([2.3,1.1,6.3,3.6,4.1,5.0], [3.4,6.2,4.1,3.4,1.2,5.6], 6),([2.3,1.1,6.3,3.6,4.1,5.0], [3.4,6.2,4.1,3.4,1.2,5.6], 6),([2.3,1.1,1.4], [3.4,6.2,4.1], 3)] - - results_pearsonr=get_sample_r_and_p_values(this_trait=this_trait,this_dataset={},target_vals=target_vals,target_dataset=target_dataset,type="pearson") - results_spearmanr=get_sample_r_and_p_values(this_trait=this_trait,this_dataset={},target_vals=target_vals,target_dataset=target_dataset,type="spearman") - results_num_overlap=get_sample_r_and_p_values(this_trait=this_trait,this_dataset={},target_vals=target_vals,target_dataset=target_dataset,type="pearson") - expected_pearsonr=[-0.21618688834430866, 0.680771605997119, 6] - expected_spearmanr=[-0.11595420713048969, 0.826848213385815, 6] - for i,val in enumerate(expected_pearsonr): - self.assertAlmostEqual(val,results_pearsonr[i]) - for i,val in enumerate(expected_spearmanr): - self.assertAlmostEqual(val,results_spearmanr[i]) - self.assertEqual(results_num_overlap,None) + def test_get_sample_r_and_p_values(self, mock_normalize): + + group = AttributeSetter( + {"samplelist": ["S1", "S2", "S3", "S4", "S5", "S6", "S7"]}) + target_dataset = AttributeSetter({"group": group}) + + target_vals = [3.4, 6.2, 4.1, 3.4, 1.2, 5.6] + trait_data = {"S1": AttributeSetter({"value": 2.3}), "S2": AttributeSetter({"value": 1.1}), + "S3": AttributeSetter( + {"value": 6.3}), "S4": AttributeSetter({"value": 3.6}), "S5": AttributeSetter({"value": 4.1}), + "S6": AttributeSetter({"value": 5.0})} + this_trait = AttributeSetter({"data": trait_data}) + mock_normalize.return_value = ([2.3, 1.1, 6.3, 3.6, 4.1, 5.0], + [3.4, 6.2, 4.1, 3.4, 1.2, 5.6], 6) + mock_normalize.side_effect = [([2.3, 1.1, 6.3, 3.6, 4.1, 5.0], + [3.4, 6.2, 4.1, 3.4, 1.2, 5.6], 6), + ([2.3, 1.1, 6.3, 3.6, 4.1, 5.0], + [3.4, 6.2, 4.1, 3.4, 1.2, 5.6], 6), + ([2.3, 1.1, 1.4], [3.4, 6.2, 4.1], 3)] + + results_pearsonr = get_sample_r_and_p_values(this_trait=this_trait, this_dataset={ + }, target_vals=target_vals, target_dataset=target_dataset, type="pearson") + results_spearmanr = get_sample_r_and_p_values(this_trait=this_trait, this_dataset={ + }, target_vals=target_vals, target_dataset=target_dataset, type="spearman") + results_num_overlap = get_sample_r_and_p_values(this_trait=this_trait, this_dataset={ + }, target_vals=target_vals, target_dataset=target_dataset, type="pearson") + expected_pearsonr = [-0.21618688834430866, 0.680771605997119, 6] + expected_spearmanr = [-0.11595420713048969, 0.826848213385815, 6] + for i, val in enumerate(expected_pearsonr): + self.assertAlmostEqual(val, results_pearsonr[i],4) + for i, val in enumerate(expected_spearmanr): + self.assertAlmostEqual(val, results_spearmanr[i],4) + self.assertEqual(results_num_overlap, None) @mock.patch("wqflask.api.correlation.do_literature_correlation_for_all_traits") - def test_calculate_results(self,literature_correlation): - - literature_correlation.return_value={'TT-1': ['GH-1', 0], 'TT-2': ['GH-2', 3], 'TT-3': ['GH-3', 1]} - - - - this_dataset=MockDataset({"group":AttributeSetter({"species":"rat"})}) - target_dataset=MockDataset({"group":AttributeSetter({"species":"rat"})}) - this_trait=AttributeSetter({"geneid":"GH-1"}) - corr_params={"type":"literature"} - sorted_results=calculate_results(this_trait=this_trait,this_dataset=this_dataset,target_dataset=target_dataset,corr_params=corr_params) - expected_results={'TT-2': ['GH-2', 3], 'TT-3': ['GH-3', 1], 'TT-1': ['GH-1', 0]} - - self.assertTrue(isinstance(sorted_results,OrderedDict)) - self.assertEqual(dict(sorted_results),expected_results) - - - - - - + def test_calculate_results(self, literature_correlation): + + literature_correlation.return_value = { + 'TT-1': ['GH-1', 0], 'TT-2': ['GH-2', 3], 'TT-3': ['GH-3', 1]} + + this_dataset = MockDataset( + {"group": AttributeSetter({"species": "rat"})}) + target_dataset = MockDataset( + {"group": AttributeSetter({"species": "rat"})}) + this_trait = AttributeSetter({"geneid": "GH-1"}) + corr_params = {"type": "literature"} + sorted_results = calculate_results( + this_trait=this_trait, this_dataset=this_dataset, target_dataset=target_dataset, corr_params=corr_params) + expected_results = {'TT-2': ['GH-2', 3], + 'TT-3': ['GH-3', 1], 'TT-1': ['GH-1', 0]} + + self.assertTrue(isinstance(sorted_results, OrderedDict)) + self.assertEqual(dict(sorted_results), expected_results) -- cgit v1.2.3 From 4773ac8715896489562df9321b4a4d34ae61d6a7 Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Mon, 14 Dec 2020 20:10:37 +0300 Subject: pep8 formatting in wqflask/api/test_mapping.py --- wqflask/tests/unit/wqflask/api/test_mapping.py | 154 ++++++++++++------------- 1 file changed, 75 insertions(+), 79 deletions(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/api/test_mapping.py b/wqflask/tests/unit/wqflask/api/test_mapping.py index 5455b215..b094294a 100644 --- a/wqflask/tests/unit/wqflask/api/test_mapping.py +++ b/wqflask/tests/unit/wqflask/api/test_mapping.py @@ -5,108 +5,104 @@ from wqflask.api.mapping import do_mapping_for_api class AttributeSetter: - def __init__(self,obj): - for key,value in obj.items(): - setattr(self,key,value) + def __init__(self, obj): + for key, value in obj.items(): + setattr(self, key, value) + class MockGroup(AttributeSetter): def get_marker(self): - self.markers=[] + self.markers = [] + + class TestMapping(unittest.TestCase): - + def test_initialize_parameters(self): - expected_results={ - "format":"json", - "limit_to":False, - "mapping_method":"gemma", - "maf":0.01, - "use_loco":True, - "num_perm":0, - "perm_check":False + expected_results = { + "format": "json", + "limit_to": False, + "mapping_method": "gemma", + "maf": 0.01, + "use_loco": True, + "num_perm": 0, + "perm_check": False } - results=initialize_parameters(start_vars={},dataset={},this_trait={}) - self.assertEqual(results,expected_results) + results = initialize_parameters( + start_vars={}, dataset={}, this_trait={}) + self.assertEqual(results, expected_results) - start_vars={ - "format":"F1", - "limit_to":"1", - "mapping_method":"rqtl", - "control_marker":True, - "pair_scan":"true", - "interval_mapping":"true", - "use_loco":"true", - "num_perm":"14" + start_vars = { + "format": "F1", + "limit_to": "1", + "mapping_method": "rqtl", + "control_marker": True, + "pair_scan": "true", + "interval_mapping": "true", + "use_loco": "true", + "num_perm": "14" } - results_2=initialize_parameters(start_vars=start_vars,dataset={},this_trait={}) - expected_results={ - "format":"F1", - "limit_to":1, - "mapping_method":"gemma", - "maf":0.01, - "use_loco":True, - "num_perm":14, - "perm_check":"ON" + results_2 = initialize_parameters( + start_vars=start_vars, dataset={}, this_trait={}) + expected_results = { + "format": "F1", + "limit_to": 1, + "mapping_method": "gemma", + "maf": 0.01, + "use_loco": True, + "num_perm": 14, + "perm_check": "ON" } - self.assertEqual(results_2,expected_results) + self.assertEqual(results_2, expected_results) - @mock.patch("wqflask.api.mapping.rqtl_mapping.run_rqtl_geno") @mock.patch("wqflask.api.mapping.gemma_mapping.run_gemma") @mock.patch("wqflask.api.mapping.initialize_parameters") @mock.patch("wqflask.api.mapping.retrieve_sample_data") @mock.patch("wqflask.api.mapping.create_trait") @mock.patch("wqflask.api.mapping.data_set.create_dataset") - def test_do_mapping_for_api(self,mock_create_dataset,mock_trait,mock_retrieve_sample,mock_param,run_gemma - ,run_rqtl_geno): - start_vars={ - "db":"Temp", - "trait_id":"dewf3232rff2", - "format":"F1", - "mapping_method":"gemma", - "use_loco":True + def test_do_mapping_for_api(self, mock_create_dataset, mock_trait, mock_retrieve_sample, mock_param, run_gemma, run_rqtl_geno): + start_vars = { + "db": "Temp", + "trait_id": "dewf3232rff2", + "format": "F1", + "mapping_method": "gemma", + "use_loco": True } - sampleList=["S1","S2","S3","S4"] - samplelist=["S1","S2","S4"] - dataset=AttributeSetter({"group":samplelist}) - this_trait=AttributeSetter({}) - trait_data=AttributeSetter({ - "data":{ - "item1":AttributeSetter({"name":"S1","value":"S1_value"}), - "item2":AttributeSetter({"name":"S2","value":"S2_value"}), - "item3":AttributeSetter({"name":"S3","value":"S3_value"}), + sampleList = ["S1", "S2", "S3", "S4"] + samplelist = ["S1", "S2", "S4"] + dataset = AttributeSetter({"group": samplelist}) + this_trait = AttributeSetter({}) + trait_data = AttributeSetter({ + "data": { + "item1": AttributeSetter({"name": "S1", "value": "S1_value"}), + "item2": AttributeSetter({"name": "S2", "value": "S2_value"}), + "item3": AttributeSetter({"name": "S3", "value": "S3_value"}), } - }) - trait=AttributeSetter({ - "data":trait_data - }) - - dataset.return_value=dataset - mock_trait.return_value=this_trait - - mock_retrieve_sample.return_value=trait - mock_param.return_value={ - "format":"F1", - "limit_to":False, - "mapping_method":"gemma", - "maf":0.01, - "use_loco":"True", - "num_perm":14, - "perm_check":"ON" + }) + trait = AttributeSetter({ + "data": trait_data + }) + + dataset.return_value = dataset + mock_trait.return_value = this_trait + + mock_retrieve_sample.return_value = trait + mock_param.return_value = { + "format": "F1", + "limit_to": False, + "mapping_method": "gemma", + "maf": 0.01, + "use_loco": "True", + "num_perm": 14, + "perm_check": "ON" } - run_gemma.return_value=["results"] - results=do_mapping_for_api(start_vars=start_vars) - self.assertEqual(results,("results",None)) - - - - - - - + run_gemma.return_value = ["results"] + results = do_mapping_for_api(start_vars=start_vars) + self.assertEqual(results, ("results", None)) -- cgit v1.2.3 From 6b6820ec9975ae4c7e9628e0d2b41754b0429b0e Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Wed, 16 Dec 2020 11:29:19 +0300 Subject: modify tests for show_corr_results --- wqflask/tests/unit/wqflask/correlation/__init__.py | 0 .../correlation/test_correlation_functions.py | 3 +- .../wqflask/correlation/test_show_corr_results.py | 174 +++++++++++---------- 3 files changed, 90 insertions(+), 87 deletions(-) create mode 100644 wqflask/tests/unit/wqflask/correlation/__init__.py (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/correlation/__init__.py b/wqflask/tests/unit/wqflask/correlation/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/wqflask/tests/unit/wqflask/correlation/test_correlation_functions.py b/wqflask/tests/unit/wqflask/correlation/test_correlation_functions.py index db449eb1..44d2e0fc 100644 --- a/wqflask/tests/unit/wqflask/correlation/test_correlation_functions.py +++ b/wqflask/tests/unit/wqflask/correlation/test_correlation_functions.py @@ -5,8 +5,7 @@ from wqflask.correlation.correlation_functions import cal_zero_order_corr_for_ti class TestCorrelationFunctions(unittest.TestCase): - - + @mock.patch("wqflask.correlation.correlation_functions.MrnaAssayTissueData") def test_get_trait_symbol_and_tissue_values(self, mock_class): """test for getting trait symbol and tissue_values""" diff --git a/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py b/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py index 969a84f5..ffb96dd6 100644 --- a/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py +++ b/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py @@ -2,92 +2,96 @@ import unittest from unittest import mock from wqflask.correlation.show_corr_results import get_header_fields from wqflask.correlation.show_corr_results import generate_corr_json -from wqflask.correlation.show_corr_results import do_bicor -class Trait: - def __init__(self,trait_obj): - for key,value in trait_obj.items(): - setattr(self,key,value) +class AttributeSetter: + def __init__(self, trait_obj): + for key, value in trait_obj.items(): + setattr(self, key, value) -class TestShowCorrResults(unittest.TestCase): - def test_get_header_fields(self): - expected=[ - ['Index', - 'Record', - 'Symbol', - 'Description', - 'Location', - 'Mean', - 'Sample rho', - 'N', - 'Sample p(rho)', - 'Lit rho', - 'Tissue rho', - 'Tissue p(rho)', - 'Max LRS', - 'Max LRS Location', - 'Additive Effect'], - - ['Index', - 'ID', - 'Location', - 'Sample r', - 'N', - 'Sample p(r)'] - - ] - result1=get_header_fields("ProbeSet","spearman") - result2=get_header_fields("Other","Other") - self.assertEqual(result1,expected[0]) - self.assertEqual(result2,expected[1]) - - - - - def test_generate_corr_json(self): - this_trait=Trait({"name":"trait_test"}) - dataset=Trait({"name":"the_name"}) - target_dataset=Trait({"type":"Publish"}) - - trait_with_publish={ - "description_display":"Trait 2 description", - "authors":"trait_2 ", - "pubmed_id":"34n4nn31hn43", - "lrs_location":"N/A", - "additive":"", - "sample_r":100, - "num_overlap":3.2, - "view":True, - "name":"trait_1", - "pubmed_text":"2016", - "additive":"", - "sample_r":10.5, - "LRS_score_repr":"N/A", - "LRS_location_repr":"N/A", - "sample_p":5, - "num_overlap":"num_1" - - - - } - expected_results="""[{"trait_id": "trait_1", "description": "Trait 2 description", "authors": "trait_2 ", "pubmed_id": "34n4nn31hn43", "year": "2016", "lrs_score": "N/A", "lrs_location": "N/A", "additive": "N/A", "sample_r": "10.500", "num_overlap": "num_1", "sample_p": "5.000e+00"}]""" - - corr_results=[Trait(trait_with_publish)] - results=generate_corr_json(corr_results=corr_results,this_trait=this_trait,dataset=dataset,target_dataset=target_dataset,for_api=True) - self.assertEqual(results,expected_results) - - - - def test_generate_corr_json_view_false(self): - trait=Trait({"view":False}) - corr_results=[trait] - this_trait=Trait({"name":"trait_test"}) - dataset=Trait({"name":"the_name"}) - - - results_where_view_is_false=generate_corr_json(corr_results=corr_results,this_trait=this_trait,dataset={},target_dataset={},for_api=False) - - # self.assertEqual(results,[]) - self.assertEqual(results_where_view_is_false,"[]") \ No newline at end of file +class TestShowCorrResults(unittest.TestCase): + def test_get_header_fields(self): + expected = [ + ['Index', + 'Record', + 'Symbol', + 'Description', + 'Location', + 'Mean', + 'Sample rho', + 'N', + 'Sample p(rho)', + 'Lit rho', + 'Tissue rho', + 'Tissue p(rho)', + 'Max LRS', + 'Max LRS Location', + 'Additive Effect'], + + ['Index', + 'ID', + 'Location', + 'Sample r', + 'N', + 'Sample p(r)'] + + ] + result1 = get_header_fields("ProbeSet", "spearman") + result2 = get_header_fields("Other", "Other") + self.assertEqual(result1, expected[0]) + self.assertEqual(result2, expected[1]) + + @mock.patch("wqflask.correlation.show_corr_results.hmac.data_hmac") + def test_generate_corr_json(self, mock_data_hmac): + mock_data_hmac.return_value = "hajsdiau" + + dataset = AttributeSetter({"name": "the_name"}) + this_trait = AttributeSetter( + {"name": "trait_test", "dataset": dataset}) + target_dataset = AttributeSetter({"type": "Publish"}) + corr_trait_1 = AttributeSetter({ + "name": "trait_1", + "dataset": AttributeSetter({"name": "dataset_1"}), + "view": True, + "abbreviation": "T1", + "description_display": "Trait I description", + "authors": "JM J,JYEW", + "pubmed_id": "34n4nn31hn43", + "pubmed_text": "2016", + "pubmed_link": "https://www.load", + "lod_score": "", + "LRS_location_repr": "BXBS", + "additive": "", + "sample_r": 10.5, + "num_overlap": 2, + "sample_p": 5 + + + + + }) + corr_results = [corr_trait_1] + + dataset_type_other = { + "location": "cx-3-4", + "sample_4": 12.32, + "num_overlap": 3, + "sample_p": 10.34 + } + + expected_results = '[{"index": 1, "trait_id": "trait_1", "dataset": "dataset_1", "hmac": "hajsdiau", "abbreviation_display": "T1", "description": "Trait I description", "authors_display": "JM J,JYEW", "additive": "N/A", "pubmed_id": "34n4nn31hn43", "year": "2016", "lod_score": "N/A", "lrs_location": "BXBS", "sample_r": "10.500", "num_overlap": 2, "sample_p": "5.000e+00"}]' + + results1 = generate_corr_json(corr_results=corr_results, this_trait=this_trait, + dataset=dataset, target_dataset=target_dataset, for_api=True) + self.assertEqual(expected_results, results1) + + def test_generate_corr_json_view_false(self): + trait = AttributeSetter({"view": False}) + corr_results = [trait] + this_trait = AttributeSetter({"name": "trait_test"}) + dataset = AttributeSetter({"name": "the_name"}) + + results_where_view_is_false = generate_corr_json( + corr_results=corr_results, this_trait=this_trait, dataset={}, target_dataset={}, for_api=False) + self.assertEqual(results_where_view_is_false, "[]") -- cgit v1.2.3 From f2e4e893f5639f216f8cc6fc57984aaebffd82ef Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Mon, 14 Dec 2020 14:11:23 +0300 Subject: add tests for snp browser --- wqflask/tests/unit/wqflask/snp_browser/__init__.py | 0 .../unit/wqflask/snp_browser/test_snp_browser.py | 84 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 wqflask/tests/unit/wqflask/snp_browser/__init__.py create mode 100644 wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/snp_browser/__init__.py b/wqflask/tests/unit/wqflask/snp_browser/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py b/wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py new file mode 100644 index 00000000..e8751778 --- /dev/null +++ b/wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py @@ -0,0 +1,84 @@ +import unittest +from unittest import mock +from wqflask import app +from wqflask.snp_browser.snp_browser import get_gene_id +from wqflask.snp_browser.snp_browser import get_gene_id_name_dict +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() + self.app_context.push() + + def tearDown(self): + self.app_context.pop() + + + @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 " + results = get_gene_id( + species_id="c9c0f59e-1259-4cba-91e6-831ef1a99c83", gene_name="INSR") + mock_db.db.execute.assert_called_once_with(called_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,{}) + + @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,"") + + @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_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) + + + + + + + + + + + + + + + -- cgit v1.2.3 From db3170eb2fe66d8fd337803a730c18367df1b150 Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Mon, 14 Dec 2020 16:11:07 +0300 Subject: add tests for type checking --- wqflask/tests/unit/utility/test_type_checking.py | 57 ++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 wqflask/tests/unit/utility/test_type_checking.py (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/utility/test_type_checking.py b/wqflask/tests/unit/utility/test_type_checking.py new file mode 100644 index 00000000..1ea11695 --- /dev/null +++ b/wqflask/tests/unit/utility/test_type_checking.py @@ -0,0 +1,57 @@ +import unittest +from utility.type_checking import is_float +from utility.type_checking import is_int +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") + + + + -- cgit v1.2.3 From 868b8cba1cda983d8d401e60e30794529b557c80 Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Mon, 14 Dec 2020 22:36:36 +0300 Subject: modify get_header tests --- .../unit/wqflask/snp_browser/test_snp_browser.py | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'wqflask/tests/unit') 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 e8751778..9ec32c78 100644 --- a/wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py +++ b/wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py @@ -15,6 +15,18 @@ class TestSnpBrowser(unittest.TestCase): def tearDown(self): 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) + @mock.patch("wqflask.snp_browser.snp_browser.g") def test_get_gene_id(self, mock_db): @@ -56,17 +68,6 @@ class TestSnpBrowser(unittest.TestCase): results=get_browser_sample_lists(species_id="12") self.assertEqual(results, {'mouse': [], 'rat': []}) - 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) -- cgit v1.2.3 From 5a73d56fdbe197e99b476d49d4adce9403c8daeb Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Fri, 18 Dec 2020 15:18:19 +0300 Subject: refactor tests and pep8 formatting --- wqflask/tests/unit/utility/test_type_checking.py | 93 ++++++++-------- .../unit/wqflask/snp_browser/test_snp_browser.py | 120 ++++++++++++--------- 2 files changed, 112 insertions(+), 101 deletions(-) (limited to 'wqflask/tests/unit') 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': []}) -- cgit v1.2.3 From b605f52440e84909631b6afdf510a9e513260901 Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Wed, 6 Jan 2021 08:21:44 +0300 Subject: fix tests for show_corr_results --- wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py b/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py index ffb96dd6..33601990 100644 --- a/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py +++ b/wqflask/tests/unit/wqflask/correlation/test_show_corr_results.py @@ -61,6 +61,7 @@ class TestShowCorrResults(unittest.TestCase): "pubmed_text": "2016", "pubmed_link": "https://www.load", "lod_score": "", + "mean": "", "LRS_location_repr": "BXBS", "additive": "", "sample_r": 10.5, @@ -80,7 +81,7 @@ class TestShowCorrResults(unittest.TestCase): "sample_p": 10.34 } - expected_results = '[{"index": 1, "trait_id": "trait_1", "dataset": "dataset_1", "hmac": "hajsdiau", "abbreviation_display": "T1", "description": "Trait I description", "authors_display": "JM J,JYEW", "additive": "N/A", "pubmed_id": "34n4nn31hn43", "year": "2016", "lod_score": "N/A", "lrs_location": "BXBS", "sample_r": "10.500", "num_overlap": 2, "sample_p": "5.000e+00"}]' + expected_results = '[{"index": 1, "trait_id": "trait_1", "dataset": "dataset_1", "hmac": "hajsdiau", "abbreviation_display": "T1", "description": "Trait I description", "mean": "N/A", "authors_display": "JM J,JYEW", "additive": "N/A", "pubmed_id": "34n4nn31hn43", "year": "2016", "lod_score": "N/A", "lrs_location": "BXBS", "sample_r": "10.500", "num_overlap": 2, "sample_p": "5.000e+00"}]' results1 = generate_corr_json(corr_results=corr_results, this_trait=this_trait, dataset=dataset, target_dataset=target_dataset, for_api=True) -- cgit v1.2.3 From 4203e9609dcf59fa7369e9e0dde02d0da3c8e32f Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Wed, 6 Jan 2021 08:50:30 +0300 Subject: update tests for snp_browser --- .../tests/unit/wqflask/snp_browser/test_snp_browser.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'wqflask/tests/unit') 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 496d228f..7fa96dba 100644 --- a/wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py +++ b/wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py @@ -21,18 +21,25 @@ class TestSnpBrowser(unittest.TestCase): "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) + 'Domain 1', 'Domain 2', 'Details'], + ['S1', 'S2', 'S3', 'S4', 'S5']], 5, + ['index', 'snp_name', 'chr', 'mb_formatted', 'alleles', + 'conservation_score', 'domain_1', 'domain_2', + 'function_details', 'S1', 'S2', 'S3', 'S4', 'S5']) 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) + ['Index', 'ID', 'Type', 'InDel Chr', 'Mb Start', + 'Mb End', 'Strand', 'Size', 'Sequence', 'Source'], 0, + ['index', 'indel_name', 'indel_type', 'indel_chr', 'indel_mb_s', + 'indel_mb_e', 'indel_strand', 'indel_size', 'indel_sequence', 'source_name']) self.assertEqual(expected_results, results_with_snp) - self.assertEqual(results_with_indel, expected_results_with_indel) + # self.assertEqual(results_with_indel, expected_results_with_indel) + self.assertEqual(expected_results_with_indel, results_with_indel) @mock.patch("wqflask.snp_browser.snp_browser.g") def test_get_gene_id(self, mock_db): -- cgit v1.2.3 From e55aa51937abf03897a20a52dd7dbf3cfc4ac6c8 Mon Sep 17 00:00:00 2001 From: Alexanderkabui Date: Wed, 6 Jan 2021 08:54:47 +0300 Subject: remove comments --- wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py | 1 - 1 file changed, 1 deletion(-) (limited to 'wqflask/tests/unit') 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 7fa96dba..ce3e7b83 100644 --- a/wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py +++ b/wqflask/tests/unit/wqflask/snp_browser/test_snp_browser.py @@ -38,7 +38,6 @@ class TestSnpBrowser(unittest.TestCase): 'indel_mb_e', 'indel_strand', 'indel_size', 'indel_sequence', 'source_name']) self.assertEqual(expected_results, results_with_snp) - # self.assertEqual(results_with_indel, expected_results_with_indel) self.assertEqual(expected_results_with_indel, results_with_indel) @mock.patch("wqflask.snp_browser.snp_browser.g") -- cgit v1.2.3 From 5187e582721ddfbb1e864378823f2685748bf5f2 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Mon, 18 Jan 2021 11:15:33 +0300 Subject: Pass salt as bytes when testing pbkdf2_hex * wqflask/tests/unit/wqflask/test_pbkdf2.py (test_pbkdf2_hex): Make password salt bytes. Breaking change introduced in 0bac313ba. --- wqflask/tests/unit/wqflask/test_pbkdf2.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/wqflask/test_pbkdf2.py b/wqflask/tests/unit/wqflask/test_pbkdf2.py index a33fbd4f..7ad6c83e 100644 --- a/wqflask/tests/unit/wqflask/test_pbkdf2.py +++ b/wqflask/tests/unit/wqflask/test_pbkdf2.py @@ -11,43 +11,43 @@ class TestPbkdf2(unittest.TestCase): """ for password, salt, iterations, keylen, expected_value in [ - ('password', 'salt', 1, 20, + ('password', b'salt', 1, 20, '0c60c80f961f0e71f3a9b524af6012062fe037a6'), - ('password', 'salt', 2, 20, + ('password', b'salt', 2, 20, 'ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957'), - ('password', 'salt', 4096, 20, + ('password', b'salt', 4096, 20, '4b007901b765489abead49d926f721d065a429c1'), ('passwordPASSWORDpassword', - 'saltSALTsaltSALTsaltSALTsaltSALTsalt', + b'saltSALTsaltSALTsaltSALTsaltSALTsalt', 4096, 25, '3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038'), - ('pass\x00word', 'sa\x00lt', 4096, 16, + ('pass\x00word', b'sa\x00lt', 4096, 16, '56fa6aa75548099dcc37d7f03425e0c3'), - ('password', 'ATHENA.MIT.EDUraeburn', 1, 16, + ('password', b'ATHENA.MIT.EDUraeburn', 1, 16, 'cdedb5281bb2f801565a1122b2563515'), - ('password', 'ATHENA.MIT.EDUraeburn', 1, 32, + ('password', b'ATHENA.MIT.EDUraeburn', 1, 32, ('cdedb5281bb2f80' '1565a1122b256351' '50ad1f7a04bb9f3a33' '3ecc0e2e1f70837')), - ('password', 'ATHENA.MIT.EDUraeburn', 2, 16, + ('password', b'ATHENA.MIT.EDUraeburn', 2, 16, '01dbee7f4a9e243e988b62c73cda935d'), - ('password', 'ATHENA.MIT.EDUraeburn', 2, 32, + ('password', b'ATHENA.MIT.EDUraeburn', 2, 32, ('01dbee7f4a9e243e9' '88b62c73cda935da05' '378b93244ec8f48a99' 'e61ad799d86')), - ('password', 'ATHENA.MIT.EDUraeburn', 1200, 32, + ('password', b'ATHENA.MIT.EDUraeburn', 1200, 32, ('5c08eb61fdf71e' '4e4ec3cf6ba1f55' '12ba7e52ddbc5e51' '42f708a31e2e62b1e13')), - ('X' * 64, 'pass phrase equals block size', 1200, 32, + ('X' * 64, b'pass phrase equals block size', 1200, 32, ('139c30c0966bc32ba' '55fdbf212530ac9c5' 'ec59f1a452f5cc9ad' '940fea0598ed1')), - ('X' * 65, 'pass phrase exceeds block size', 1200, 32, + ('X' * 65, b'pass phrase exceeds block size', 1200, 32, ('9ccad6d468770cd' '51b10e6a68721be6' '11a8b4d282601db3' -- cgit v1.2.3