From 54c40b8c3afe05549e98b23083821aeebe4e9d72 Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Sun, 13 Dec 2020 18:09:13 +0000 Subject: [PATCH] making tests and fixing error output --- binarycpython/tests/main.py | 12 +++-- binarycpython/tests/test_c_bindings.py | 1 + binarycpython/tests/test_functions.py | 71 +++++++++++++++----------- src/binary_c_python.c | 2 + 4 files changed, 51 insertions(+), 35 deletions(-) diff --git a/binarycpython/tests/main.py b/binarycpython/tests/main.py index 20b1a1fde..db49ca2d8 100644 --- a/binarycpython/tests/main.py +++ b/binarycpython/tests/main.py @@ -1,6 +1,10 @@ # Main file for the tests. This file imports all the combined_test functions from all files. -from population.grid_tests import test_all as test_all_grid_tests -from function_tests import test_all as test_all_function_tests +import unittest -test_all_grid_tests() -test_all_function_tests() +from test_c_bindings import * +from test_functions import * + + + +if __name__ == '__main__': + unittest.main() diff --git a/binarycpython/tests/test_c_bindings.py b/binarycpython/tests/test_c_bindings.py index 23efdce5a..5e9b9c397 100644 --- a/binarycpython/tests/test_c_bindings.py +++ b/binarycpython/tests/test_c_bindings.py @@ -470,5 +470,6 @@ def all(): # # test_combine_with_empty_json() # all() # print("Done") + if __name__ == '__main__': unittest.main() diff --git a/binarycpython/tests/test_functions.py b/binarycpython/tests/test_functions.py index 150e337e2..7d5430a18 100644 --- a/binarycpython/tests/test_functions.py +++ b/binarycpython/tests/test_functions.py @@ -1,52 +1,61 @@ +import unittest from binarycpython.utils.functions import * ############################# # Script that contains unit tests for functions from the binarycpython.utils.functions file -def test_get_help_super(): +class test_get_help_super(unittest.TestCase): """ - Function to test the get_help_super function + Unit test for get_help_super """ - get_help_super_output = get_help_super() - get_help_super_keys = get_help_super_output.keys() + def test_all_output(self): + """ + Function to test the get_help_super function + """ - assert "stars" in get_help_super_keys, "missing section" - assert "binary" in get_help_super_keys, "missing section" - assert "nucsyn" in get_help_super_keys, "missing section" - assert "output" in get_help_super_keys, "missing section" - assert "i/o" in get_help_super_keys, "missing section" - assert "algorithms" in get_help_super_keys, "missing section" - assert "misc" in get_help_super_keys, "missing section" + get_help_super_output = get_help_super() + get_help_super_keys = get_help_super_output.keys() + self.assertIn("stars", get_help_super_keys, "missing section") + self.assertIn("binary", get_help_super_keys, "missing section") + self.assertIn("nucsyn", get_help_super_keys, "missing section") + self.assertIn("output", get_help_super_keys, "missing section") + self.assertIn("i/o", get_help_super_keys, "missing section") + self.assertIn("algorithms", get_help_super_keys, "missing section") + self.assertIn("misc", get_help_super_keys, "missing section") -def test_get_help_all(): +class test_get_help_all(unittest.TestCase): """ - Function to test the get_help_all function + Unit test for get_help_all """ - get_help_all_output = get_help_all(print_help=False) - get_help_all_keys = get_help_all_output.keys() + def test_all_output(self): + """ + Function to test the get_help_all function + """ - assert "stars" in get_help_all_keys, "missing section" - assert "binary" in get_help_all_keys, "missing section" - assert "nucsyn" in get_help_all_keys, "missing section" - assert "output" in get_help_all_keys, "missing section" - assert "i/o" in get_help_all_keys, "missing section" - assert "algorithms" in get_help_all_keys, "missing section" - assert "misc" in get_help_all_keys, "missing section" + get_help_all_output = get_help_all(print_help=False) + get_help_all_keys = get_help_all_output.keys() -def test_get_help(): - """ - Function to test the get_help function - """ + self.assertIn("stars", get_help_all_keys, "missing section") + self.assertIn("binary", get_help_all_keys, "missing section") + self.assertIn("nucsyn", get_help_all_keys, "missing section") + self.assertIn("output", get_help_all_keys, "missing section") + self.assertIn("i/o", get_help_all_keys, "missing section") + self.assertIn("algorithms", get_help_all_keys, "missing section") + self.assertIn("misc", get_help_all_keys, "missing section") + - assert ( - get_help("M_1", print_help=False)["parameter_name"] == "M_1" - ), "get_help('M_1') should return the correct parameter name" +class test_get_help(unittest.TestCase): + def test_input(self): + """ + Function to test the get_help function + """ + self.assertEqual(get_help("M_1", print_help=False)["parameter_name"], "M_1", msg="get_help('M_1') should return the correct parameter name") def all(): test_get_help() @@ -54,5 +63,5 @@ def all(): test_get_help_super() -if __name__ == "__main__": - all() +if __name__ == '__main__': + unittest.main() diff --git a/src/binary_c_python.c b/src/binary_c_python.c index 97547ef2c..6494cdb66 100644 --- a/src/binary_c_python.c +++ b/src/binary_c_python.c @@ -216,6 +216,8 @@ static PyObject* binary_c_run_system(PyObject *self, PyObject *args, PyObject *k fprintf(stderr, "Error (in function: binary_c_run_system): %s\n", error_buffer); + printf("Error (in function: binary_c_run_system): %s\n", + error_buffer); } Safe_free(buffer); -- GitLab