From 5269fa3e4ec6173fe62379878bede2c394df6334 Mon Sep 17 00:00:00 2001
From: David Hendriks <davidhendriks93@gmail.com>
Date: Thu, 19 Aug 2021 18:51:33 +0100
Subject: [PATCH] updated the tests to contain a correct temp dir

---
 binarycpython/tests/test_c_bindings.py        |  4 +--
 binarycpython/tests/test_custom_logging.py    | 25 +++++++++--------
 binarycpython/tests/test_distributions.py     |  6 ++++-
 binarycpython/tests/test_functions.py         | 26 +++++-------------
 binarycpython/tests/test_grid.py              | 27 +++++++++----------
 .../tests/test_grid_options_defaults.py       |  7 +++--
 binarycpython/tests/test_notebooks.py         |  3 ---
 binarycpython/tests/test_plot_functions.py    |  6 -----
 8 files changed, 41 insertions(+), 63 deletions(-)

diff --git a/binarycpython/tests/test_c_bindings.py b/binarycpython/tests/test_c_bindings.py
index 662a50e46..d92d44968 100644
--- a/binarycpython/tests/test_c_bindings.py
+++ b/binarycpython/tests/test_c_bindings.py
@@ -24,9 +24,7 @@ from binarycpython.utils.functions import (
     Capturing,
 )
 
-# https://docs.python.org/3/library/unittest.html
-TMP_DIR = temp_dir()
-os.makedirs(os.path.join(TMP_DIR, "test"), exist_ok=True)
+TMP_DIR = temp_dir("tests", "test_c_bindings")
 
 #### some useful functions
 def return_argstring(
diff --git a/binarycpython/tests/test_custom_logging.py b/binarycpython/tests/test_custom_logging.py
index 62c5be370..9e9600f41 100644
--- a/binarycpython/tests/test_custom_logging.py
+++ b/binarycpython/tests/test_custom_logging.py
@@ -7,8 +7,7 @@ import unittest
 from binarycpython.utils.custom_logging_functions import *
 from binarycpython.utils.functions import Capturing
 
-binary_c_temp_dir = temp_dir()
-
+TMP_DIR = temp_dir("tests", "test_custom_logging")
 
 class test_custom_logging(unittest.TestCase):
     """
@@ -26,7 +25,7 @@ class test_custom_logging(unittest.TestCase):
         """
 
         input_dict_1 = None
-        output_1 = autogen_C_logging_code(input_dict_1, verbose=1)
+        output_1 = autogen_C_logging_code(input_dict_1, verbosity=1)
         self.assertEqual(output_1, None, msg="Error. return value should be None")
 
         input_dict_2 = {
@@ -37,7 +36,7 @@ class test_custom_logging(unittest.TestCase):
                 "model.dt",
             ]
         }
-        output_2 = autogen_C_logging_code(input_dict_2, verbose=1)
+        output_2 = autogen_C_logging_code(input_dict_2, verbosity=1)
 
         test_output_2 = 'Printf("MY_STELLAR_DATA %g %g %g %g\\n",((double)stardata->model.time),((double)stardata->star[0].mass),((double)stardata->model.probability),((double)stardata->model.dt));'
         self.assertEqual(
@@ -45,7 +44,7 @@ class test_custom_logging(unittest.TestCase):
         )
 
         input_dict_3 = {"MY_STELLAR_DATA": 2}
-        output_3 = autogen_C_logging_code(input_dict_3, verbose=1)
+        output_3 = autogen_C_logging_code(input_dict_3, verbosity=1)
         self.assertEqual(output_3, None, msg="Output should be None")
 
     def test_binary_c_log_code(self):
@@ -59,11 +58,11 @@ class test_custom_logging(unittest.TestCase):
         """
 
         input_1 = "None"
-        output_1 = binary_c_log_code(input_1, verbose=1)
+        output_1 = binary_c_log_code(input_1, verbosity=1)
         self.assertEqual(output_1, None, msg="Output should be None")
 
         input_2 = 'Printf("MY_STELLAR_DATA %g %g %g %g\\n",((double)stardata->model.time),((double)stardata->star[0].mass),((double)stardata->model.probability),((double)stardata->model.dt));'
-        output_2 = binary_c_log_code(input_2, verbose=1)
+        output_2 = binary_c_log_code(input_2, verbosity=1)
         test_value_2 = '#pragma push_macro("Max")\n#pragma push_macro("Min")\n#undef Max\n#undef Min\n#include "binary_c.h"\n\n// add visibility __attribute__ ((visibility ("default"))) to it \nvoid binary_c_API_function custom_output_function(struct stardata_t * stardata);\nvoid binary_c_API_function custom_output_function(struct stardata_t * stardata)\n{\n    // struct stardata_t * stardata = (struct stardata_t *)x;\n    Printf("MY_STELLAR_DATA %g %g %g %g\\n",((double)stardata->model.time),((double)stardata->star[0].mass),((double)stardata->model.probability),((double)stardata->model.dt));;\n}\n\n#undef Max \n#undef Min\n#pragma pop_macro("Min")\n#pragma pop_macro("Max")    '
 
         self.assertEqual(
@@ -86,18 +85,18 @@ class test_custom_logging(unittest.TestCase):
 
         binary_c_write_log_code(
             input_1,
-            os.path.join(binary_c_temp_dir, "test_binary_c_write_log_code.txt"),
-            verbose=1,
+            os.path.join(TMP_DIR, "test_binary_c_write_log_code.txt"),
+            verbosity=1,
         )
 
         self.assertTrue(
             os.path.isfile(
-                os.path.join(binary_c_temp_dir, "test_binary_c_write_log_code.txt")
+                os.path.join(TMP_DIR, "test_binary_c_write_log_code.txt")
             ),
             msg="File not created",
         )
         with open(
-            os.path.join(binary_c_temp_dir, "test_binary_c_write_log_code.txt")
+            os.path.join(TMP_DIR, "test_binary_c_write_log_code.txt")
         ) as f:
             content_file = repr(f.read())
         self.assertEqual(repr(input_1), content_file, msg="Contents are not similar")
@@ -144,7 +143,7 @@ class test_custom_logging(unittest.TestCase):
         # Just going to check whether the dictionary has the components it needs
         # TODO: check whether we need to make this better
 
-        output = return_compilation_dict(verbose=1)
+        output = return_compilation_dict(verbosity=1)
 
         self.assertTrue("cc" in output)
         self.assertTrue("ld" in output)
@@ -164,7 +163,7 @@ class test_custom_logging(unittest.TestCase):
 
         #
         input_1 = '#pragma push_macro("MAX")\n#pragma push_macro("MIN")\n#undef MAX\n#undef MIN\n#include "binary_c.h"\n\n// add visibility __attribute__ ((visibility ("default"))) to it \nvoid binary_c_API_function custom_output_function(struct stardata_t * stardata);\nvoid binary_c_API_function custom_output_function(struct stardata_t * stardata)\n{\n    // struct stardata_t * stardata = (struct stardata_t *)x;\n    Printf("MY_STELLAR_DATA %g %g %g %g\\n",((double)stardata->model.time),((double)stardata->star[0].mass),((double)stardata->model.probability),((double)stardata->model.dt));;\n}\n\n#undef MAX \n#undef MIN\n#pragma pop_macro("MIN")\n#pragma pop_macro("MAX")    '
-        output_1 = create_and_load_logging_function(input_1, verbose=1)
+        output_1 = create_and_load_logging_function(input_1, verbosity=1)
 
         self.assertTrue(isinstance(output_1[0], int), msg="memaddr is not an int")
         self.assertTrue(output_1[0] > 0, msg="memaddr is an int but not set correctly")
diff --git a/binarycpython/tests/test_distributions.py b/binarycpython/tests/test_distributions.py
index caeb87ffe..ba90e5d50 100644
--- a/binarycpython/tests/test_distributions.py
+++ b/binarycpython/tests/test_distributions.py
@@ -6,8 +6,12 @@ import unittest
 
 from binarycpython.utils.distribution_functions import *
 from binarycpython.utils.useful_funcs import calc_sep_from_period
-from binarycpython.utils.functions import Capturing
+from binarycpython.utils.functions import (
+    Capturing,
+    temp_dir
+)
 
+TMP_DIR = temp_dir("tests", "test_distributions")
 
 class TestDistributions(unittest.TestCase):
     """
diff --git a/binarycpython/tests/test_functions.py b/binarycpython/tests/test_functions.py
index b576bf7f6..432a48253 100644
--- a/binarycpython/tests/test_functions.py
+++ b/binarycpython/tests/test_functions.py
@@ -8,19 +8,7 @@ from binarycpython.utils.functions import *
 from binarycpython.utils.custom_logging_functions import binary_c_log_code
 from binarycpython.utils.run_system_wrapper import run_system
 
-binary_c_temp_dir = temp_dir()
-
-#############################
-# Script that contains unit tests for functions from the binarycpython.utils.functions file
-
-# class test_(unittest.TestCase):
-#     """
-#     Unittests for function
-#     """
-
-#     def test_1(self):
-#         pass
-
+TMP_DIR = temp_dir("tests", "test_functions")
 
 class dummy:
     """
@@ -82,11 +70,11 @@ class test_remove_file(unittest.TestCase):
         """
 
         with open(
-            os.path.join(binary_c_temp_dir, "test_remove_file_file.txt"), "w"
+            os.path.join(TMP_DIR, "test_remove_file_file.txt"), "w"
         ) as f:
             f.write("test")
 
-        remove_file(os.path.join(binary_c_temp_dir, "test_remove_file_file.txt"))
+        remove_file(os.path.join(TMP_DIR, "test_remove_file_file.txt"))
 
     def test_remove_nonexisting_file(self):
         with Capturing() as output:
@@ -97,7 +85,7 @@ class test_remove_file(unittest.TestCase):
         Test to try to remove a nonexistant file
         """
 
-        file = os.path.join(binary_c_temp_dir, "test_remove_nonexistingfile_file.txt")
+        file = os.path.join(TMP_DIR, "test_remove_nonexistingfile_file.txt")
 
         remove_file(file)
 
@@ -141,7 +129,7 @@ class test_create_hdf5(unittest.TestCase):
         Test that creates files, packs them in a hdf5 file and checks the contents
         """
 
-        testdir = os.path.join(binary_c_temp_dir, "test_create_hdf5")
+        testdir = os.path.join(TMP_DIR, "test_create_hdf5")
         os.makedirs(testdir, exist_ok=True)
 
         # Create dummy settings file:
@@ -600,7 +588,7 @@ class test_write_binary_c_parameter_descriptions_to_rst_file(unittest.TestCase):
         """
 
         output_name = os.path.join(
-            binary_c_temp_dir,
+            TMP_DIR,
             "test_write_binary_c_parameter_descriptions_to_rst_file_test_1.txt",
         )
         output_1 = write_binary_c_parameter_descriptions_to_rst_file(output_name)
@@ -616,7 +604,7 @@ class test_write_binary_c_parameter_descriptions_to_rst_file(unittest.TestCase):
         """
 
         output_name = os.path.join(
-            binary_c_temp_dir,
+            TMP_DIR,
             "test_write_binary_c_parameter_descriptions_to_rst_file_test_1.rst",
         )
         output_1 = write_binary_c_parameter_descriptions_to_rst_file(output_name)
diff --git a/binarycpython/tests/test_grid.py b/binarycpython/tests/test_grid.py
index 5eb146ff8..5c761801c 100644
--- a/binarycpython/tests/test_grid.py
+++ b/binarycpython/tests/test_grid.py
@@ -22,8 +22,7 @@ from binarycpython.utils.functions import (
 )
 from binarycpython.utils.custom_logging_functions import binary_c_log_code
 
-binary_c_temp_dir = temp_dir()
-
+TMP_DIR = temp_dir("tests", "test_grid")
 TEST_VERBOSITY = 1
 
 def parse_function_test_grid_evolve_2_threads_with_custom_logging(self, output):
@@ -342,7 +341,7 @@ class test_Population(unittest.TestCase):
         test_pop.set(metallicity=0.02, verbosity=TEST_VERBOSITY)
         test_pop.set(M_1=10)
         test_pop.set(amt_cores=2)
-        test_pop.set(data_dir=binary_c_temp_dir)
+        test_pop.set(data_dir=TMP_DIR)
 
         # datadir
         settings_filename = test_pop.export_all_info(use_datadir=True)
@@ -366,7 +365,7 @@ class test_Population(unittest.TestCase):
         # datadir
         settings_filename = test_pop.export_all_info(
             use_datadir=False,
-            outfile=os.path.join(binary_c_temp_dir, "example_settings.json"),
+            outfile=os.path.join(TMP_DIR, "example_settings.json"),
         )
         self.assertTrue(os.path.isfile(settings_filename))
         with open(settings_filename, "r") as f:
@@ -389,7 +388,7 @@ class test_Population(unittest.TestCase):
             ValueError,
             test_pop.export_all_info,
             use_datadir=False,
-            outfile=os.path.join(binary_c_temp_dir, "example_settings.txt"),
+            outfile=os.path.join(TMP_DIR, "example_settings.txt"),
         )
 
     def test__cleanup_defaults(self):
@@ -440,7 +439,7 @@ class test_Population(unittest.TestCase):
         Unittests for the function _dict_from_line_source_file
         """
 
-        source_file = os.path.join(binary_c_temp_dir, "example_source_file.txt")
+        source_file = os.path.join(TMP_DIR, "example_source_file.txt")
 
         # write
         with open(source_file, "w") as f:
@@ -602,7 +601,7 @@ class test_grid_evolve(unittest.TestCase):
         Unittests to see if multiple threads do the custom logging correctly
         """
 
-        data_dir_value = os.path.join(binary_c_temp_dir, "grid_tests")
+        data_dir_value = os.path.join(TMP_DIR, "grid_tests")
         amt_cores_value = 2
         custom_logging_string = 'Printf("MY_STELLAR_DATA_TEST_EXAMPLE %g %g %g %g\\n",((double)stardata->model.time),((double)stardata->star[0].mass),((double)stardata->model.probability),((double)stardata->model.dt));'
 
@@ -784,7 +783,7 @@ Printf("TEST_CUSTOM_LOGGING_1 %30.12e %g %g %g %g\\n",
         Unittests to see if multiple threads output the ensemble information to files correctly
         """
 
-        data_dir_value = binary_c_temp_dir
+        data_dir_value = TMP_DIR
         amt_cores_value = 2
 
         test_pop = Population()
@@ -800,7 +799,7 @@ Printf("TEST_CUSTOM_LOGGING_1 %30.12e %g %g %g %g\\n",
             ensemble_dt=1000,
         )
         test_pop.set(
-            data_dir=binary_c_temp_dir,
+            data_dir=TMP_DIR,
             ensemble_output_name="ensemble_output.json",
             combine_ensemble_with_thread_joining=False,
         )
@@ -858,7 +857,7 @@ Printf("TEST_CUSTOM_LOGGING_1 %30.12e %g %g %g %g\\n",
         Unittests to see if multiple threads correclty combine the ensemble data and store them in the grid
         """
 
-        data_dir_value = binary_c_temp_dir
+        data_dir_value = TMP_DIR
         amt_cores_value = 2
 
         test_pop = Population()
@@ -874,7 +873,7 @@ Printf("TEST_CUSTOM_LOGGING_1 %30.12e %g %g %g %g\\n",
             ensemble_dt=1000,
         )
         test_pop.set(
-            data_dir=binary_c_temp_dir,
+            data_dir=TMP_DIR,
             combine_ensemble_with_thread_joining=True,
             ensemble_output_name="ensemble_output.json",
         )
@@ -915,7 +914,7 @@ Printf("TEST_CUSTOM_LOGGING_1 %30.12e %g %g %g %g\\n",
         Unittests to compare the method of storing the combined ensemble data in the object and writing them to files and combining them later. they have to be the same
         """
 
-        data_dir_value = binary_c_temp_dir
+        data_dir_value = TMP_DIR
         amt_cores_value = 2
 
         # First
@@ -932,7 +931,7 @@ Printf("TEST_CUSTOM_LOGGING_1 %30.12e %g %g %g %g\\n",
             ensemble_dt=1000,
         )
         test_pop_1.set(
-            data_dir=binary_c_temp_dir,
+            data_dir=TMP_DIR,
             combine_ensemble_with_thread_joining=True,
             ensemble_output_name="ensemble_output.json",
         )
@@ -971,7 +970,7 @@ Printf("TEST_CUSTOM_LOGGING_1 %30.12e %g %g %g %g\\n",
             ensemble_dt=1000,
         )
         test_pop_2.set(
-            data_dir=binary_c_temp_dir,
+            data_dir=TMP_DIR,
             ensemble_output_name="ensemble_output.json",
             combine_ensemble_with_thread_joining=False,
         )
diff --git a/binarycpython/tests/test_grid_options_defaults.py b/binarycpython/tests/test_grid_options_defaults.py
index 8986e1ada..ae1ccb912 100644
--- a/binarycpython/tests/test_grid_options_defaults.py
+++ b/binarycpython/tests/test_grid_options_defaults.py
@@ -14,8 +14,7 @@ from binarycpython.utils.grid_options_defaults import (
     grid_options_description_checker,
 )
 
-binary_c_temp_dir = temp_dir()
-
+TMP_DIR = temp_dir("tests", "test_grid_options_defaults")
 
 class test_grid_options_defaults(unittest.TestCase):
     """
@@ -79,13 +78,13 @@ class test_grid_options_defaults(unittest.TestCase):
         """
 
         input_1 = os.path.join(
-            binary_c_temp_dir, "test_write_grid_options_to_rst_file_1.txt"
+            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)
 
         input_2 = os.path.join(
-            binary_c_temp_dir, "test_write_grid_options_to_rst_file_2.rst"
+            TMP_DIR, "test_write_grid_options_to_rst_file_2.rst"
         )
         output_2 = write_grid_options_to_rst_file(input_2)
 
diff --git a/binarycpython/tests/test_notebooks.py b/binarycpython/tests/test_notebooks.py
index 61c809651..276dc6bab 100644
--- a/binarycpython/tests/test_notebooks.py
+++ b/binarycpython/tests/test_notebooks.py
@@ -13,8 +13,6 @@ TMP_DIR = temp_dir('testing', 'test_notebooks')
 def run_notebook(notebook_path):
     """
     Function to run notebooks and get the errors
-
-
     """
 
     # https://www.blog.pythonlibrary.org/2018/10/16/testing-jupyter-notebooks/
@@ -42,7 +40,6 @@ def run_notebook(notebook_path):
 
     return nb, errors
 
-
 class TestNotebook(unittest.TestCase):
     """
     Class that contains the notebook test calls
diff --git a/binarycpython/tests/test_plot_functions.py b/binarycpython/tests/test_plot_functions.py
index 43b716e95..3e103e6b7 100644
--- a/binarycpython/tests/test_plot_functions.py
+++ b/binarycpython/tests/test_plot_functions.py
@@ -9,13 +9,7 @@ import matplotlib.pyplot as plt
 from binarycpython.utils.plot_functions import *
 from binarycpython.utils.functions import Capturing
 
-# class test_(unittest.TestCase):
-#     """
-#     Unittests for function
-#     """
 
-#     def test_1(self):
-#         pass
 
 
 class test_color_by_index(unittest.TestCase):
-- 
GitLab