diff --git a/scripts/gather_outdated_snapshots.py b/scripts/gather_outdated_snapshots.py index ee287d92aeed1..984e56901c466 100644 --- a/scripts/gather_outdated_snapshots.py +++ b/scripts/gather_outdated_snapshots.py @@ -6,7 +6,11 @@ def get_outdated_snapshots_for_directory( - path: str, date_limit: str, check_sub_directories: bool = True, combine_parametrized=True + path: str, + date_limit: str, + check_sub_directories: bool = True, + combine_parametrized=True, + show_date=False, ) -> dict: """ Fetches all snapshots that were recorded before the given date_limit @@ -20,7 +24,7 @@ def get_outdated_snapshots_for_directory( result = {"date": date_limit} date_limit = datetime.datetime.strptime(date_limit, "%d-%m-%Y") - outdated_snapshots = [] + outdated_snapshots = {} def do_get_outdated_snapshots(path: str): @@ -32,18 +36,19 @@ def do_get_outdated_snapshots(path: str): elif file.endswith(".snapshot.json"): with open(f"{path}{file}") as f: json_content: dict = json.load(f) - for name, snapshot in json_content.items(): - date = snapshot.get("recorded-date") - date = datetime.datetime.strptime(date, "%d-%m-%Y, %H:%M:%S") + for name, recorded_snapshot_data in json_content.items(): + recorded_date = recorded_snapshot_data.get("recorded-date") + date = datetime.datetime.strptime(recorded_date, "%d-%m-%Y, %H:%M:%S") if date < date_limit: + outdated_snapshot_data = dict() + if show_date: + outdated_snapshot_data["recorded-date"] = recorded_date if combine_parametrized: # change parametrized tests of the form to just name = name.split("[")[0] - outdated_snapshots.append(name) + outdated_snapshots[name] = outdated_snapshot_data do_get_outdated_snapshots(path) - # remove duplicates, e.g. combine_parametrized was False - outdated_snapshots = set(outdated_snapshots) result["count"] = len(outdated_snapshots) result["outdated_snapshots"] = outdated_snapshots return result @@ -66,7 +71,14 @@ def do_get_outdated_snapshots(path: str): default=True, help="If True, parametrized snapshots are treated as one", ) -def get_snapshots(path: str, date_limit: str, check_sub_dirs, combine_parametrized): +@click.option( + "--show-date", + type=bool, + required=False, + default=False, + help="Should tests have their recording date attached?", +) +def get_snapshots(path: str, date_limit: str, check_sub_dirs, combine_parametrized, show_date): """ Fetches all snapshots in PATH that were recorded before the given DATE_LIMIT. Format of the DATE_LIMIT-string must be "DD-MM-YYYY". @@ -78,10 +90,10 @@ def get_snapshots(path: str, date_limit: str, check_sub_dirs, combine_parametriz python gather_outdated_snapshots.py ../tests/integration 24-12-2022 | jq . """ snapshots = get_outdated_snapshots_for_directory( - path, date_limit, check_sub_dirs, combine_parametrized + path, date_limit, check_sub_dirs, combine_parametrized, show_date ) # sorted lists are prettier to read in the console - snapshots["outdated_snapshots"] = sorted(snapshots["outdated_snapshots"]) + snapshots["outdated_snapshots"] = dict(sorted(snapshots["outdated_snapshots"].items())) # turn the list of snapshots into a whitespace separated string usable by pytest join = " ".join(snapshots["outdated_snapshots"])