| 279 | |
| 280 | @pytest.mark.skipif("not np") |
| 281 | def test_normalize_numpy_ufunc_unserializable(): |
| 282 | # Make a ufunc that isn't in the numpy namespace and can't be serialized |
| 283 | inc = np.frompyfunc(lambda x: x + 1, 1, 1) |
| 284 | with dask.config.set({"tokenize.ensure-deterministic": False}): |
| 285 | # Not idempotent |
| 286 | assert tokenize(inc) != tokenize(inc) |
| 287 | # You can call normalize_token directly |
| 288 | assert normalize_token(inc) != normalize_token(inc) |
| 289 | |
| 290 | with dask.config.set({"tokenize.ensure-deterministic": True}): |
| 291 | with pytest.raises( |
| 292 | TokenizationError, match=r"Cannot tokenize.*dask\.array\.ufunc.*instead" |
| 293 | ): |
| 294 | tokenize(inc) |
| 295 | |
| 296 | # Test env override |
| 297 | assert tokenize(inc, ensure_deterministic=False) != tokenize( |
| 298 | inc, ensure_deterministic=False |
| 299 | ) |
| 300 | with pytest.raises(TokenizationError, match="Cannot tokenize"): |
| 301 | tokenize(inc, ensure_deterministic=True) |
| 302 | |
| 303 | |
| 304 | def test_normalize_object_unserializable(): |