Loading binarycpython/tests/test_event_logging.py +10 −6 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ from binarycpython.utils.event_logging import ( from binarycpython.utils.functions import Capturing, temp_dir TMP_DIR = temp_dir("tests", "test_event_logging") EVENT_TYPE_INDEX = 2 def setup_data_dir(dirname): Loading Loading @@ -86,7 +87,7 @@ class test_event_types(unittest.TestCase): event_log_values = line.split()[1:] # select current event type if event_log_values[1] == event_type: if event_log_values[EVENT_TYPE_INDEX] == event_type: self.assertTrue( len(event_log_values) == len( Loading Loading @@ -130,7 +131,7 @@ class test_event_types(unittest.TestCase): event_log_values = line.split()[1:] # select current event type if event_log_values[1] == event_type: if event_log_values[EVENT_TYPE_INDEX] == event_type: self.assertTrue( len(event_log_values) == len( Loading Loading @@ -174,7 +175,7 @@ class test_event_types(unittest.TestCase): event_log_values = line.split()[1:] # select current event type if event_log_values[1] == event_type: if event_log_values[EVENT_TYPE_INDEX] == event_type: self.assertTrue( len(event_log_values) == len( Loading Loading @@ -218,7 +219,7 @@ class test_event_types(unittest.TestCase): event_log_values = line.split()[1:] # select current event type if event_log_values[1] == event_type: if event_log_values[EVENT_TYPE_INDEX] == event_type: self.assertTrue( len(event_log_values) == len( Loading Loading @@ -361,7 +362,7 @@ class test_event_file_processing(unittest.TestCase): # extract event types all_event_types = [] for event in all_events_list: all_event_types.append(event.split()[1]) all_event_types.append(event.split()[EVENT_TYPE_INDEX]) # check unique events equals the number that we expect, and also that they only occur once self.assertTrue(len(set(all_event_types)) == 3) Loading Loading @@ -444,7 +445,7 @@ class test_event_file_processing(unittest.TestCase): # extract event types all_event_types = [] for event in all_events_list: all_event_types.append(event.split()[1]) all_event_types.append(event.split()[EVENT_TYPE_INDEX]) # check unique events equals the number that we expect, and also that they only occur once self.assertTrue(len(set(all_event_types)) == 3) Loading Loading @@ -545,3 +546,6 @@ class test_event_file_processing(unittest.TestCase): if __name__ == "__main__": unittest.main() # test_event_file_processing_obj = test_event_file_processing() # test_event_file_processing_obj._test_individual_event_file_processing() binarycpython/tests/test_grid.py +11 −3 Original line number Diff line number Diff line Loading @@ -31,7 +31,13 @@ import unittest import numpy as np from binarycpython.utils.dicts import merge_dicts from binarycpython.utils.functions import Capturing, bin_data, remove_file, temp_dir from binarycpython.utils.functions import ( Capturing, bin_data, output_lines, remove_file, temp_dir, ) from binarycpython.utils.population_class import Population TMP_DIR = temp_dir("tests", "test_grid") Loading Loading @@ -80,7 +86,7 @@ def parse_function_adding_results(self, output): # pragma: no cover self.population_results["example"]["count"] += 1 # Go over the output. for line in output.splitlines(): for line in output_lines(output): headerline = line.split()[0] # CHeck the header and act accordingly Loading Loading @@ -1185,4 +1191,6 @@ Printf("TEST_CUSTOM_LOGGING_1 %30.12e %g %g %g %g\\n", if __name__ == "__main__": unittest.main() # unittest.main() test_resultdict_obj = test_resultdict() test_resultdict_obj._test_adding_results() binarycpython/utils/ensemble.py +2 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ from binarycpython.utils.dicts import ( recursive_change_key_to_float, recursive_change_key_to_string, ) from binarycpython.utils.functions import output_lines from binarycpython.utils.logging_functions import verbose_print Loading Loading @@ -263,7 +264,7 @@ def extract_ensemble_json_from_string(binary_c_output: str) -> dict: ensemble_jsons_strings = [ line for line in binary_c_output.splitlines() for line in output_lines(binary_c_output) if line.startswith("ENSEMBLE_JSON") ] Loading binarycpython/utils/event_logging.py +4 −3 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ import astropy.units as u from binarycpython.utils.functions import get_numerical_value, output_lines dimensionless_unit = u.m / u.m EVENT_TYPE_INDEX = 2 ######################## # event based logging header dictionary Loading Loading @@ -564,7 +565,7 @@ def event_based_logging_output_parser( if line.startswith("EVENT"): events_values = line.split()[1:] # Check for correct length event_type = events_values[2] event_type = events_values[EVENT_TYPE_INDEX] if not len(events_values) == len( events_parameters_list_dict[event_type] ): Loading Loading @@ -600,7 +601,7 @@ def event_based_logging_split_event_types_to_files( with open(input_file, "r") as f: for line in f: values = line.strip().split() event_type = values[2] event_type = values[EVENT_TYPE_INDEX] if event_type not in unique_events_list: unique_events_list.append(event_type) Loading Loading @@ -629,7 +630,7 @@ def event_based_logging_split_event_types_to_files( with open(input_file, "r") as source_f: for line in source_f: events_values = line.strip().split() event_type = events_values[2] event_type = events_values[EVENT_TYPE_INDEX] if event_type == unique_event: # Check if we have the same length of values as to what we expect based on the parameter list Loading binarycpython/utils/functions.py +5 −1 Original line number Diff line number Diff line Loading @@ -593,6 +593,8 @@ def output_lines(output: str) -> list: """ Function that outputs the lines that were received from the binary_c run, but now as an iterator. This function filters out lines that are empty. Args: output: raw binary_c output Loading @@ -601,7 +603,9 @@ def output_lines(output: str) -> list: """ if output: return output.splitlines() for line in output.splitlines(): if line: yield line return [] Loading Loading
binarycpython/tests/test_event_logging.py +10 −6 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ from binarycpython.utils.event_logging import ( from binarycpython.utils.functions import Capturing, temp_dir TMP_DIR = temp_dir("tests", "test_event_logging") EVENT_TYPE_INDEX = 2 def setup_data_dir(dirname): Loading Loading @@ -86,7 +87,7 @@ class test_event_types(unittest.TestCase): event_log_values = line.split()[1:] # select current event type if event_log_values[1] == event_type: if event_log_values[EVENT_TYPE_INDEX] == event_type: self.assertTrue( len(event_log_values) == len( Loading Loading @@ -130,7 +131,7 @@ class test_event_types(unittest.TestCase): event_log_values = line.split()[1:] # select current event type if event_log_values[1] == event_type: if event_log_values[EVENT_TYPE_INDEX] == event_type: self.assertTrue( len(event_log_values) == len( Loading Loading @@ -174,7 +175,7 @@ class test_event_types(unittest.TestCase): event_log_values = line.split()[1:] # select current event type if event_log_values[1] == event_type: if event_log_values[EVENT_TYPE_INDEX] == event_type: self.assertTrue( len(event_log_values) == len( Loading Loading @@ -218,7 +219,7 @@ class test_event_types(unittest.TestCase): event_log_values = line.split()[1:] # select current event type if event_log_values[1] == event_type: if event_log_values[EVENT_TYPE_INDEX] == event_type: self.assertTrue( len(event_log_values) == len( Loading Loading @@ -361,7 +362,7 @@ class test_event_file_processing(unittest.TestCase): # extract event types all_event_types = [] for event in all_events_list: all_event_types.append(event.split()[1]) all_event_types.append(event.split()[EVENT_TYPE_INDEX]) # check unique events equals the number that we expect, and also that they only occur once self.assertTrue(len(set(all_event_types)) == 3) Loading Loading @@ -444,7 +445,7 @@ class test_event_file_processing(unittest.TestCase): # extract event types all_event_types = [] for event in all_events_list: all_event_types.append(event.split()[1]) all_event_types.append(event.split()[EVENT_TYPE_INDEX]) # check unique events equals the number that we expect, and also that they only occur once self.assertTrue(len(set(all_event_types)) == 3) Loading Loading @@ -545,3 +546,6 @@ class test_event_file_processing(unittest.TestCase): if __name__ == "__main__": unittest.main() # test_event_file_processing_obj = test_event_file_processing() # test_event_file_processing_obj._test_individual_event_file_processing()
binarycpython/tests/test_grid.py +11 −3 Original line number Diff line number Diff line Loading @@ -31,7 +31,13 @@ import unittest import numpy as np from binarycpython.utils.dicts import merge_dicts from binarycpython.utils.functions import Capturing, bin_data, remove_file, temp_dir from binarycpython.utils.functions import ( Capturing, bin_data, output_lines, remove_file, temp_dir, ) from binarycpython.utils.population_class import Population TMP_DIR = temp_dir("tests", "test_grid") Loading Loading @@ -80,7 +86,7 @@ def parse_function_adding_results(self, output): # pragma: no cover self.population_results["example"]["count"] += 1 # Go over the output. for line in output.splitlines(): for line in output_lines(output): headerline = line.split()[0] # CHeck the header and act accordingly Loading Loading @@ -1185,4 +1191,6 @@ Printf("TEST_CUSTOM_LOGGING_1 %30.12e %g %g %g %g\\n", if __name__ == "__main__": unittest.main() # unittest.main() test_resultdict_obj = test_resultdict() test_resultdict_obj._test_adding_results()
binarycpython/utils/ensemble.py +2 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ from binarycpython.utils.dicts import ( recursive_change_key_to_float, recursive_change_key_to_string, ) from binarycpython.utils.functions import output_lines from binarycpython.utils.logging_functions import verbose_print Loading Loading @@ -263,7 +264,7 @@ def extract_ensemble_json_from_string(binary_c_output: str) -> dict: ensemble_jsons_strings = [ line for line in binary_c_output.splitlines() for line in output_lines(binary_c_output) if line.startswith("ENSEMBLE_JSON") ] Loading
binarycpython/utils/event_logging.py +4 −3 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ import astropy.units as u from binarycpython.utils.functions import get_numerical_value, output_lines dimensionless_unit = u.m / u.m EVENT_TYPE_INDEX = 2 ######################## # event based logging header dictionary Loading Loading @@ -564,7 +565,7 @@ def event_based_logging_output_parser( if line.startswith("EVENT"): events_values = line.split()[1:] # Check for correct length event_type = events_values[2] event_type = events_values[EVENT_TYPE_INDEX] if not len(events_values) == len( events_parameters_list_dict[event_type] ): Loading Loading @@ -600,7 +601,7 @@ def event_based_logging_split_event_types_to_files( with open(input_file, "r") as f: for line in f: values = line.strip().split() event_type = values[2] event_type = values[EVENT_TYPE_INDEX] if event_type not in unique_events_list: unique_events_list.append(event_type) Loading Loading @@ -629,7 +630,7 @@ def event_based_logging_split_event_types_to_files( with open(input_file, "r") as source_f: for line in source_f: events_values = line.strip().split() event_type = events_values[2] event_type = events_values[EVENT_TYPE_INDEX] if event_type == unique_event: # Check if we have the same length of values as to what we expect based on the parameter list Loading
binarycpython/utils/functions.py +5 −1 Original line number Diff line number Diff line Loading @@ -593,6 +593,8 @@ def output_lines(output: str) -> list: """ Function that outputs the lines that were received from the binary_c run, but now as an iterator. This function filters out lines that are empty. Args: output: raw binary_c output Loading @@ -601,7 +603,9 @@ def output_lines(output: str) -> list: """ if output: return output.splitlines() for line in output.splitlines(): if line: yield line return [] Loading