diff options
Diffstat (limited to 'wqflask')
3 files changed, 90 insertions, 87 deletions
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 --- /dev/null +++ b/wqflask/tests/unit/wqflask/correlation/__init__.py 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, "[]") |