about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexanderlacuna2020-11-05 22:30:33 +0300
committerAlexanderlacuna2020-11-05 22:30:33 +0300
commit6b4bcc526c27a17f96704b54fbfa6a506b3a22f9 (patch)
treec5eee0f4625c068d4e88540a4a64d9b9248e3ea2
parent510e66de705b90341cd773e666e51dfcf033a958 (diff)
downloadgenenetwork2-6b4bcc526c27a17f96704b54fbfa6a506b3a22f9.tar.gz
add test for samplelist and show_trait
-rw-r--r--wqflask/tests/wqflask/show_trait/testSampleList.py18
-rw-r--r--wqflask/tests/wqflask/show_trait/test_show_trait.py55
2 files changed, 73 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..4cc8c4da
--- /dev/null
+++ b/wqflask/tests/wqflask/show_trait/testSampleList.py
@@ -0,0 +1,18 @@
+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"]
+
+        natural_sort(characters_list)
+        natural_sort(names_list)
+
+        self.assertEqual(characters_list, ["a", "f", "g", "q", "s", "t", "z"])
+        self.assertEqual(names_list, ["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..b1a91bbe 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,57 @@ 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_location_ignore):
+        # test no complete to be continued with
+        # a .geno file
+        mock_location_ignore.return_value = True
+        mock_file_with_one_line = mock.mock_open(
+            read_data="Some data from opened file")
+
+        mock_file = """#@scale and random data:is here_returned\n
+           This is second   with spaced with tabs\n  """
+        mock_file_result = mock.mock_open(read_data=mock_file)
+
+        with mock.patch("builtins.open", mock_file_with_one_line):
+            result = get_scales_from_genofile("~/data/file")
+            self.assertEqual(result, [['morgan', 'cM']])
+
+        with mock.patch("builtins.open", mock_file_result):
+            results = get_scales_from_genofile("~data/file_geno")
+            self.assertEqual(results, [['physic', 'Mb']])
+
+    @mock.patch("wqflask.show_trait.show_trait.locate_ignore_error")
+    def test_get_scales_from_genofile_found(self, mock_ingore_location):
+        """"add test for get scales from genofile where file is found"""
+        mock_ingore_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)