utils.normalise_datetime
Contains the utility function that allows for ease of testing the ingestion functions.
1""" 2Contains the utility function that allows for ease of testing the ingestion functions. 3""" 4 5from datetime import datetime 6 7 8def normalise_datetimes(rows): 9 """ 10 Iterates through a list of dictionaries and converts datetime objects to string in the format 'YYYY-MM-DD HH:MM:SS.sss' so they can be compared with expected string values. 11 12 # Arguments: 13 rows: A list of dictionaries; each dictionary represents a data record. 14 15 # Return: 16 A list of dictionaries where the datetime values are formatted as strings. 17 18 """ 19 for row in rows: 20 for key, value in row.items(): 21 if isinstance(value, datetime): 22 row[key] = value.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] 23 return rows
def
normalise_datetimes(rows):
9def normalise_datetimes(rows): 10 """ 11 Iterates through a list of dictionaries and converts datetime objects to string in the format 'YYYY-MM-DD HH:MM:SS.sss' so they can be compared with expected string values. 12 13 # Arguments: 14 rows: A list of dictionaries; each dictionary represents a data record. 15 16 # Return: 17 A list of dictionaries where the datetime values are formatted as strings. 18 19 """ 20 for row in rows: 21 for key, value in row.items(): 22 if isinstance(value, datetime): 23 row[key] = value.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] 24 return rows
Iterates through a list of dictionaries and converts datetime objects to string in the format 'YYYY-MM-DD HH:MM:SS.sss' so they can be compared with expected string values.
Arguments:
rows: A list of dictionaries; each dictionary represents a data record.
Return:
A list of dictionaries where the datetime values are formatted as strings.