Loading binarycpython/utils/functions.py +1 −2 Original line number Diff line number Diff line Loading @@ -198,11 +198,10 @@ def run_system_with_log(**kwargs): # Run it and get output buffer = "" output = binary_c_python_api.run_binary_with_log(arg_string) output = binary_c_python_api.run_binary_with_logfile(arg_string) return output def parse_output(output, selected_header): """ Function that parses output of binary_c: Loading tests/python_API_test.py +91 −8 Original line number Diff line number Diff line Loading @@ -2,12 +2,19 @@ import binary_c_python_api from binarycpython.utils.custom_logging_functions import ( autogen_C_logging_code, binary_c_log_code, create_and_load_logging_function, ) import tempfile ############################################################ # Test script to run a binary using the binary_c Python # module. # Test script for the api functions ############################################################ def run_test_binary(): def test_run_binary(): m1 = 15.0 # Msun m2 = 14.0 # Msun separation = 0 # 0 = ignored, use period Loading @@ -15,7 +22,6 @@ def run_test_binary(): eccentricity = 0.0 metallicity = 0.02 max_evolution_time = 15000 buffer = "" argstring = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g} ".format( m1, m2, Loading @@ -28,13 +34,90 @@ def run_test_binary(): output = binary_c_python_api.run_binary(argstring) print("\n\nBinary_c output:\n\n") print("\n\nBinary_c output:") print(output) def run_help(): def test_return_help(): out = binary_c_python_api.return_help('M_1') print(out) run_help() def test_return_arglines(): out = binary_c_python_api.return_arglines() print(out) def test_run_binary_with_log(): m1 = 15.0 # Msun m2 = 14.0 # Msun separation = 0 # 0 = ignored, use period orbital_period = 4530.0 # days eccentricity = 0.0 metallicity = 0.02 max_evolution_time = 15000 log_filename = tempfile.gettempdir() + "/test_log.txt" api_log_filename_prefix = tempfile.gettempdir()+'/test_log' argstring = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g} log_filename {7:s} api_log_filename_prefix {8:s}".format( m1, m2, separation, orbital_period, eccentricity, metallicity, max_evolution_time, log_filename, api_log_filename_prefix, ) output = binary_c_python_api.run_binary_with_logfile(argstring) print("\n\nBinary_c output:") print(output) def test_run_binary_with_custom_logging(): """ """ # generate logging lines. Here you can choose whatever you want to have logged, and with what header # this generates working print statements logging_line = autogen_C_logging_code( {"MY_STELLAR_DATA": ["model.time", "star[0].mass"],} ) # Generate entire shared lib code around logging lines custom_logging_code = binary_c_log_code(logging_line) # Load memory adress func_memaddr = create_and_load_logging_function(custom_logging_code) m1 = 15.0 # Msun m2 = 14.0 # Msun separation = 0 # 0 = ignored, use period orbital_period = 4530.0 # days eccentricity = 0.0 metallicity = 0.02 max_evolution_time = 15000 log_filename = tempfile.gettempdir() + "/test_log.txt" argstring = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g} log_filename {7:s}".format( m1, m2, separation, orbital_period, eccentricity, metallicity, max_evolution_time, log_filename, ) out = binary_c_python_api.run_binary_custom_logging(argstring, func_memaddr) print(out) #### # test_run_binary() test_run_binary_with_log() # test_return_help() # test_return_arglines() # test_run_binary_with_custom_logging() No newline at end of file Loading
binarycpython/utils/functions.py +1 −2 Original line number Diff line number Diff line Loading @@ -198,11 +198,10 @@ def run_system_with_log(**kwargs): # Run it and get output buffer = "" output = binary_c_python_api.run_binary_with_log(arg_string) output = binary_c_python_api.run_binary_with_logfile(arg_string) return output def parse_output(output, selected_header): """ Function that parses output of binary_c: Loading
tests/python_API_test.py +91 −8 Original line number Diff line number Diff line Loading @@ -2,12 +2,19 @@ import binary_c_python_api from binarycpython.utils.custom_logging_functions import ( autogen_C_logging_code, binary_c_log_code, create_and_load_logging_function, ) import tempfile ############################################################ # Test script to run a binary using the binary_c Python # module. # Test script for the api functions ############################################################ def run_test_binary(): def test_run_binary(): m1 = 15.0 # Msun m2 = 14.0 # Msun separation = 0 # 0 = ignored, use period Loading @@ -15,7 +22,6 @@ def run_test_binary(): eccentricity = 0.0 metallicity = 0.02 max_evolution_time = 15000 buffer = "" argstring = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g} ".format( m1, m2, Loading @@ -28,13 +34,90 @@ def run_test_binary(): output = binary_c_python_api.run_binary(argstring) print("\n\nBinary_c output:\n\n") print("\n\nBinary_c output:") print(output) def run_help(): def test_return_help(): out = binary_c_python_api.return_help('M_1') print(out) run_help() def test_return_arglines(): out = binary_c_python_api.return_arglines() print(out) def test_run_binary_with_log(): m1 = 15.0 # Msun m2 = 14.0 # Msun separation = 0 # 0 = ignored, use period orbital_period = 4530.0 # days eccentricity = 0.0 metallicity = 0.02 max_evolution_time = 15000 log_filename = tempfile.gettempdir() + "/test_log.txt" api_log_filename_prefix = tempfile.gettempdir()+'/test_log' argstring = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g} log_filename {7:s} api_log_filename_prefix {8:s}".format( m1, m2, separation, orbital_period, eccentricity, metallicity, max_evolution_time, log_filename, api_log_filename_prefix, ) output = binary_c_python_api.run_binary_with_logfile(argstring) print("\n\nBinary_c output:") print(output) def test_run_binary_with_custom_logging(): """ """ # generate logging lines. Here you can choose whatever you want to have logged, and with what header # this generates working print statements logging_line = autogen_C_logging_code( {"MY_STELLAR_DATA": ["model.time", "star[0].mass"],} ) # Generate entire shared lib code around logging lines custom_logging_code = binary_c_log_code(logging_line) # Load memory adress func_memaddr = create_and_load_logging_function(custom_logging_code) m1 = 15.0 # Msun m2 = 14.0 # Msun separation = 0 # 0 = ignored, use period orbital_period = 4530.0 # days eccentricity = 0.0 metallicity = 0.02 max_evolution_time = 15000 log_filename = tempfile.gettempdir() + "/test_log.txt" argstring = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g} log_filename {7:s}".format( m1, m2, separation, orbital_period, eccentricity, metallicity, max_evolution_time, log_filename, ) out = binary_c_python_api.run_binary_custom_logging(argstring, func_memaddr) print(out) #### # test_run_binary() test_run_binary_with_log() # test_return_help() # test_return_arglines() # test_run_binary_with_custom_logging() No newline at end of file