def setup_workbook(filepath, sheet_name, max_col, json_rows): if not os.path.exists(filepath): ExcelReader.make_template(filepath) wb = load_workbook(filepath) active_sheet = wb[sheet_name] row_counter = 0 # TODO: Make the max_col more dynamic for row in active_sheet.iter_rows(min_row=2, max_col=max_col, max_row=len(json_rows)+1): for idx, cell in enumerate(row): cell.value = json_rows[row_counter][idx] row_counter += 1 wb.save(filepath)
def test_verify_template_sheets(): # Setup temp_path = "./temp_verfiysheets.xlsx" ExcelReader.make_template(temp_path) # Expected expected_sheets = set([ "ColumnsLineage", "TablesLineage", "EntityDefs", "BulkEntities", "UpdateLineage" ]) wb = load_workbook(temp_path) difference = set(wb.sheetnames).symmetric_difference(expected_sheets) try: assert (len(difference) == 0) finally: wb.close() os.remove(temp_path)