Skip to content

Commit 485fd72

Browse files
committed
Fix numpy seed wrapper tests
1 parent bf397d4 commit 485fd72

1 file changed

Lines changed: 31 additions & 27 deletions

File tree

tests/test_conftest.py

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,46 @@
55

66

77
class TestSafeNumpySeed:
8-
"""Verify numpy.random.seed handles oversized seeds from pytest-randomly."""
8+
"""Verify numpy.random.seed handles oversized seeds from pytest-randomly."""
99

1010
def test_seed_exceeding_uint32_max(self):
11-
"""Seeds above 2**32 - 1 should not raise ValueError."""
12-
np.random.seed(2**32 + 12345)
11+
"""Seeds above 2**32 - 1 should not raise ValueError."""
12+
np.random.seed(2**32 + 12345)
1313

1414
def test_seed_at_uint32_boundary(self):
15-
"""Seed exactly at 2**32 should wrap to 0."""
16-
np.random.seed(2**32)
15+
"""Seed exactly at 2**32 should wrap to 0."""
16+
np.random.seed(2**32)
1717

1818
def test_seed_zero(self):
19-
"""Seed 0 should work as normal."""
20-
np.random.seed(0)
19+
"""Seed 0 should work as normal."""
20+
np.random.seed(0)
2121

2222
def test_seed_max_valid(self):
23-
"""Seed 2**32 - 1 should work as normal."""
24-
np.random.seed(2**32 - 1)
23+
"""Seed 2**32 - 1 should work as normal."""
24+
np.random.seed(2**32 - 1)
2525

2626
def test_seed_none(self):
27-
"""Seed None should work as normal (random seed)."""
28-
np.random.seed(None)
27+
"""Seed None should work as normal (random seed)."""
28+
np.random.seed(None)
29+
30+
def test_negative_seed_still_raises(self):
31+
"""Negative seeds should keep NumPy's original validation behavior."""
32+
with pytest.raises(ValueError):
33+
np.random.seed(-1)
2934

3035
def test_determinism_preserved(self):
31-
"""Patched seed should still produce deterministic results."""
32-
np.random.seed(42)
33-
a = np.random.rand(5)
34-
np.random.seed(42)
35-
b = np.random.rand(5)
36-
np.testing.assert_array_equal(a, b)
37-
38-
def test_large_seed_determinism(self):
39-
"""Oversized seeds should produce deterministic results."""
40-
large_seed = 2**33 + 99
41-
np.random.seed(large_seed)
42-
a = np.random.rand(5)
43-
np.random.seed(large_seed)
44-
b = np.random.rand(5)
45-
np.testing.assert_array_equal(a, b)
46-
36+
"""Patched seed should still produce deterministic results."""
37+
np.random.seed(42)
38+
a = np.random.rand(5)
39+
np.random.seed(42)
40+
b = np.random.rand(5)
41+
np.testing.assert_array_equal(a, b)
42+
43+
def test_large_seed_matches_wrapped_seed(self):
44+
"""Oversized seeds should behave like their uint32-wrapped value."""
45+
large_seed = 2**33 + 99
46+
np.random.seed(large_seed)
47+
a = np.random.rand(5)
48+
np.random.seed(99)
49+
b = np.random.rand(5)
50+
np.testing.assert_array_equal(a, b)

0 commit comments

Comments
 (0)