Skip to content

Commit

Permalink
attach data to gathered outdated snapshots (localstack#8980)
Browse files Browse the repository at this point in the history
  • Loading branch information
baermat authored Aug 24, 2023
1 parent fc5570f commit 981173a
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions scripts/gather_outdated_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):

Expand All @@ -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 <mytest[param_value]> to just <mytest>
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
Expand All @@ -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".
Expand All @@ -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"])
Expand Down

0 comments on commit 981173a

Please sign in to comment.