| 1 |
# This file is part of Hypothesis, which may be found at |
| 2 |
# https://github.com/HypothesisWorks/hypothesis/ |
| 3 |
# |
| 4 |
# Copyright the Hypothesis Authors. |
| 5 |
# Individual contributors are listed in AUTHORS.rst and the git log. |
| 6 |
# |
| 7 |
# This Source Code Form is subject to the terms of the Mozilla Public License, |
| 8 |
# v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 9 |
# obtain one at https://mozilla.org/MPL/2.0/. |
| 10 |
|
| 11 |
import numpy as np |
| 12 |
|
| 13 |
from hypothesis import given |
| 14 |
from hypothesis.strategies import none |
| 15 |
|
| 16 |
|
| 17 |
def test_numpy_prng_is_seeded(): |
| 18 |
first = [] |
| 19 |
prng_state = np.random.get_state() |
| 20 |
|
| 21 |
@given(none()) |
| 22 |
def inner(_): |
| 23 |
val = np.random.bytes(10) |
| 24 |
if not first: |
| 25 |
first.append(val) |
| 26 |
assert val == first[0], "Numpy random module should be reproducible" |
| 27 |
|
| 28 |
inner() |
| 29 |
|
| 30 |
np.testing.assert_array_equal( |
| 31 |
np.random.get_state()[1], prng_state[1], "State was not restored." |
| 32 |
) |