From 3fb920a28e10e74964925ebfa5dbcdff485039eb Mon Sep 17 00:00:00 2001
From: David Hendriks <davidhendriks93@gmail.com>
Date: Mon, 24 Oct 2022 13:50:23 +0100
Subject: [PATCH] added test case for custom logging
---
binarycpython/tests/test_custom_logging.py | 36 ++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/binarycpython/tests/test_custom_logging.py b/binarycpython/tests/test_custom_logging.py
index a42e4b0b2..156177c17 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()
--
GitLab