| 351 | |
| 352 | |
| 353 | def test_tokenize_object(): |
| 354 | with dask.config.set({"tokenize.ensure-deterministic": False}): |
| 355 | # object() tokenization is idempotent... |
| 356 | o = object() |
| 357 | assert tokenize(o) == tokenize(o) |
| 358 | # ...but not deterministic |
| 359 | assert tokenize(object()) != tokenize(object()) |
| 360 | |
| 361 | # Two objects don't tokenize to the same token even if their pickle output is |
| 362 | # identical. Stress id reuse by creating and dereferencing many objects in quick |
| 363 | # succession. |
| 364 | assert len({tokenize(object()) for _ in range(100)}) == 100 |
| 365 | |
| 366 | # You can call normalize_token even if the _ensure_deterministic context |
| 367 | # variable hasn't been set |
| 368 | assert normalize_token(o) == normalize_token(o) |
| 369 | |
| 370 | with dask.config.set({"tokenize.ensure-deterministic": True}): |
| 371 | with pytest.raises(TokenizationError, match="deterministic"): |
| 372 | tokenize(o) |
| 373 | with pytest.raises(TokenizationError, match="deterministic"): |
| 374 | normalize_token(o) |
| 375 | |
| 376 | # Test env override |
| 377 | assert tokenize(o, ensure_deterministic=False) == tokenize( |
| 378 | o, ensure_deterministic=False |
| 379 | ) |
| 380 | with pytest.raises(TokenizationError, match="deterministic"): |
| 381 | tokenize(o, ensure_deterministic=True) |
| 382 | |
| 383 | |
| 384 | def nested_tokenize_ensure_deterministic(): |