From 4e6c1662e2b2d333593aa043d1aee6ee1b614c8c Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Wed, 7 Apr 2021 20:20:28 +0100 Subject: [PATCH] updated test suites to handle the pycapsules --- binarycpython/tests/test_c_bindings.py | 30 ++++++++++++++++++++------ binarycpython/tests/test_grid.py | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/binarycpython/tests/test_c_bindings.py b/binarycpython/tests/test_c_bindings.py index b2d97ee48..1f59f3a70 100644 --- a/binarycpython/tests/test_c_bindings.py +++ b/binarycpython/tests/test_c_bindings.py @@ -64,6 +64,11 @@ ensemble_filters_off {8} ensemble_filter_{9} 1 probability 0.1" return argstring +def is_capsule(o): + t = type(o) + return t.__module__ == 'builtins' and t.__name__ == 'PyCapsule' + + ####################################################################################################################################################### ### General run_system test ####################################################################################################################################################### @@ -78,6 +83,7 @@ class test_run_system(unittest.TestCase): """ General test if run_system works """ + print(self.id()) m1 = 15.0 # Msun m2 = 14.0 # Msun @@ -109,6 +115,7 @@ class test_run_system(unittest.TestCase): ### memaddr test ####################################################################################################################################################### +# TODO: Make some assertion tests in c class test_return_store_memaddr(unittest.TestCase): """ @@ -119,15 +126,17 @@ class test_return_store_memaddr(unittest.TestCase): """ Test to see if the memory adress is returned properly """ - + print(self.id()) output = _binary_c_bindings.return_store_memaddr() # print("function: test_return_store") # print("store memory adress:") # print(textwrap.indent(str(output), "\t")) - self.assertTrue(isinstance(output, int)) - self.assertNotEqual(output, -1, "memory adress not created properly") + self.assertTrue(is_capsule(output)) + # self.assertNotEqual( + # output, 0, "memory adress seems not to have a correct value" + # ) # TODO: check if we can built in some signal for how successful this was. _ = _binary_c_bindings.free_store_memaddr(output) @@ -153,18 +162,20 @@ class TestEnsemble(unittest.TestCase): """ Test case to check if the memory adress has been created succesfully """ + print(self.id()) output = _binary_c_bindings.return_persistent_data_memaddr() - self.assertIsInstance(output, int, msg="memory adress has to be an integer") - self.assertNotEqual( - output, 0, "memory adress seems not to have a correct value" - ) + self.assertTrue(is_capsule(output), msg="Object must be an integer") + # self.assertNotEqual( + # output, 0, "memory adress seems not to have a correct value" + # ) def test_minimal_ensemble_output(self): """ test_case to check if the ensemble output is correctly output """ + print(self.id()) m1 = 2 # Msun m2 = 0.1 # Msun @@ -190,6 +201,7 @@ class TestEnsemble(unittest.TestCase): """ test_case to check if the ensemble output is correctly output, by using defer command and freeing+outputting """ + print(self.id()) m1 = 2 # Msun m2 = 0.1 # Msun @@ -227,6 +239,7 @@ class TestEnsemble(unittest.TestCase): """ test_case to check if adding the ensemble outputs works. Many things should be caught by tests in the merge_dict test, but still good to test a bit here """ + print(self.id()) m1 = 2 # Msun m2 = 0.1 # Msun @@ -287,6 +300,7 @@ class TestEnsemble(unittest.TestCase): """ test to run 2 systems without deferring, and merging them manually. Then run 2 systems with defer and then output them. """ + print(self.id()) m1 = 2 # Msun m2 = 0.1 # Msun @@ -373,6 +387,7 @@ class TestEnsemble(unittest.TestCase): """ Test for merging with an empty dict """ + print(self.id()) m1 = 2 # Msun m2 = 0.1 # Msun @@ -398,6 +413,7 @@ class TestEnsemble(unittest.TestCase): Function to just output the whole ensemble TODO: put this one back """ + print(self.id()) m1 = 2 # Msun m2 = 0.1 # Msun diff --git a/binarycpython/tests/test_grid.py b/binarycpython/tests/test_grid.py index a6503d71c..3eed2895c 100644 --- a/binarycpython/tests/test_grid.py +++ b/binarycpython/tests/test_grid.py @@ -465,7 +465,7 @@ class test_grid_evolve(unittest.TestCase): test_pop_evolve_1_thread = Population() test_pop_evolve_1_thread.set( - amt_cores=1, verbosity=1, M_2=1, orbital_period=100000 + amt_cores=1, verbosity=0, M_2=1, orbital_period=100000 ) resolution = {"M_1": 10} -- GitLab