From c5e6745169020d691fdbba51f6dbc09174b95ca3 Mon Sep 17 00:00:00 2001
From: dh00601 <dh00601@surrey.ac.uk>
Date: Wed, 29 Dec 2021 20:46:25 +0000
Subject: [PATCH] piecing together the tests again

---
 badges/test_coverage.svg                      |   4 +-
 binarycpython/tests/main.py                   |  33 +--
 binarycpython/tests/test_dicts.py             | 192 ++++++++++++++++++
 binarycpython/tests/test_functions.py         |  17 --
 .../test__grid_options_defaults.py            |  47 +++--
 binarycpython/tests/tmp_functions.py          | 136 +------------
 binarycpython/utils/dicts.py                  |   1 -
 7 files changed, 245 insertions(+), 185 deletions(-)
 create mode 100644 binarycpython/tests/test_dicts.py

diff --git a/badges/test_coverage.svg b/badges/test_coverage.svg
index 6198a7284..a9be2c5a7 100644
--- a/badges/test_coverage.svg
+++ b/badges/test_coverage.svg
@@ -15,7 +15,7 @@
     <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
         <text x="31.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
         <text x="31.5" y="14">coverage</text>
-        <text x="80" y="15" fill="#010101" fill-opacity=".3">27%</text>
-        <text x="80" y="14">27%</text>
+        <text x="80" y="15" fill="#010101" fill-opacity=".3">29%</text>
+        <text x="80" y="14">29%</text>
     </g>
 </svg>
diff --git a/binarycpython/tests/main.py b/binarycpython/tests/main.py
index b293970ea..5e23cee46 100755
--- a/binarycpython/tests/main.py
+++ b/binarycpython/tests/main.py
@@ -20,6 +20,9 @@ from binarycpython.tests.test_custom_logging import (
     test_return_compilation_dict,
     test_create_and_load_logging_function
 )
+from binarycpython.tests.test_dicts import (
+    test_merge_dicts
+)
 from binarycpython.tests.test_functions import (
     test_verbose_print,
     test_temp_dir,
@@ -43,7 +46,19 @@ from binarycpython.tests.test_plot_functions import (
     test_plot_system,
 )
 from binarycpython.tests.test_run_system_wrapper import *
-# from binarycpython.tests.test_spacing_functions import *
+
+from binarycpython.tests.tests_population_extensions.test__distribution_functions import (
+    test_flat,
+    test_number,
+    test_const
+)
+from binarycpython.tests.tests_population_extensions.test__grid_options_defaults import (
+    test_grid_options_help,
+    test_grid_options_description_checker,
+    test_write_grid_options_to_rst_file,
+)
+
+from binarycpython.tests.test_stellar_types import *
 from binarycpython.tests.test_useful_funcs import (
     test_calc_period_from_sep,
     test_calc_sep_from_period,
@@ -52,23 +67,11 @@ from binarycpython.tests.test_useful_funcs import (
     test_rzams,
     test_zams_collission,
 )
-# from binarycpython.tests.test_grid_options_defaults import *
-from binarycpython.tests.test_stellar_types import *
-
-
-
-
 
 
+# from binarycpython.tests.test_spacing_functions import *
+# from binarycpython.tests.test_grid_options_defaults import *
 # from binarycpython.tests.test_hpc_functions import *
-from binarycpython.tests.tests_population_extensions.test__distribution_functions import (
-    test_flat,
-    test_number,
-    test_const
-)
-
-
-
 
 
 
diff --git a/binarycpython/tests/test_dicts.py b/binarycpython/tests/test_dicts.py
new file mode 100644
index 000000000..8dc2435e3
--- /dev/null
+++ b/binarycpython/tests/test_dicts.py
@@ -0,0 +1,192 @@
+"""
+Unittests for dicts module
+
+TODO: keys_to_floats
+TODO: recursive_change_key_to_float
+TODO: recursive_change_key_to_string
+TODO: _nested_set
+TODO: _nested_get
+TODO: _recursive_normalize_floats
+TODO: multiply_float_values
+TODO: subtract_dicts
+TODO: AutoVivificationDict
+TODO: inspect_dict
+TODO: count_keys_recursive
+
+TODO: update_dicts
+TODO: multiply_values_dict
+TODO: custom_sort_dict
+TODO: filter_dict
+TODO: filter_dict_through_values
+TODO: prepare_dict
+TODO: set_opts
+TODO: normalize_dict
+"""
+
+import os
+import unittest
+
+from binarycpython.utils.functions import (
+    temp_dir,
+    Capturing,
+)
+from binarycpython.utils.dicts import (
+    merge_dicts
+)
+
+TMP_DIR = temp_dir("tests", "test_dicts")
+
+
+class dummy:
+    """
+    Dummy class to be used in the merge_dicts
+    """
+
+    def __init__(self, name):
+        """
+        init
+        """
+        self.name = name
+
+    def __str__(self):
+        """
+        str returns self.name
+        """
+        return self.name
+
+
+class test_merge_dicts(unittest.TestCase):
+    """
+    Unittests for function merge_dicts
+    """
+
+    def test_empty(self):
+        with Capturing() as output:
+            self._test_empty()
+
+    def _test_empty(self):
+        """
+        Test merging an empty dict
+        """
+
+        input_dict = {
+            "int": 1,
+            "float": 1.2,
+            "list": [1, 2, 3],
+            "function": os.path.isfile,
+            "dict": {"int": 1, "float": 1.2},
+        }
+        dict_2 = {}
+        output_dict = merge_dicts(input_dict, dict_2)
+        self.assertTrue(output_dict == input_dict)
+
+    def test_unequal_types(self):
+        with Capturing() as output:
+            self._test_unequal_types()
+
+    def _test_unequal_types(self):
+        """
+        Test merging unequal types: should raise valueError
+        """
+
+        dict_1 = {"input": 10}
+        dict_2 = {"input": "hello"}
+
+        self.assertRaises(ValueError, merge_dicts, dict_1, dict_2)
+
+    def test_bools(self):
+        with Capturing() as output:
+            self._test_bools()
+
+    def _test_bools(self):
+        """
+        Test merging dict with booleans
+        """
+
+        dict_1 = {"bool": True}
+        dict_2 = {"bool": False}
+        output_dict = merge_dicts(dict_1, dict_2)
+
+        self.assertTrue(isinstance(output_dict["bool"], bool))
+        self.assertTrue(output_dict["bool"])
+
+    def test_ints(self):
+        with Capturing() as _:
+            self._test_ints()
+
+    def _test_ints(self):
+        """
+        Test merging dict with ints
+        """
+
+        dict_1 = {"int": 2}
+        dict_2 = {"int": 1}
+        output_dict = merge_dicts(dict_1, dict_2)
+
+        self.assertTrue(isinstance(output_dict["int"], int))
+        self.assertEqual(output_dict["int"], 3)
+
+    def test_floats(self):
+        with Capturing() as output:
+            self._test_floats()
+
+    def _test_floats(self):
+        """
+        Test merging dict with floats
+        """
+
+        dict_1 = {"float": 4.5}
+        dict_2 = {"float": 4.6}
+        output_dict = merge_dicts(dict_1, dict_2)
+
+        self.assertTrue(isinstance(output_dict["float"], float))
+        self.assertEqual(output_dict["float"], 9.1)
+
+    def test_lists(self):
+        with Capturing() as output:
+            self._test_lists()
+
+    def _test_lists(self):
+        """
+        Test merging dict with lists
+        """
+
+        dict_1 = {"list": [1, 2]}
+        dict_2 = {"list": [3, 4]}
+        output_dict = merge_dicts(dict_1, dict_2)
+
+        self.assertTrue(isinstance(output_dict["list"], list))
+        self.assertEqual(output_dict["list"], [1, 2, 3, 4])
+
+    def test_dicts(self):
+        with Capturing() as _:
+            self._test_dicts()
+
+    def _test_dicts(self):
+        """
+        Test merging dict with dicts
+        """
+
+        dict_1 = {"dict": {"same": 1, "other_1": 2.0}}
+        dict_2 = {"dict": {"same": 2, "other_2": [4.0]}}
+        output_dict = merge_dicts(dict_1, dict_2)
+
+        self.assertTrue(isinstance(output_dict["dict"], dict))
+        self.assertEqual(
+            output_dict["dict"], {"same": 3, "other_1": 2.0, "other_2": [4.0]}
+        )
+
+    def test_unsupported(self):
+        with Capturing() as output:
+            self._test_unsupported()
+
+    def _test_unsupported(self):
+        """
+        Test merging dict with unsupported types. should raise ValueError
+        """
+
+        dict_1 = {"new": dummy("david")}
+        dict_2 = {"new": dummy("gio")}
+
+        # output_dict = merge_dicts(dict_1, dict_2)
+        self.assertRaises(ValueError, merge_dicts, dict_1, dict_2)
diff --git a/binarycpython/tests/test_functions.py b/binarycpython/tests/test_functions.py
index 4a75cc134..86c52958f 100644
--- a/binarycpython/tests/test_functions.py
+++ b/binarycpython/tests/test_functions.py
@@ -35,23 +35,6 @@ from binarycpython.utils.functions import (
 TMP_DIR = temp_dir("tests", "test_functions")
 
 
-class dummy:
-    """
-    Dummy class to be used in the merge_dicts
-    """
-
-    def __init__(self, name):
-        """
-        init
-        """
-        self.name = name
-
-    def __str__(self):
-        """
-        str returns self.name
-        """
-        return self.name
-
 
 class test_verbose_print(unittest.TestCase):
     """
diff --git a/binarycpython/tests/tests_population_extensions/test__grid_options_defaults.py b/binarycpython/tests/tests_population_extensions/test__grid_options_defaults.py
index 18291f2ee..69cd20bc6 100644
--- a/binarycpython/tests/tests_population_extensions/test__grid_options_defaults.py
+++ b/binarycpython/tests/tests_population_extensions/test__grid_options_defaults.py
@@ -1,5 +1,10 @@
 """
 Unittests for grid_options_defaults module
+
+TODO: get_grid_options_defaults_dict
+TODO: get_grid_options_descriptions
+TODO: print_option_descriptions
+TODO: default_cache_dir
 """
 import os
 import unittest
@@ -8,18 +13,14 @@ from binarycpython.utils.functions import (
     temp_dir,
     Capturing,
 )
-from binarycpython.utils.grid_options_defaults import (
-    write_grid_options_to_rst_file,
-    grid_options_help,
-    grid_options_description_checker,
-)
+from binarycpython.utils.grid import Population
 
 TMP_DIR = temp_dir("tests", "test_grid_options_defaults")
 
 
-class test_grid_options_defaults(unittest.TestCase):
+class test_grid_options_help(unittest.TestCase):
     """
-    Unit tests for the grid_options_defaults module
+    Unit tests for the grid_options_help function
     """
 
     def test_grid_options_help(self):
@@ -31,12 +32,14 @@ class test_grid_options_defaults(unittest.TestCase):
         Unit tests for the grid_options_help function
         """
 
+        grid_options_defaults_pop = Population()
+
         input_1 = "aa"
-        result_1 = grid_options_help(input_1)
+        result_1 = grid_options_defaults_pop.grid_options_help(input_1)
         self.assertEqual(result_1, {}, msg="Dict should be empty")
 
         input_2 = "num_cores"
-        result_2 = grid_options_help(input_2)
+        result_2 = grid_options_defaults_pop.grid_options_help(input_2)
         self.assertIn(
             input_2,
             result_2,
@@ -47,7 +50,7 @@ class test_grid_options_defaults(unittest.TestCase):
         )
 
         input_3 = "evolution_type"
-        result_3 = grid_options_help(input_3)
+        result_3 = grid_options_defaults_pop.grid_options_help(input_3)
         self.assertIn(
             input_3,
             result_3,
@@ -55,6 +58,12 @@ class test_grid_options_defaults(unittest.TestCase):
         )
         # self.assertEqual(result_3[input_3], "", msg="description should be empty")
 
+
+class test_grid_options_description_checker(unittest.TestCase):
+    """
+    Unit tests for the grid_options_description_checker function
+    """
+
     def test_grid_options_description_checker(self):
         with Capturing() as output:
             self._test_grid_options_description_checker()
@@ -64,11 +73,19 @@ class test_grid_options_defaults(unittest.TestCase):
         Unit tests for the grid_options_description_checker function
         """
 
-        output_1 = grid_options_description_checker(print_info=True)
+        grid_options_defaults_pop = Population()
+
+        output_1 = grid_options_defaults_pop.grid_options_description_checker(print_info=True)
 
         self.assertTrue(isinstance(output_1, int))
         self.assertTrue(output_1 > 0)
 
+
+class test_write_grid_options_to_rst_file(unittest.TestCase):
+    """
+    Unit tests for the write_grid_options_to_rst_file function
+    """
+
     def test_write_grid_options_to_rst_file(self):
         with Capturing() as output:
             self._test_write_grid_options_to_rst_file()
@@ -78,15 +95,15 @@ class test_grid_options_defaults(unittest.TestCase):
         Unit tests for the grid_options_description_checker function
         """
 
+        grid_options_defaults_pop = Population()
+
         input_1 = os.path.join(TMP_DIR, "test_write_grid_options_to_rst_file_1.txt")
-        output_1 = write_grid_options_to_rst_file(input_1)
-        self.assertIsNone(output_1)
+        self.assertRaises(ValueError, grid_options_defaults_pop.write_grid_options_to_rst_file, input_1)
 
         input_2 = os.path.join(TMP_DIR, "test_write_grid_options_to_rst_file_2.rst")
-        output_2 = write_grid_options_to_rst_file(input_2)
+        _ = grid_options_defaults_pop.write_grid_options_to_rst_file(input_2)
 
         self.assertTrue(os.path.isfile(input_2))
 
-
 if __name__ == "__main__":
     unittest.main()
diff --git a/binarycpython/tests/tmp_functions.py b/binarycpython/tests/tmp_functions.py
index 6fc3ab08f..f812a8652 100644
--- a/binarycpython/tests/tmp_functions.py
+++ b/binarycpython/tests/tmp_functions.py
@@ -1,4 +1,4 @@
-from binarycpython.utils.dicts import AutoVivificationDict, inspect_dict, merge_dicts
+
 from binarycpython.utils.ensemble import (
     binaryc_json_serializer,
     handle_ensemble_string_to_json,
@@ -140,141 +140,7 @@ from binarycpython.utils.ensemble import (
 #         output_dict = inspect_dict(input_dict, print_structure=True)
 
 
-# class test_merge_dicts(unittest.TestCase):
-#     """
-#     Unittests for function merge_dicts
-#     """
-
-#     def test_empty(self):
-#         with Capturing() as output:
-#             self._test_empty()
-
-#     def _test_empty(self):
-#         """
-#         Test merging an empty dict
-#         """
-
-#         input_dict = {
-#             "int": 1,
-#             "float": 1.2,
-#             "list": [1, 2, 3],
-#             "function": os.path.isfile,
-#             "dict": {"int": 1, "float": 1.2},
-#         }
-#         dict_2 = {}
-#         output_dict = merge_dicts(input_dict, dict_2)
-#         self.assertTrue(output_dict == input_dict)
-
-#     def test_unequal_types(self):
-#         with Capturing() as output:
-#             self._test_unequal_types()
-
-#     def _test_unequal_types(self):
-#         """
-#         Test merging unequal types: should raise valueError
-#         """
-
-#         dict_1 = {"input": 10}
-#         dict_2 = {"input": "hello"}
-
-#         self.assertRaises(ValueError, merge_dicts, dict_1, dict_2)
-
-#     def test_bools(self):
-#         with Capturing() as output:
-#             self._test_bools()
-
-#     def _test_bools(self):
-#         """
-#         Test merging dict with booleans
-#         """
-
-#         dict_1 = {"bool": True}
-#         dict_2 = {"bool": False}
-#         output_dict = merge_dicts(dict_1, dict_2)
-
-#         self.assertTrue(isinstance(output_dict["bool"], bool))
-#         self.assertTrue(output_dict["bool"])
-
-#     def test_ints(self):
-#         with Capturing() as _:
-#             self._test_ints()
-
-#     def _test_ints(self):
-#         """
-#         Test merging dict with ints
-#         """
-
-#         dict_1 = {"int": 2}
-#         dict_2 = {"int": 1}
-#         output_dict = merge_dicts(dict_1, dict_2)
-
-#         self.assertTrue(isinstance(output_dict["int"], int))
-#         self.assertEqual(output_dict["int"], 3)
-
-#     def test_floats(self):
-#         with Capturing() as output:
-#             self._test_floats()
-
-#     def _test_floats(self):
-#         """
-#         Test merging dict with floats
-#         """
-
-#         dict_1 = {"float": 4.5}
-#         dict_2 = {"float": 4.6}
-#         output_dict = merge_dicts(dict_1, dict_2)
-
-#         self.assertTrue(isinstance(output_dict["float"], float))
-#         self.assertEqual(output_dict["float"], 9.1)
-
-#     def test_lists(self):
-#         with Capturing() as output:
-#             self._test_lists()
-
-#     def _test_lists(self):
-#         """
-#         Test merging dict with lists
-#         """
-
-#         dict_1 = {"list": [1, 2]}
-#         dict_2 = {"list": [3, 4]}
-#         output_dict = merge_dicts(dict_1, dict_2)
-
-#         self.assertTrue(isinstance(output_dict["list"], list))
-#         self.assertEqual(output_dict["list"], [1, 2, 3, 4])
-
-#     def test_dicts(self):
-#         with Capturing() as _:
-#             self._test_dicts()
-
-#     def _test_dicts(self):
-#         """
-#         Test merging dict with dicts
-#         """
-
-#         dict_1 = {"dict": {"same": 1, "other_1": 2.0}}
-#         dict_2 = {"dict": {"same": 2, "other_2": [4.0]}}
-#         output_dict = merge_dicts(dict_1, dict_2)
-
-#         self.assertTrue(isinstance(output_dict["dict"], dict))
-#         self.assertEqual(
-#             output_dict["dict"], {"same": 3, "other_1": 2.0, "other_2": [4.0]}
-#         )
-
-#     def test_unsupported(self):
-#         with Capturing() as output:
-#             self._test_unsupported()
-
-#     def _test_unsupported(self):
-#         """
-#         Test merging dict with unsupported types. should raise ValueError
-#         """
-
-#         dict_1 = {"new": dummy("david")}
-#         dict_2 = {"new": dummy("gio")}
 
-#         # output_dict = merge_dicts(dict_1, dict_2)
-#         self.assertRaises(ValueError, merge_dicts, dict_1, dict_2)
 
 
 # class test_binaryc_json_serializer(unittest.TestCase):
diff --git a/binarycpython/utils/dicts.py b/binarycpython/utils/dicts.py
index f39f969dc..244d99278 100644
--- a/binarycpython/utils/dicts.py
+++ b/binarycpython/utils/dicts.py
@@ -104,7 +104,6 @@ def recursive_change_key_to_string(input_dict, custom_format="{:g}"):
     return new_dict
 
 
-
 def _nested_set(dic, keys, value):
     """
     Code to set a value of a nested dict based on a list of keys. We take into account the fact that the vallue in the dict might not be set at all by the setdefault call and the reverse looping of the keys
-- 
GitLab