Marco Ricci commited on 2024-10-14 22:20:29
Zeige 2 geänderte Dateien mit 31 Einfügungen und 31 Löschungen.
The generation of vault service configurations is not inherently tied to the `vault` module only; the CLI also requires its use. So move it to a more central location.
... | ... |
@@ -321,6 +321,36 @@ def _test_config_ids(val: VaultTestConfig) -> Any: # pragma: no cover |
321 | 321 |
return val[1] or (val[0], val[1], val[2]) |
322 | 322 |
|
323 | 323 |
|
324 |
+@strategies.composite |
|
325 |
+def vault_full_service_config(draw: strategies.DrawFn) -> dict[str, int]: |
|
326 |
+ lower = draw(strategies.integers(min_value=0, max_value=10)) |
|
327 |
+ upper = draw(strategies.integers(min_value=0, max_value=10)) |
|
328 |
+ number = draw(strategies.integers(min_value=0, max_value=10)) |
|
329 |
+ space = draw(strategies.integers(min_value=0, max_value=10)) |
|
330 |
+ dash = draw(strategies.integers(min_value=0, max_value=10)) |
|
331 |
+ symbol = draw(strategies.integers(min_value=0, max_value=10)) |
|
332 |
+ repeat = draw(strategies.integers(min_value=0, max_value=10)) |
|
333 |
+ length = draw( |
|
334 |
+ strategies.integers( |
|
335 |
+ min_value=max(1, lower + upper + number + space + dash + symbol), |
|
336 |
+ max_value=70, |
|
337 |
+ ) |
|
338 |
+ ) |
|
339 |
+ hypothesis.assume(lower + upper + number + dash + symbol > 0) |
|
340 |
+ hypothesis.assume(lower + upper + number + space + symbol > 0) |
|
341 |
+ hypothesis.assume(repeat >= space) |
|
342 |
+ return { |
|
343 |
+ 'lower': lower, |
|
344 |
+ 'upper': upper, |
|
345 |
+ 'number': number, |
|
346 |
+ 'space': space, |
|
347 |
+ 'dash': dash, |
|
348 |
+ 'symbol': symbol, |
|
349 |
+ 'repeat': repeat, |
|
350 |
+ 'length': length, |
|
351 |
+ } |
|
352 |
+ |
|
353 |
+ |
|
324 | 354 |
def is_smudgable_vault_test_config(conf: VaultTestConfig) -> bool: |
325 | 355 |
"""Check whether this vault test config can be effectively smudged. |
326 | 356 |
|
... | ... |
@@ -268,43 +268,13 @@ class TestVault: |
268 | 268 |
assert v._estimate_sufficient_hash_length(None) # type: ignore[arg-type] |
269 | 269 |
|
270 | 270 |
|
271 |
-@strategies.composite |
|
272 |
-def vault_config(draw: strategies.DrawFn) -> dict[str, int]: |
|
273 |
- lower = draw(strategies.integers(min_value=0, max_value=10)) |
|
274 |
- upper = draw(strategies.integers(min_value=0, max_value=10)) |
|
275 |
- number = draw(strategies.integers(min_value=0, max_value=10)) |
|
276 |
- space = draw(strategies.integers(min_value=0, max_value=10)) |
|
277 |
- dash = draw(strategies.integers(min_value=0, max_value=10)) |
|
278 |
- symbol = draw(strategies.integers(min_value=0, max_value=10)) |
|
279 |
- repeat = draw(strategies.integers(min_value=0, max_value=10)) |
|
280 |
- length = draw( |
|
281 |
- strategies.integers( |
|
282 |
- min_value=max(1, lower + upper + number + space + dash + symbol), |
|
283 |
- max_value=70, |
|
284 |
- ) |
|
285 |
- ) |
|
286 |
- hypothesis.assume(lower + upper + number + dash + symbol > 0) |
|
287 |
- hypothesis.assume(lower + upper + number + space + symbol > 0) |
|
288 |
- hypothesis.assume(repeat >= space) |
|
289 |
- return { |
|
290 |
- 'lower': lower, |
|
291 |
- 'upper': upper, |
|
292 |
- 'number': number, |
|
293 |
- 'space': space, |
|
294 |
- 'dash': dash, |
|
295 |
- 'symbol': symbol, |
|
296 |
- 'repeat': repeat, |
|
297 |
- 'length': length, |
|
298 |
- } |
|
299 |
- |
|
300 |
- |
|
301 | 271 |
class TestHypotheses: |
302 | 272 |
@tests.hypothesis_settings_coverage_compatible |
303 | 273 |
@hypothesis.given( |
304 | 274 |
phrase=strategies.one_of( |
305 | 275 |
strategies.binary(min_size=1), strategies.text(min_size=1) |
306 | 276 |
), |
307 |
- config=vault_config(), |
|
277 |
+ config=tests.vault_full_service_config(), |
|
308 | 278 |
service=strategies.text(min_size=1), |
309 | 279 |
) |
310 | 280 |
# regression test |
311 | 281 |