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

Function test_tokenize_random_functions

dask/tests/test_tokenize.py:1286–1305  ·  view source on GitHub ↗

random.random() and other methods of the global random state do not compare as equal to themselves after a pickle roundtrip

(module)

Source from the content-addressed store, hash-verified

1284 ["random", pytest.param("np.random", marks=pytest.mark.skipif("not np"))],
1285)
1286def test_tokenize_random_functions(module):
1287 """random.random() and other methods of the global random state do not compare as
1288 equal to themselves after a pickle roundtrip"""
1289 module = eval(module)
1290 module.seed(2)
1291
1292 a = module.random
1293 b = pickle.loads(pickle.dumps(a))
1294 assert check_tokenize(a) == check_tokenize(b)
1295
1296 # Drawing elements or reseeding changes the global state
1297 a()
1298 c = pickle.loads(pickle.dumps(a))
1299 assert check_tokenize(a) == check_tokenize(c)
1300 assert check_tokenize(a) != check_tokenize(b)
1301
1302 module.seed(123)
1303 d = pickle.loads(pickle.dumps(a))
1304 assert check_tokenize(a) == check_tokenize(d)
1305 assert check_tokenize(a) != check_tokenize(c)
1306
1307
1308def test_tokenize_random_functions_with_state():

Callers

nothing calls this directly

Calls 2

check_tokenizeFunction · 0.85
seedMethod · 0.45

Tested by

no test coverage detected