diff --git a/onair/src/util/cleanup.py b/onair/src/util/cleanup.py index 428ca4cd..215c2813 100644 --- a/onair/src/util/cleanup.py +++ b/onair/src/util/cleanup.py @@ -16,5 +16,8 @@ def setup_folders(results_path): + """ + Check if given directory exists and create directory if not + """ if not os.path.isdir(results_path): os.mkdir(results_path) diff --git a/onair/src/util/data_conversion.py b/onair/src/util/data_conversion.py index c888d4e0..b5cd12cb 100644 --- a/onair/src/util/data_conversion.py +++ b/onair/src/util/data_conversion.py @@ -13,12 +13,15 @@ """ import numpy as np -classes = {"RED": 0, "YELLOW": 1, "GREEN": 2, "---": 3} +CLASSES = {"RED": 0, "YELLOW": 1, "GREEN": 2, "---": 3} -def status_to_oneHot(status): +def status_to_one_hot(status): + """ + Convert status string to one hot positional array + """ if isinstance(status, np.ndarray): return status one_hot = [0.0, 0.0, 0.0, 0.0] - one_hot[classes[status]] = 1.0 + one_hot[CLASSES[status]] = 1.0 return list(one_hot) diff --git a/onair/src/util/file_io.py b/onair/src/util/file_io.py index ff3e21df..f743f6d9 100644 --- a/onair/src/util/file_io.py +++ b/onair/src/util/file_io.py @@ -16,12 +16,14 @@ def parse_associations_from_json(filepath): - with open(filepath) as f: - data = json.load(f) + """ + Parse associations from given JSON file + """ + with open(filepath) as file: + data = json.load(file) associations_list = [] - raw_associations = data["children"] - for association in raw_associations: + for association in data["children"]: antecedant = association["name"] for connection in association["connections"]: consequent = connection["target"] @@ -40,4 +42,7 @@ def parse_associations_from_json(filepath): def aggregate_results(): + """ + TODO: This function is a placeholder + """ return diff --git a/onair/src/util/plugin_import.py b/onair/src/util/plugin_import.py index beb0d539..4913a439 100644 --- a/onair/src/util/plugin_import.py +++ b/onair/src/util/plugin_import.py @@ -18,6 +18,9 @@ def import_plugins(headers, module_dict): + """ + Function to import user-specified plugins (from config files) into interfaces + """ plugin_list = [] init_filename = "__init__.py" for construct_name, module_path in module_dict.items(): diff --git a/onair/src/util/print_io.py b/onair/src/util/print_io.py index 4593d553..85033b56 100644 --- a/onair/src/util/print_io.py +++ b/onair/src/util/print_io.py @@ -2,7 +2,7 @@ # # Copyright © 2023 United States Government as represented by the Administrator of # the National Aeronautics and Space Administration. No copyright is claimed in the -# United States under Title 17, U.S. Code. All Other Rights Reserved. +# United States under Title 17, U.print_string. Code. All Other Rights Reserved. # # Licensed under the NASA Open Source Agreement version 1.3 # See "NOSA GSC-19165-1 OnAIR.pdf" @@ -15,159 +15,189 @@ ############################# COLORS ############################# # Static class to hold color constants -class bcolors: - HEADER = "\033[95m" - OKBLUE = "\033[94m" - OKGREEN = "\033[92m" - WARNING = "\033[93m" - FAIL = "\033[91m" - ENDC = "\033[0m" - BOLD = "\033[1m" - UNDERLINE = "\033[4m" +BCOLORS = { + "HEADER": "\033[95m", + "OKBLUE": "\033[94m", + "OKGREEN": "\033[92m", + "WARNING": "\033[93m", + "FAIL": "\033[91m", + "ENDC": "\033[0m", + "BOLD": "\033[1m", + "UNDERLINE": "\033[4m", +} # Global colors dictionary -scolors = { - "HEADER": bcolors.HEADER, - "OKBLUE": bcolors.OKBLUE, - "OKGREEN": bcolors.OKGREEN, - "WARNING": bcolors.WARNING, - "FAIL": bcolors.FAIL, - "ENDC": bcolors.ENDC, - "BOLD": bcolors.BOLD, - "UNDERLINE": bcolors.UNDERLINE, +SCOLORS = { + "HEADER": BCOLORS["HEADER"], + "OKBLUE": BCOLORS["OKBLUE"], + "OKGREEN": BCOLORS["OKGREEN"], + "WARNING": BCOLORS["WARNING"], + "FAIL": BCOLORS["FAIL"], + "ENDC": BCOLORS["ENDC"], + "BOLD": BCOLORS["BOLD"], + "UNDERLINE": BCOLORS["UNDERLINE"], } # Global dictionary for STATUS -> COLOR -status_colors = { - "GREEN": bcolors.OKGREEN, - "YELLOW": bcolors.WARNING, - "RED": bcolors.FAIL, - "---": bcolors.OKBLUE, +STATUS_COLORS = { + "GREEN": BCOLORS["OKGREEN"], + "YELLOW": BCOLORS["WARNING"], + "RED": BCOLORS["FAIL"], + "---": BCOLORS["OKBLUE"], } ############################# I/O ############################# -# Print that the simulation started def print_sim_header(): + """ + Print that the simulation started + """ print( - bcolors.HEADER - + bcolors.BOLD + BCOLORS["HEADER"] + + BCOLORS["BOLD"] + "\n***************************************************" ) print("************ SIMULATION STARTED ************") - print("***************************************************" + bcolors.ENDC) + print("***************************************************" + BCOLORS["ENDC"]) -# Print when a new step is starting def print_sim_step(step_num): + """ + Print when a new sim step is starting + """ print( - bcolors.HEADER - + bcolors.BOLD + BCOLORS["HEADER"] + + BCOLORS["BOLD"] + "\n--------------------- STEP " + str(step_num) + " ---------------------\n" - + bcolors.ENDC + + BCOLORS["ENDC"] ) -# Print a line to separate things -def print_separator(color=bcolors.HEADER): +def print_separator(color=BCOLORS["HEADER"]): + """ + Print a line to separate things + """ print( color - + bcolors.BOLD + + BCOLORS["BOLD"] + "\n------------------------------------------------\n" - + bcolors.ENDC + + BCOLORS["ENDC"] ) -# Print header update -def update_header(msg, clr=bcolors.BOLD): - print(clr + "--------- " + msg + " update" + bcolors.ENDC) +def update_header(msg, clr=BCOLORS["BOLD"]): + """ + Print header update + """ + print(clr + "--------- " + msg + " update" + BCOLORS["ENDC"]) -# Print header update -def print_msg(msg, clrs=["HEADER"]): +def print_msg(msg, clrs=None): + """ + Print a message + """ + if clrs is None: + clrs = ["HEADER"] for clr in clrs: - print(scolors[clr]) - print("---- " + msg + bcolors.ENDC) + print(SCOLORS[clr]) + print("---- " + msg + BCOLORS["ENDC"]) -# Print interpreted system status def print_system_status(agent, data=None): - # print_separator(bcolors.OKBLUE) - if data != None: + """ + Print interpreted system status + """ + # print_separator(BCOLORS["OKBLUE"]) + if data is not None: print("CURRENT DATA: " + str(data)) print("INTERPRETED SYSTEM STATUS: " + str(format_status(agent.mission_status))) - # print_separator(bcolors.OKBLUE) + # print_separator(BCOLORS["OKBLUE"]) -# Print diagnosis info def print_diagnosis(diagnosis): + """ + Print diagnosis info + """ status_list = diagnosis.get_status_list() - tree_traversal = diagnosis.fault_tree activations = diagnosis.current_activations print_separator() - print(bcolors.HEADER + bcolors.BOLD + "DIAGNOSIS INFO: \n" + bcolors.ENDC) + print(BCOLORS["HEADER"] + BCOLORS["BOLD"] + "DIAGNOSIS INFO: \n" + BCOLORS["ENDC"]) for status in status_list: stat = status[1] print(status[0] + ": " + format_status(stat)) - print(bcolors.HEADER + bcolors.BOLD + "\nCURRENT ACTIVATIONS: \n" + bcolors.ENDC) + print( + BCOLORS["HEADER"] + + BCOLORS["BOLD"] + + "\nCURRENT ACTIVATIONS: \n" + + BCOLORS["ENDC"] + ) if len(activations) > 0: for activation in activations: print("---" + str(activation)) print_separator() -# Print subsystem status -def subsystem_status_str(ss): - s = bcolors.BOLD + "[" + str(ss.type) + "] : " + bcolors.ENDC - stat = ss.get_status() - s = ( - s +def subsystem_status_str(subsystem): + """ + Print subsystem status + """ + print_string = ( + BCOLORS["BOLD"] + "[" + str(subsystem.type) + "] : " + BCOLORS["ENDC"] + ) + stat = subsystem.get_status() + print_string = ( + print_string + "\n" - + status_colors[stat] + + STATUS_COLORS[stat] + " ---- " + str(stat) - + bcolors.ENDC + + BCOLORS["ENDC"] + " (" - + str(ss.uncertainty) + + str(subsystem.uncertainty) + ")" ) - return s + "\n" - - -# Print out subsystem information -def subsystem_str(ss): - s = bcolors.BOLD + ss.type + "\n" + bcolors.ENDC - s = s + "--[headers] " - for h in ss.headers: - s = s + "\n---" + str(h) - s = s + "\n--[tests] " - for t in ss.tests: - s = s + "\n---" + str(t) - s = s + "\n--[test data] " - for d in ss.test_data: - s = s + "\n---" + str(d) - return s + return print_string + "\n" + + +def subsystem_str(subsystem): + """ + Print out subsystem information + """ + print_string = BCOLORS["BOLD"] + subsystem.type + "\n" + BCOLORS["ENDC"] + print_string = print_string + "--[headers] " + for header in subsystem.headers: + print_string = print_string + "\n---" + str(header) + print_string = print_string + "\n--[tests] " + for test in subsystem.tests: + print_string = print_string + "\n---" + str(test) + print_string = print_string + "\n--[test data] " + for data in subsystem.test_data: + print_string = print_string + "\n---" + str(data) + return print_string -# Print out headers def headers_string(headers): - s = "" + """ + Print out headers + """ + print_string = "" for hdr in headers: - s = s + "\n -- " + hdr - return s + print_string = print_string + "\n -- " + hdr + return print_string -# Print out status def format_status(stat): - if type(stat) == str: - return status_colors[stat] + stat + scolors["ENDC"] - else: - s = "(" - for status in stat: - s = s + format_status(status) + ", " - s = s[:-2] + ")" - return s + """ + Print out status + """ + if isinstance(stat, str): + return STATUS_COLORS[stat] + stat + SCOLORS["ENDC"] + print_string = "(" + for status in stat: + print_string = print_string + format_status(status) + ", " + print_string = print_string[:-2] + ")" + return print_string diff --git a/onair/src/util/sim_io.py b/onair/src/util/sim_io.py index 6026f8fe..7038df9d 100644 --- a/onair/src/util/sim_io.py +++ b/onair/src/util/sim_io.py @@ -17,6 +17,9 @@ def render_reasoning(diagnosis_list): + """ + Write reasoning to diagnosis output files + """ with open( os.path.join(os.environ.get("ONAIR_DIAGNOSIS_SAVE_PATH"), "diagnosis.txt"), mode="a", @@ -43,6 +46,9 @@ def render_reasoning(diagnosis_list): def render_viz(status_data, sensor_data, sim_name, diagnosis=None): + """ + Write status, associativity, and diagnosis to JSON files + """ # Status Staburst status_report = {} status_report["filename"] = sim_name @@ -71,10 +77,13 @@ def render_viz(status_data, sensor_data, sim_name, diagnosis=None): json.dump(results, outfile) -def print_dots(ts): - incrFlag = ts % 20 - if incrFlag < 10: - dots = ts % 10 +def print_dots(timestep): + """ + Print some dots + """ + incr_flag = timestep % 20 + if incr_flag < 10: + dots = timestep % 10 else: - dots = 10 - (ts % 10) + dots = 10 - (timestep % 10) print("\033[95m" + (dots + 1) * "." + "\033[0m") diff --git a/test/onair/src/util/test_data_conversion.py b/test/onair/src/util/test_data_conversion.py index a930b3ba..fcb19d7f 100644 --- a/test/onair/src/util/test_data_conversion.py +++ b/test/onair/src/util/test_data_conversion.py @@ -16,8 +16,8 @@ from numpy import ndarray -# status_to_oneHot tests -def test_data_conversion_status_to_oneHot_returns_given_status_when_status_isinstance_of_np_ndarray( +# status_to_one_hot tests +def test_data_conversion_status_to_one_hot_returns_given_status_when_status_isinstance_of_np_ndarray( mocker, ): # Arrange @@ -26,7 +26,7 @@ def test_data_conversion_status_to_oneHot_returns_given_status_when_status_isins mocker.patch(data_conversion.__name__ + ".isinstance", return_value=True) # Act - result = data_conversion.status_to_oneHot(arg_status) + result = data_conversion.status_to_one_hot(arg_status) # Assert assert data_conversion.isinstance.call_count == 1 @@ -34,7 +34,7 @@ def test_data_conversion_status_to_oneHot_returns_given_status_when_status_isins assert result == arg_status -def test_data_conversion_status_to_oneHot_returns_one_hot_set_to_list_of_four_zeros_and_the_value_of_the_classes_status_to_1_point_0( +def test_data_conversion_status_to_one_hot_returns_one_hot_set_to_list_of_four_zeros_and_the_value_of_the_classes_status_to_1_point_0( mocker, ): # Arrange @@ -45,12 +45,12 @@ def test_data_conversion_status_to_oneHot_returns_one_hot_set_to_list_of_four_ze expected_result = [0.0, 0.0, 0.0, 0.0] expected_result[fake_status] = 1.0 - data_conversion.classes = {arg_status: fake_status} + data_conversion.CLASSES = {arg_status: fake_status} mocker.patch(data_conversion.__name__ + ".isinstance", return_value=False) # Act - result = data_conversion.status_to_oneHot(arg_status) + result = data_conversion.status_to_one_hot(arg_status) # Assert assert result == expected_result diff --git a/test/onair/src/util/test_print_io.py b/test/onair/src/util/test_print_io.py index 8af9abd5..5ecf644d 100644 --- a/test/onair/src/util/test_print_io.py +++ b/test/onair/src/util/test_print_io.py @@ -13,86 +13,86 @@ import onair.src.util.print_io as print_io -# bcolors tests +# BCOLORS tests def test_print_io_bcolors_HEADER_is_expected_value(): - assert print_io.bcolors.HEADER == "\033[95m" + assert print_io.BCOLORS["HEADER"] == "\033[95m" def test_print_io_bcolors_OKBLUE_is_expected_value(): - assert print_io.bcolors.OKBLUE == "\033[94m" + assert print_io.BCOLORS["OKBLUE"] == "\033[94m" def test_print_io_bcolors_OKGREEN_is_expected_value(): - assert print_io.bcolors.OKGREEN == "\033[92m" + assert print_io.BCOLORS["OKGREEN"] == "\033[92m" def test_print_io_bcolors_WARNING_is_expected_value(): - assert print_io.bcolors.WARNING == "\033[93m" + assert print_io.BCOLORS["WARNING"] == "\033[93m" def test_print_io_bcolors_FAIL_is_expected_value(): - assert print_io.bcolors.FAIL == "\033[91m" + assert print_io.BCOLORS["FAIL"] == "\033[91m" def test_print_io_bcolors_ENDC_is_expected_value(): - assert print_io.bcolors.ENDC == "\033[0m" + assert print_io.BCOLORS["ENDC"] == "\033[0m" def test_print_io_bcolors_BOLD_is_expected_value(): - assert print_io.bcolors.BOLD == "\033[1m" + assert print_io.BCOLORS["BOLD"] == "\033[1m" def test_print_io_bcolors_UNDERLINE_is_expected_value(): - assert print_io.bcolors.UNDERLINE == "\033[4m" + assert print_io.BCOLORS["UNDERLINE"] == "\033[4m" # Globals tests def test_print_io_scolors_HEADER_is_set_to_bcolors_HEADER(): - assert print_io.scolors["HEADER"] == print_io.bcolors.HEADER + assert print_io.SCOLORS["HEADER"] == print_io.BCOLORS["HEADER"] def test_print_io_scolors_OKBLUE_is_set_to_bcolors_OKBLUE(): - assert print_io.scolors["OKBLUE"] == print_io.bcolors.OKBLUE + assert print_io.SCOLORS["OKBLUE"] == print_io.BCOLORS["OKBLUE"] def test_print_io_scolors_OKGREEN_is_set_to_bcolors_OKGREEN(): - assert print_io.scolors["OKGREEN"] == print_io.bcolors.OKGREEN + assert print_io.SCOLORS["OKGREEN"] == print_io.BCOLORS["OKGREEN"] def test_print_io_scolors_WARNING_is_set_to_bcolors_WARNING(): - assert print_io.scolors["WARNING"] == print_io.bcolors.WARNING + assert print_io.SCOLORS["WARNING"] == print_io.BCOLORS["WARNING"] def test_print_io_scolors_FAIL_is_set_to_bcolors_FAIL(): - assert print_io.scolors["FAIL"] == print_io.bcolors.FAIL + assert print_io.SCOLORS["FAIL"] == print_io.BCOLORS["FAIL"] def test_print_io_scolors_ENDC_is_set_to_bcolors_ENDC(): - assert print_io.scolors["ENDC"] == print_io.bcolors.ENDC + assert print_io.SCOLORS["ENDC"] == print_io.BCOLORS["ENDC"] def test_print_io_scolors_BOLD_is_set_to_bcolors_BOLD(): - assert print_io.scolors["BOLD"] == print_io.bcolors.BOLD + assert print_io.SCOLORS["BOLD"] == print_io.BCOLORS["BOLD"] def test_print_io_scolors_UNDERLINE_is_set_to_bcolors_UNDERLINE(): - assert print_io.scolors["UNDERLINE"] == print_io.bcolors.UNDERLINE + assert print_io.SCOLORS["UNDERLINE"] == print_io.BCOLORS["UNDERLINE"] def test_print_io_status_colors_GREEN_is_set_to_bcolors_OKGREEN(): - assert print_io.status_colors["GREEN"] == print_io.bcolors.OKGREEN + assert print_io.STATUS_COLORS["GREEN"] == print_io.BCOLORS["OKGREEN"] def test_print_io_status_colors_YELLOW_is_set_to_bcolors_WARNING(): - assert print_io.status_colors["YELLOW"] == print_io.bcolors.WARNING + assert print_io.STATUS_COLORS["YELLOW"] == print_io.BCOLORS["WARNING"] def test_print_io_status_colors_RED_is_set_to_bcolors_FAIL(): - assert print_io.status_colors["RED"] == print_io.bcolors.FAIL + assert print_io.STATUS_COLORS["RED"] == print_io.BCOLORS["FAIL"] def test_print_io_status_colors_3_dashes_is_set_to_bcolors_OKBLUE(): - assert print_io.status_colors["---"] == print_io.bcolors.OKBLUE + assert print_io.STATUS_COLORS["---"] == print_io.BCOLORS["OKBLUE"] # print_sim_header tests @@ -100,13 +100,13 @@ def test_print_io_print_sim_header_prints_expected_strings(mocker): # Arrange expected_print = [] expected_print.append( - print_io.bcolors.HEADER - + print_io.bcolors.BOLD + print_io.BCOLORS["HEADER"] + + print_io.BCOLORS["BOLD"] + "\n***************************************************" ) expected_print.append("************ SIMULATION STARTED ************") expected_print.append( - "***************************************************" + print_io.bcolors.ENDC + "***************************************************" + print_io.BCOLORS["ENDC"] ) mocker.patch(print_io.__name__ + ".print") @@ -124,11 +124,11 @@ def test_print_io_print_sim_step_inserts_given_step_num_into_text(mocker): # Arrange arg_step_num = pytest.gen.randint(1, 100) # arbitrary from 1 to 100 expected_print = ( - print_io.bcolors.HEADER - + print_io.bcolors.BOLD + print_io.BCOLORS["HEADER"] + + print_io.BCOLORS["BOLD"] + f"\n--------------------- STEP {arg_step_num}" + " ---------------------\n" - + print_io.bcolors.ENDC + + print_io.BCOLORS["ENDC"] ) mocker.patch(print_io.__name__ + ".print") @@ -143,12 +143,12 @@ def test_print_io_print_sim_step_inserts_given_step_num_into_text(mocker): # print_separator tests def test_print_io_print_separator_uses_bcolors_HEADER_as_default_color_value(mocker): # Arrange - expected_color = print_io.bcolors.HEADER + expected_color = print_io.BCOLORS["HEADER"] expected_print = ( expected_color - + print_io.bcolors.BOLD + + print_io.BCOLORS["BOLD"] + "\n------------------------------------------------\n" - + print_io.bcolors.ENDC + + print_io.BCOLORS["ENDC"] ) mocker.patch(print_io.__name__ + ".print") @@ -168,9 +168,9 @@ def test_print_io_print_separator_prints_whatever_is_passed_in_as_color_at_start expected_print = ( arg_color - + print_io.bcolors.BOLD + + print_io.BCOLORS["BOLD"] + "\n------------------------------------------------\n" - + print_io.bcolors.ENDC + + print_io.BCOLORS["ENDC"] ) mocker.patch(print_io.__name__ + ".print") @@ -190,9 +190,9 @@ def test_print_io_update_header_prints_message_with_bcolors_BOLD_at_start_when_n # Arrange arg_msg = MagicMock() - expected_clr = print_io.bcolors.BOLD + expected_clr = print_io.BCOLORS["BOLD"] expected_print = ( - expected_clr + "--------- " + arg_msg + " update" + print_io.bcolors.ENDC + expected_clr + "--------- " + arg_msg + " update" + print_io.BCOLORS["ENDC"] ) mocker.patch(print_io.__name__ + ".print") @@ -213,7 +213,7 @@ def test_print_io_update_header_prints_message_starting_with_whatever_is_given_a arg_clr = MagicMock() expected_print = ( - arg_clr + "--------- " + arg_msg + " update" + print_io.bcolors.ENDC + arg_clr + "--------- " + arg_msg + " update" + print_io.BCOLORS["ENDC"] ) mocker.patch(print_io.__name__ + ".print") @@ -233,10 +233,10 @@ def test_print_io_print_msg_prints_message_starting_only_with_scolor_HEADER_when # Arrange arg_msg = MagicMock() - expected_scolor = print_io.scolors["HEADER"] + expected_scolor = print_io.SCOLORS["HEADER"] expected_print = [] expected_print.append(expected_scolor) - expected_print.append("---- " + arg_msg + print_io.bcolors.ENDC) + expected_print.append("---- " + arg_msg + print_io.BCOLORS["ENDC"]) mocker.patch(print_io.__name__ + ".print") @@ -278,14 +278,14 @@ def test_print_io_print_msg_prints_only_given_msg_when_given_clrs_is_empty(mocke # Assert assert print_io.print.call_count == 1 assert print_io.print.call_args_list[0].args == ( - "---- " + arg_msg + print_io.bcolors.ENDC, + "---- " + arg_msg + print_io.BCOLORS["ENDC"], ) def test_print_io_print_msg_prints_all_scolors_given_in_clrs(mocker): # Arrange arg_msg = MagicMock() - arg_clrs = list(print_io.scolors.keys()) + arg_clrs = list(print_io.SCOLORS.keys()) pytest.gen.shuffle(arg_clrs) # change up the order to show it does not matter mocker.patch(print_io.__name__ + ".print") @@ -294,11 +294,11 @@ def test_print_io_print_msg_prints_all_scolors_given_in_clrs(mocker): print_io.print_msg(arg_msg, arg_clrs) # Assert - assert print_io.print.call_count == len(print_io.scolors.keys()) + 1 + assert print_io.print.call_count == len(print_io.SCOLORS.keys()) + 1 for i in range(len(arg_clrs)): - assert print_io.print.call_args_list[i].args == (print_io.scolors[arg_clrs[i]],) + assert print_io.print.call_args_list[i].args == (print_io.SCOLORS[arg_clrs[i]],) assert print_io.print.call_args_list[i + 1].args == ( - "---- " + arg_msg + print_io.bcolors.ENDC, + "---- " + arg_msg + print_io.BCOLORS["ENDC"], ) @@ -403,16 +403,16 @@ def test_print_io_print_diagnosis_only_prints_separators_and_headers_when_status assert print_io.print_separator.call_count == 2 assert print_io.print.call_count == 2 assert print_io.print.call_args_list[0].args == ( - print_io.bcolors.HEADER - + print_io.bcolors.BOLD + print_io.BCOLORS["HEADER"] + + print_io.BCOLORS["BOLD"] + "DIAGNOSIS INFO: \n" - + print_io.bcolors.ENDC, + + print_io.BCOLORS["ENDC"], ) assert print_io.print.call_args_list[1].args == ( - print_io.bcolors.HEADER - + print_io.bcolors.BOLD + print_io.BCOLORS["HEADER"] + + print_io.BCOLORS["BOLD"] + "\nCURRENT ACTIVATIONS: \n" - + print_io.bcolors.ENDC, + + print_io.BCOLORS["ENDC"], ) @@ -450,10 +450,10 @@ def test_print_io_print_diagnosis_prints_separators_headers_status_and_activatio assert print_io.print_separator.call_count == 2 assert print_io.print.call_count == 2 + num_status + num_activations assert print_io.print.call_args_list[0].args == ( - print_io.bcolors.HEADER - + print_io.bcolors.BOLD + print_io.BCOLORS["HEADER"] + + print_io.BCOLORS["BOLD"] + "DIAGNOSIS INFO: \n" - + print_io.bcolors.ENDC, + + print_io.BCOLORS["ENDC"], ) for i in range(num_status): assert print_io.print.call_args_list[1 + i].args == ( @@ -461,10 +461,10 @@ def test_print_io_print_diagnosis_prints_separators_headers_status_and_activatio ) assert print_io.format_status.call_args_list[i].args == (fake_status[i][1],) assert print_io.print.call_args_list[1 + num_status].args == ( - print_io.bcolors.HEADER - + print_io.bcolors.BOLD + print_io.BCOLORS["HEADER"] + + print_io.BCOLORS["BOLD"] + "\nCURRENT ACTIVATIONS: \n" - + print_io.bcolors.ENDC, + + print_io.BCOLORS["ENDC"], ) for i in range(num_activations): assert print_io.print.call_args_list[2 + num_status + i].args == ( @@ -481,18 +481,18 @@ def test_print_io_subsystem_status_str_returns_expected_string_when_stat_exists_ arg_ss = MagicMock() fake_type = MagicMock() - fake_stat = pytest.gen.choice(list(print_io.status_colors.keys())) + fake_stat = pytest.gen.choice(list(print_io.STATUS_COLORS.keys())) fake_uncertainty = MagicMock() fake_str = MagicMock() - expected_s = print_io.bcolors.BOLD + "[" + fake_str + "] : " + print_io.bcolors.ENDC + expected_s = print_io.BCOLORS["BOLD"] + "[" + fake_str + "] : " + print_io.BCOLORS["ENDC"] expected_s = ( expected_s + "\n" - + print_io.status_colors[fake_stat] + + print_io.STATUS_COLORS[fake_stat] + " ---- " + fake_str - + print_io.bcolors.ENDC + + print_io.BCOLORS["ENDC"] + " (" + fake_str + ")" @@ -528,7 +528,7 @@ def test_print_io_subsystem_str_returns_string_without_any_data_when_headers_tes arg_ss.tests = [] arg_ss.test_data = [] - expected_result = print_io.bcolors.BOLD + arg_ss.type + "\n" + print_io.bcolors.ENDC + expected_result = print_io.BCOLORS["BOLD"] + arg_ss.type + "\n" + print_io.BCOLORS["ENDC"] expected_result = expected_result + "--[headers] \n--[tests] \n--[test data] " # Act @@ -552,7 +552,7 @@ def test_print_io_subsystem_str_returns_string_all_data_when_headers_tests_and_t num_test_data = pytest.gen.randint(1, 10) # arbitrary from 1 to 10 arg_ss.test_data = [] - expected_result = print_io.bcolors.BOLD + arg_ss.type + "\n" + print_io.bcolors.ENDC + expected_result = print_io.BCOLORS["BOLD"] + arg_ss.type + "\n" + print_io.BCOLORS["ENDC"] expected_result = expected_result + "--[headers] " for i in range(num_headers): arg_ss.headers.append(MagicMock()) @@ -620,10 +620,10 @@ def test_print_io_format_status_raises_KeyError_when_stat_is_string_and_not_in_s def test_print_io_format_status_returns_stat_in_its_status_color_when_stat_is_string_and_a_key(): # Arrange - arg_stat = pytest.gen.choice(list(print_io.status_colors.keys())) + arg_stat = pytest.gen.choice(list(print_io.STATUS_COLORS.keys())) expected_result = ( - print_io.status_colors[arg_stat] + arg_stat + print_io.scolors["ENDC"] + print_io.STATUS_COLORS[arg_stat] + arg_stat + print_io.SCOLORS["ENDC"] ) # Act @@ -655,9 +655,9 @@ def test_print_io_format_status_returns_all_status_in_stat_formatted_into_string expected_result = "(" for i in range(num_stat): - arg_stat.append(pytest.gen.choice(list(print_io.status_colors.keys()))) + arg_stat.append(pytest.gen.choice(list(print_io.STATUS_COLORS.keys()))) expected_result += ( - print_io.status_colors[arg_stat[i]] + arg_stat[i] + print_io.scolors["ENDC"] + print_io.STATUS_COLORS[arg_stat[i]] + arg_stat[i] + print_io.SCOLORS["ENDC"] ) if i != (num_stat - 1): expected_result += ", "