aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests
diff options
context:
space:
mode:
authorzsloan2020-11-18 12:49:54 -0600
committerzsloan2020-11-18 12:49:54 -0600
commitd78d7561bd05bdd1e24cd312c7075c16b331b7b6 (patch)
tree7738457c794402cd8e9059c456ddd35a8666160f /wqflask/tests
parent7a2a59f3d225f94bda5a9bc51a958d3203ea690c (diff)
parent8e6a42bfedd465cc8cc9f4963c712377f176c12b (diff)
downloadgenenetwork2-d78d7561bd05bdd1e24cd312c7075c16b331b7b6.tar.gz
Merge branch 'testing' of github.com:genenetwork/genenetwork2 into testing
Diffstat (limited to 'wqflask/tests')
-rw-r--r--wqflask/tests/wqflask/show_trait/testSampleList.py16
-rw-r--r--wqflask/tests/wqflask/show_trait/test_show_trait.py36
2 files changed, 52 insertions, 0 deletions
diff --git a/wqflask/tests/wqflask/show_trait/testSampleList.py b/wqflask/tests/wqflask/show_trait/testSampleList.py
new file mode 100644
index 00000000..34c51e3e
--- /dev/null
+++ b/wqflask/tests/wqflask/show_trait/testSampleList.py
@@ -0,0 +1,16 @@
+import unittest
+import re
+from unittest import mock
+from wqflask.show_trait.SampleList import natural_sort
+
+
+class TestSampleList(unittest.TestCase):
+ def test_natural_sort(self):
+ "Sort the list into natural alphanumeric order."
+
+ characters_list = ["z", "f", "q", "s", "t", "a", "g"]
+ names_list = ["temp1", "publish", "Sample", "Dataset"]
+ sorted_list_a=natural_sort(characters_list)
+ sorted_list_b=natural_sort(names_list)
+ self.assertEqual(sorted_list_a, ["a", "f", "g", "q", "s", "t", "z"])
+ self.assertEqual(sorted_list_b,["Dataset", "Sample", "publish", "temp1"])
diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py
index 24150738..8c866874 100644
--- a/wqflask/tests/wqflask/show_trait/test_show_trait.py
+++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py
@@ -11,6 +11,7 @@ from wqflask.show_trait.show_trait import get_trait_units
from wqflask.show_trait.show_trait import get_nearest_marker
from wqflask.show_trait.show_trait import get_genotype_scales
from wqflask.show_trait.show_trait import requests
+from wqflask.show_trait.show_trait import get_scales_from_genofile
class TraitObject:
@@ -240,3 +241,38 @@ class TestTraits(unittest.TestCase):
expected_results = {f"{file_location}": [["physic", "Mb"]]}
self.assertEqual(get_genotype_scales(file_location), expected_results)
mock_get_scales.assert_called_once_with(file_location)
+
+
+ @mock.patch("wqflask.show_trait.show_trait.locate_ignore_error")
+ def test_get_scales_from_genofile_found(self, mock_ignore_location):
+ """"add test for get scales from genofile where file is found"""
+ mock_ignore_location.return_value = True
+ geno_file = """
+ #sample line with no @scales:other\n
+ #sample line @scales and :separated by semicolon\n
+ This attempts to check whether\n
+ """
+
+ geno_file_string = "@line start with @ and has @scale:morgan"
+
+ file_location = "~/data/file.geno"
+
+ mock_open_geno_file = mock.mock_open(read_data=geno_file)
+ with mock.patch("builtins.open", mock_open_geno_file):
+ results = get_scales_from_genofile(file_location)
+ self.assertEqual(results, [["morgan", "cM"]])
+
+ mock_open_string = mock.mock_open(read_data=geno_file_string)
+
+ with mock.patch("builtins.open", mock_open_string):
+ result2 = get_scales_from_genofile(file_location)
+ self.assertEqual([['morgan', 'cM']], result2)
+
+ @mock.patch("wqflask.show_trait.show_trait.locate_ignore_error")
+ def test_get_scales_from_genofile_not_found(self, mock_location_ignore):
+ mock_location_ignore.return_value = False
+
+ expected_results = [["physic", "Mb"]]
+ results = get_scales_from_genofile("~/data/file")
+ mock_location_ignore.assert_called_once_with("~/data/file", "genotype")
+ self.assertEqual(results, expected_results)