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

Function test_tokenize_random_functions

dask/tests/test_tokenize.py:1285–1304  ·  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

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