66
77
88def get_outdated_snapshots_for_directory (
9- path : str , date_limit : str , check_sub_directories : bool = True , combine_parametrized = True
9+ path : str ,
10+ date_limit : str ,
11+ check_sub_directories : bool = True ,
12+ combine_parametrized = True ,
13+ show_date = False ,
1014) -> dict :
1115 """
1216 Fetches all snapshots that were recorded before the given date_limit
@@ -20,7 +24,7 @@ def get_outdated_snapshots_for_directory(
2024
2125 result = {"date" : date_limit }
2226 date_limit = datetime .datetime .strptime (date_limit , "%d-%m-%Y" )
23- outdated_snapshots = []
27+ outdated_snapshots = {}
2428
2529 def do_get_outdated_snapshots (path : str ):
2630
@@ -32,18 +36,19 @@ def do_get_outdated_snapshots(path: str):
3236 elif file .endswith (".snapshot.json" ):
3337 with open (f"{ path } { file } " ) as f :
3438 json_content : dict = json .load (f )
35- for name , snapshot in json_content .items ():
36- date = snapshot .get ("recorded-date" )
37- date = datetime .datetime .strptime (date , "%d-%m-%Y, %H:%M:%S" )
39+ for name , recorded_snapshot_data in json_content .items ():
40+ recorded_date = recorded_snapshot_data .get ("recorded-date" )
41+ date = datetime .datetime .strptime (recorded_date , "%d-%m-%Y, %H:%M:%S" )
3842 if date < date_limit :
43+ outdated_snapshot_data = dict ()
44+ if show_date :
45+ outdated_snapshot_data ["recorded-date" ] = recorded_date
3946 if combine_parametrized :
4047 # change parametrized tests of the form <mytest[param_value]> to just <mytest>
4148 name = name .split ("[" )[0 ]
42- outdated_snapshots . append ( name )
49+ outdated_snapshots [ name ] = outdated_snapshot_data
4350
4451 do_get_outdated_snapshots (path )
45- # remove duplicates, e.g. combine_parametrized was False
46- outdated_snapshots = set (outdated_snapshots )
4752 result ["count" ] = len (outdated_snapshots )
4853 result ["outdated_snapshots" ] = outdated_snapshots
4954 return result
@@ -66,7 +71,14 @@ def do_get_outdated_snapshots(path: str):
6671 default = True ,
6772 help = "If True, parametrized snapshots are treated as one" ,
6873)
69- def get_snapshots (path : str , date_limit : str , check_sub_dirs , combine_parametrized ):
74+ @click .option (
75+ "--show-date" ,
76+ type = bool ,
77+ required = False ,
78+ default = False ,
79+ help = "Should tests have their recording date attached?" ,
80+ )
81+ def get_snapshots (path : str , date_limit : str , check_sub_dirs , combine_parametrized , show_date ):
7082 """
7183 Fetches all snapshots in PATH that were recorded before the given DATE_LIMIT.
7284 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
7890 python gather_outdated_snapshots.py ../tests/integration 24-12-2022 | jq .
7991 """
8092 snapshots = get_outdated_snapshots_for_directory (
81- path , date_limit , check_sub_dirs , combine_parametrized
93+ path , date_limit , check_sub_dirs , combine_parametrized , show_date
8294 )
8395 # sorted lists are prettier to read in the console
84- snapshots ["outdated_snapshots" ] = sorted (snapshots ["outdated_snapshots" ])
96+ snapshots ["outdated_snapshots" ] = dict ( sorted (snapshots ["outdated_snapshots" ]. items ()) )
8597
8698 # turn the list of snapshots into a whitespace separated string usable by pytest
8799 join = " " .join (snapshots ["outdated_snapshots" ])
0 commit comments