MCPcopy Create free account
hub / github.com/dask/dask / test_tokenize_object

Function test_tokenize_object

dask/tests/test_tokenize.py:353–381  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

351
352
353def 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
384def nested_tokenize_ensure_deterministic():

Callers

nothing calls this directly

Calls 2

tokenizeFunction · 0.90
setMethod · 0.80

Tested by

no test coverage detected