From 6b4bcc526c27a17f96704b54fbfa6a506b3a22f9 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Thu, 5 Nov 2020 22:30:33 +0300 Subject: add test for samplelist and show_trait --- wqflask/tests/wqflask/show_trait/testSampleList.py | 18 +++++++ .../tests/wqflask/show_trait/test_show_trait.py | 55 ++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 wqflask/tests/wqflask/show_trait/testSampleList.py (limited to 'wqflask/tests') 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) -- cgit v1.2.3 From 162e3e1acc1fea2548f7caa71fa3fc425c0a4ccd Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Thu, 5 Nov 2020 22:47:30 +0300 Subject: remove duplicates --- wqflask/tests/wqflask/show_trait/test_show_trait.py | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'wqflask/tests') diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index b1a91bbe..600baefb 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -242,25 +242,6 @@ class TestTraits(unittest.TestCase): 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): -- cgit v1.2.3 From 7078bd8a2d9d3a2ab8f31e102deeece8bc0e5fcf Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Fri, 6 Nov 2020 00:45:50 +0300 Subject: fix typo --- wqflask/tests/wqflask/show_trait/test_show_trait.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wqflask/tests') diff --git a/wqflask/tests/wqflask/show_trait/test_show_trait.py b/wqflask/tests/wqflask/show_trait/test_show_trait.py index 600baefb..8c866874 100644 --- a/wqflask/tests/wqflask/show_trait/test_show_trait.py +++ b/wqflask/tests/wqflask/show_trait/test_show_trait.py @@ -244,9 +244,9 @@ class TestTraits(unittest.TestCase): @mock.patch("wqflask.show_trait.show_trait.locate_ignore_error") - def test_get_scales_from_genofile_found(self, mock_ingore_location): + def test_get_scales_from_genofile_found(self, mock_ignore_location): """"add test for get scales from genofile where file is found""" - mock_ingore_location.return_value = True + mock_ignore_location.return_value = True geno_file = """ #sample line with no @scales:other\n #sample line @scales and :separated by semicolon\n -- cgit v1.2.3 From 6b23bf4a0698339a1c7672b8d84dfef9b9066a79 Mon Sep 17 00:00:00 2001 From: Alexanderlacuna Date: Fri, 6 Nov 2020 10:59:12 +0300 Subject: modify tests to for changes in the natural sort function --- wqflask/tests/wqflask/show_trait/testSampleList.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'wqflask/tests') diff --git a/wqflask/tests/wqflask/show_trait/testSampleList.py b/wqflask/tests/wqflask/show_trait/testSampleList.py index 4cc8c4da..34c51e3e 100644 --- a/wqflask/tests/wqflask/show_trait/testSampleList.py +++ b/wqflask/tests/wqflask/show_trait/testSampleList.py @@ -10,9 +10,7 @@ class TestSampleList(unittest.TestCase): 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"]) + 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"]) -- cgit v1.2.3