Index: shared/scripts/configuration/utility.py =================================================================== diff -u -ref981744e6899b22a40fef4a8d74db9a4e930575 -rc79559a8ecd6dc676c7aed956ba1a5d1e45534a0 --- shared/scripts/configuration/utility.py (.../utility.py) (revision ef981744e6899b22a40fef4a8d74db9a4e930575) +++ shared/scripts/configuration/utility.py (.../utility.py) (revision c79559a8ecd6dc676c7aed956ba1a5d1e45534a0) @@ -18,6 +18,8 @@ import squish import shutil import test +import re + from builtins import format from builtins import str as pyStr from builtins import int as pyInt @@ -27,7 +29,6 @@ from datetime import timezone from datetime import datetime - def color_verification(exp_val = "Red", act_val = "#c53b33"): test.compare(config.COLOR_CODES[color_name],(act_val.color[name])) @@ -155,6 +156,9 @@ names.o_vitals_reading["text"] = reading return names.o_vitals_reading +def get_heparin_string_with_mock(originalString): + return re.sub("{.*?}", "0.1mL", originalString) + def erase_entered_value(input_field): """ Method to erase the entered value @@ -163,9 +167,10 @@ test.startSection("Erasing value") input_field= squish.waitForObject(input_field) entered_value = str(input_field.text) - for value in range(len(entered_value)+1): - utils.waitForGUI(0.1) - squish.mouseClick(squish.waitForObjectExists(names.o_back_space_key)) + if len(entered_value) != 0: + for value in range(len(entered_value)+1): + utils.waitForGUI(0.1) + squish.mouseClick(squish.waitForObjectExists(names.o_back_space_key)) test.compare(str(input_field.text), "", "Input field should be empty") test.endSection() @@ -622,29 +627,39 @@ return False def get_message_from_log(file_name, message_text, check_ack_bak = False): - MAX_LINE = 30 + MAX_LINE = 100 lines_from_last = 0 test.log(str(file_name)) message_to_return = None ack_bak_message = None - with open(file_name, 'r') as log_file: - lines = reversed(list(log_file.readlines())) - for line in lines: - if message_text in line: - message_to_return = line - if check_ack_bak: - continue - else: - return message_to_return, ack_bak_message - elif lines_from_last >= MAX_LINE: - if message_to_return is not None: - return message_to_return, ack_bak_message - test.fail("handler unable to find message text from log file.") - return message_to_return, ack_bak_message + try: + with open(file_name, 'r') as log_file: + listOfLines = list(log_file.readlines()) + if len(listOfLines) > 0: + lines = reversed(listOfLines) + for line in lines: + if message_text in line: + message_to_return = line + if check_ack_bak: + continue + else: + return message_to_return, ack_bak_message + elif lines_from_last >= MAX_LINE: + if message_to_return is not None: + return message_to_return, ack_bak_message + test.fail("handler unable to find message text from log file.") + return message_to_return, ack_bak_message + else: + if config.ACK_BAK_STATUS in line: + ack_bak_message = line + lines_from_last += 1 else: - if config.ACK_BAK_STATUS in line: - ack_bak_message = line - lines_from_last += 1 + test.fail(f"Log file is empty - {file_name}") + return None, None + except IOError: + # file opening failed + test.fail(f"ERROR : Opening {file_name} failed") + return None, None # def get_message_from_log(file_name, message_text): # @@ -995,7 +1010,7 @@ latest_file = config.INP_BUF_FILE_LOCATION + current_date + '_inp.buf' return latest_file except: - return False + return "" def retrive_log_data(readline_count = 1): """ @@ -1007,6 +1022,10 @@ cloudsync_data = [] count = 0 file_name = get_extracted_input_buf_file() + if len(file_name) == 0: + #empty filename, fail + test.fail("Extracted input buffer filename empty, error") + return [] try: with open(file_name,mode = 'r') as filereader: contents = csv.reader(filereader)