From ed7232d54e2ec4b4ca0ea970361201b3fe24b9dd Mon Sep 17 00:00:00 2001 From: Kyle Swanson Date: Sat, 3 Feb 2018 08:36:25 -0500 Subject: [PATCH] Tests for all functions --- p_tqdm/__init__.py | 6 +- p_tqdm/tests/tests.py | 166 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 161 insertions(+), 11 deletions(-) diff --git a/p_tqdm/__init__.py b/p_tqdm/__init__.py index 8732cff..ff47670 100644 --- a/p_tqdm/__init__.py +++ b/p_tqdm/__init__.py @@ -154,14 +154,14 @@ def _sequential(function, *arrays, **kwargs): def t_imap(function, *arrays, **kwargs): """Returns an iterator for a sequential map with a progress bar.""" - iterator = sequential(function, *arrays, **kwargs) + iterator = _sequential(function, *arrays, **kwargs) return iterator def t_map(function, *arrays, **kwargs): """Performs a sequential map with a progress bar.""" - iterator = sequential(function, *arrays, **kwargs) - result = list(iteratorZ) + iterator = _sequential(function, *arrays, **kwargs) + result = list(iterator) return result diff --git a/p_tqdm/tests/tests.py b/p_tqdm/tests/tests.py index 2539ba0..7b82b86 100644 --- a/p_tqdm/tests/tests.py +++ b/p_tqdm/tests/tests.py @@ -20,7 +20,10 @@ def _test_one_list(self): result = list(result) correct_array = [2, 3, 4] - self.assertEqual(correct_array, result) + if self.ordered: + self.assertListEqual(correct_array, result) + else: + self.assertListEqual(sorted(correct_array), sorted(result)) def _test_two_lists(self): array_1 = [1, 2, 3] @@ -30,7 +33,10 @@ def _test_two_lists(self): result = list(result) correct_array = [11, 13, 15] - self.assertEqual(correct_array, result) + if self.ordered: + self.assertListEqual(correct_array, result) + else: + self.assertListEqual(sorted(correct_array), sorted(result)) def _test_two_lists_and_one_single(self): array_1 = [1, 2, 3] @@ -41,7 +47,10 @@ def _test_two_lists_and_one_single(self): result = list(result) correct_array = [16, 18, 20] - self.assertEqual(correct_array, result) + if self.ordered: + self.assertListEqual(correct_array, result) + else: + self.assertListEqual(sorted(correct_array), sorted(result)) def _test_one_list_and_two_singles(self): array = [1, 2, 3] @@ -52,7 +61,10 @@ def _test_one_list_and_two_singles(self): result = list(result) correct_array = [4, 5, 6] - self.assertEqual(correct_array, result) + if self.ordered: + self.assertListEqual(correct_array, result) + else: + self.assertListEqual(sorted(correct_array), sorted(result)) def _test_one_single(self): single = 5 @@ -61,7 +73,10 @@ def _test_one_single(self): result = list(result) correct_array = [6] - self.assertEqual(correct_array, result) + if self.ordered: + self.assertListEqual(correct_array, result) + else: + self.assertListEqual(sorted(correct_array), sorted(result)) def _test_one_single_with_num_iter(self): single = 5 @@ -71,7 +86,10 @@ def _test_one_single_with_num_iter(self): result = list(result) correct_array = [6]*num_iter - self.assertEqual(correct_array, result) + if self.ordered: + self.assertListEqual(correct_array, result) + else: + self.assertListEqual(sorted(correct_array), sorted(result)) def _test_two_singles(self): single_1 = 5 @@ -81,7 +99,10 @@ def _test_two_singles(self): result = list(result) correct_array = [3] - self.assertEqual(correct_array, result) + if self.ordered: + self.assertListEqual(correct_array, result) + else: + self.assertListEqual(sorted(correct_array), sorted(result)) def _test_two_singles_with_num_iter(self): single_1 = 5 @@ -92,13 +113,17 @@ def _test_two_singles_with_num_iter(self): result = list(result) correct_array = [3]*num_iter - self.assertEqual(correct_array, result) + if self.ordered: + self.assertListEqual(correct_array, result) + else: + self.assertListEqual(sorted(correct_array), sorted(result)) class Testp_imap(unittest.TestCase): def __init__(self, *args, **kwargs): super(Testp_imap, self).__init__(*args, **kwargs) self.func = p_tqdm.p_imap self.generator = True + self.ordered = True def test_one_list(self): _test_one_list(self) @@ -129,6 +154,131 @@ class Testp_map(unittest.TestCase): super(Testp_map, self).__init__(*args, **kwargs) self.func = p_tqdm.p_map self.generator = False + self.ordered = True + + def test_one_list(self): + _test_one_list(self) + + def test_two_lists(self): + _test_two_lists(self) + + def test_two_lists_and_one_single(self): + _test_two_lists_and_one_single(self) + + def test_one_list_and_two_singles(self): + _test_one_list_and_two_singles(self) + + def test_one_single(self): + _test_one_single(self) + + def test_one_single_with_num_iter(self): + _test_one_single_with_num_iter(self) + + def test_two_singles(self): + _test_two_singles(self) + + def test_two_singles_with_num_iter(self): + _test_two_singles_with_num_iter(self) + +class Testp_uimap(unittest.TestCase): + def __init__(self, *args, **kwargs): + super(Testp_uimap, self).__init__(*args, **kwargs) + self.func = p_tqdm.p_uimap + self.generator = True + self.ordered = False + + def test_one_list(self): + _test_one_list(self) + + def test_two_lists(self): + _test_two_lists(self) + + def test_two_lists_and_one_single(self): + _test_two_lists_and_one_single(self) + + def test_one_list_and_two_singles(self): + _test_one_list_and_two_singles(self) + + def test_one_single(self): + _test_one_single(self) + + def test_one_single_with_num_iter(self): + _test_one_single_with_num_iter(self) + + def test_two_singles(self): + _test_two_singles(self) + + def test_two_singles_with_num_iter(self): + _test_two_singles_with_num_iter(self) + +class Testp_umap(unittest.TestCase): + def __init__(self, *args, **kwargs): + super(Testp_umap, self).__init__(*args, **kwargs) + self.func = p_tqdm.p_umap + self.generator = False + self.ordered = False + + def test_one_list(self): + _test_one_list(self) + + def test_two_lists(self): + _test_two_lists(self) + + def test_two_lists_and_one_single(self): + _test_two_lists_and_one_single(self) + + def test_one_list_and_two_singles(self): + _test_one_list_and_two_singles(self) + + def test_one_single(self): + _test_one_single(self) + + def test_one_single_with_num_iter(self): + _test_one_single_with_num_iter(self) + + def test_two_singles(self): + _test_two_singles(self) + + def test_two_singles_with_num_iter(self): + _test_two_singles_with_num_iter(self) + +class Testt_imap(unittest.TestCase): + def __init__(self, *args, **kwargs): + super(Testt_imap, self).__init__(*args, **kwargs) + self.func = p_tqdm.t_imap + self.generator = True + self.ordered = True + + def test_one_list(self): + _test_one_list(self) + + def test_two_lists(self): + _test_two_lists(self) + + def test_two_lists_and_one_single(self): + _test_two_lists_and_one_single(self) + + def test_one_list_and_two_singles(self): + _test_one_list_and_two_singles(self) + + def test_one_single(self): + _test_one_single(self) + + def test_one_single_with_num_iter(self): + _test_one_single_with_num_iter(self) + + def test_two_singles(self): + _test_two_singles(self) + + def test_two_singles_with_num_iter(self): + _test_two_singles_with_num_iter(self) + +class Testt_map(unittest.TestCase): + def __init__(self, *args, **kwargs): + super(Testt_map, self).__init__(*args, **kwargs) + self.func = p_tqdm.t_map + self.generator = False + self.ordered = True def test_one_list(self): _test_one_list(self)