diff --git a/binarycpython/tests/test_custom_logging.py b/binarycpython/tests/test_custom_logging.py index a42e4b0b24d460e7f670ce17e78da5bfb898fa28..156177c1749834239f155fd8b4ef141211abf815 100644 --- a/binarycpython/tests/test_custom_logging.py +++ b/binarycpython/tests/test_custom_logging.py @@ -6,6 +6,7 @@ import unittest from binarycpython.utils.custom_logging_functions import * from binarycpython.utils.functions import Capturing +from binarycpython.utils.run_system_wrapper import run_system TMP_DIR = temp_dir("tests", "test_custom_logging") @@ -204,5 +205,40 @@ class test_create_and_load_logging_function(unittest.TestCase): ) +class test_run_system_with_custom_logging(unittest.TestCase): + """ + Unit test class for autogen_C_logging_code + """ + + def test_run_system_with_custom_logging(self): + with Capturing() as _: + self._test_run_system_with_custom_logging() + # print("\n".join(output)) + + def _test_run_system_with_custom_logging(self): + """ + Tests for the autogeneration of a print statement from a dictionary. and then checking if the output is correct + """ + + # Create the print statement + custom_logging_print_statement = """ + Printf("EXAMPLE_CUSTOM_LOGGING %30.12e %g %g %d\\n", + // + stardata->model.time, // 1 + stardata->star[0].mass, //2 + stardata->common.zero_age.mass[0], //4 + + stardata->star[0].stellar_type //5 + ); + """ + + # Generate entire shared lib code around logging lines + custom_logging_code = binary_c_log_code(custom_logging_print_statement) + + output = run_system(M_1=1, custom_logging_code=custom_logging_code, api_log_filename_prefix=TMP_DIR) + + self.assertTrue(output.splitlines()[0].startswith("EXAMPLE_CUSTOM_LOGGING")) + + if __name__ == "__main__": unittest.main()