46
46
47
47
from __future__ import annotations
48
48
49
- import contextlib
50
49
import json # NOQA
51
50
import os
52
51
import uuid
53
52
from collections .abc import Callable , Generator
53
+ from contextlib import _GeneratorContextManager , contextmanager
54
54
from typing import Any
55
55
56
56
import pytest
@@ -125,15 +125,17 @@ def get_stacktrace_render(data: dict[str, Any]) -> str:
125
125
126
126
127
127
INPUTS = [
128
- CategorizationInput (fname ) for fname in os .listdir (_fixture_path ) if fname .endswith (".json" )
128
+ CategorizationInput (fname )
129
+ for fname in sorted (os .listdir (_fixture_path ))
130
+ if fname .endswith (".json" )
129
131
]
130
132
131
133
132
134
@pytest .mark .parametrize ("input" , INPUTS , ids = lambda x : x .filename [:- 5 ].replace ("-" , "_" ))
133
135
def test_categorization (
134
136
input : CategorizationInput ,
135
137
insta_snapshot : InstaSnapshotter ,
136
- track_enhancers_coverage : Callable [[CategorizationInput ], Any ],
138
+ track_enhancers_coverage : Callable [[CategorizationInput ], _GeneratorContextManager [ None ] ],
137
139
) -> None :
138
140
# XXX: In-process re-runs using pytest-watch or whatever will behave
139
141
# wrongly because input.data is reused between tests, we do this for perf.
@@ -146,13 +148,11 @@ def test_categorization(
146
148
147
149
@pytest .fixture (scope = "session" , autouse = True )
148
150
def track_enhancers_coverage () -> (
149
- Generator [
150
- Callable [[CategorizationInput ], contextlib ._GeneratorContextManager [None , None , None ]]
151
- ]
151
+ Generator [Callable [[CategorizationInput ], _GeneratorContextManager [None ]]]
152
152
):
153
153
ran_tests = {}
154
154
155
- @contextlib . contextmanager
155
+ @contextmanager
156
156
def inner (input : CategorizationInput ) -> Generator [None ]:
157
157
ran_tests [input .filename ] = True
158
158
yield
@@ -225,20 +225,13 @@ def _strip_sensitive_keys(data: dict[str, Any], keep_keys: list[str]) -> bool:
225
225
226
226
keys_stripped = False
227
227
228
- for key in list (data ):
229
- if key not in keep_keys :
230
- del data [key ]
231
- keys_stripped = True
232
-
233
- elif data [key ] is None :
234
- del data [key ]
235
- keys_stripped = True
236
-
237
- elif any (x in key .lower () for x in _DELETE_KEYWORDS ):
238
- del data [key ]
239
- keys_stripped = True
240
-
241
- elif any (x in json .dumps (data [key ]).lower () for x in _DELETE_KEYWORDS ):
228
+ for key in data :
229
+ if (
230
+ key not in keep_keys
231
+ or data [key ] is None
232
+ or any (x in key .lower () for x in _DELETE_KEYWORDS )
233
+ or any (x in json .dumps (data [key ]).lower () for x in _DELETE_KEYWORDS )
234
+ ):
242
235
del data [key ]
243
236
keys_stripped = True
244
237
0 commit comments