This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyexcel as pe | |
from datetime import datetime | |
from datetime import date | |
import pytest | |
def test_monthly_close_off_checks(): | |
# this is the expected set of errors from business requirements | |
expected_error_code_set = set({'J01','J01.N','J02','J03','A01','A02','A02.N','A03','A04','A05','D01','D02','AV01','AV02','AR01','AR02','AP01','AP02','AP03','AP04','AP05'}) | |
#get today's date in YYYYMMDD format as it is appended at the end of the excel sheet that needs to be parsed | |
today_date = str(date.today().strftime("%Y%m%d")) | |
print(today_date) | |
# using pyexcel object parse the first log file to get a list of ordered dicts for each row in the log file | |
notifications = pe.get_records(file_name = r"CloseOffChecks_Sunjeet\Notifications_"+today_date+".xlsx") | |
# define an empty set to store the list of unique error codes parsed from the log files | |
parsed_error_code = set() | |
#iterate through the rows and get the value of the error code , it is under the column "Error Code" i.e. would be the key in the retrieved dict | |
for n in notifications: | |
#add the error to the set . The set will ensure uniquness ! | |
parsed_error_code.add(n["Error Code"]) | |
print (n) | |
print(parsed_error_code) | |
#same drill as the notifications file above for the error file | |
errors = pe.get_records(file_name = r"CloseOffChecks_Sunjeet\Errors_"+today_date+".xlsx") | |
for e in errors: | |
#append further error codes to the existing set | |
parsed_error_code.add(e["Error Code"]) | |
print (n) | |
print(parsed_error_code) | |
#assert that the parsed set of error codes is the same as the expected set | |
assert(parsed_error_code == expected_error_code_set) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment