From 9b015315f754e81e9392f3a1738ca5e62a377915 Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Tue, 17 Sep 2024 10:31:43 +0100 Subject: [PATCH] REF: Regenerate test date with new seeds --- randomgen/_seed_sequence.pyi | 4 ++-- randomgen/common.pxd | 4 ++-- randomgen/efiix64.pyi | 2 +- randomgen/generator.pyi | 2 +- randomgen/mt19937.pyi | 2 +- randomgen/mt64.pyi | 2 +- randomgen/tests/test_direct.py | 11 ++--------- randomgen/tests/test_smoke.py | 18 +++--------------- requirements-dev.txt | 5 ++++- setup.cfg | 4 ++-- 10 files changed, 19 insertions(+), 35 deletions(-) diff --git a/randomgen/_seed_sequence.pyi b/randomgen/_seed_sequence.pyi index 7445b277a..73530bdc7 100644 --- a/randomgen/_seed_sequence.pyi +++ b/randomgen/_seed_sequence.pyi @@ -1,7 +1,7 @@ from abc import ABCMeta, abstractmethod -from typing import Any, Dict, List, Literal, Optional, Sequence, Type, Union +from typing import Any, Dict, List, Optional, Sequence, Type, Union -from numpy import uint32, uint64, unsignedinteger +from numpy import unsignedinteger DEFAULT_POOL_SIZE: int diff --git a/randomgen/common.pxd b/randomgen/common.pxd index 4ca887882..bf5b2e930 100644 --- a/randomgen/common.pxd +++ b/randomgen/common.pxd @@ -16,10 +16,10 @@ from libc.stdint cimport ( ) import numpy as np -from numpy.random cimport bitgen_t -from numpy.random.bit_generator cimport BitGenerator as _BitGenerator cimport numpy as np +from numpy.random cimport bitgen_t +from numpy.random.bit_generator cimport BitGenerator as _BitGenerator cdef bint RANDOMGEN_BIG_ENDIAN diff --git a/randomgen/efiix64.pyi b/randomgen/efiix64.pyi index f12663808..fb728cb2b 100644 --- a/randomgen/efiix64.pyi +++ b/randomgen/efiix64.pyi @@ -3,7 +3,7 @@ from typing import Dict, Optional, Union import numpy as np from randomgen.common import BitGenerator -from randomgen.typing import IntegerSequenceSeed, SeedMode +from randomgen.typing import IntegerSequenceSeed class EFIIX64(BitGenerator): def __init__(self, seed: Optional[IntegerSequenceSeed] = ...) -> None: ... diff --git a/randomgen/generator.pyi b/randomgen/generator.pyi index 1db7862c0..6cd8352fc 100644 --- a/randomgen/generator.pyi +++ b/randomgen/generator.pyi @@ -1,5 +1,5 @@ from threading import Lock -from typing import Any, Dict, Literal, Optional, Sequence, Tuple, Union, overload +from typing import Any, Dict, Literal, Optional, Union, overload from numpy import ndarray diff --git a/randomgen/mt19937.pyi b/randomgen/mt19937.pyi index 274e3507c..337f30e36 100644 --- a/randomgen/mt19937.pyi +++ b/randomgen/mt19937.pyi @@ -3,7 +3,7 @@ from typing import Dict, Literal, Optional, Tuple, Union import numpy as np from randomgen.common import BitGenerator -from randomgen.typing import IntegerSequenceSeed, SeedMode +from randomgen.typing import IntegerSequenceSeed class MT19937(BitGenerator): def __init__( diff --git a/randomgen/mt64.pyi b/randomgen/mt64.pyi index b3eeac1f5..4a2fb9650 100644 --- a/randomgen/mt64.pyi +++ b/randomgen/mt64.pyi @@ -1,4 +1,4 @@ -from typing import Dict, Optional, Tuple, Union +from typing import Dict, Optional, Union import numpy as np diff --git a/randomgen/tests/test_direct.py b/randomgen/tests/test_direct.py index cf37ad82b..56d79175f 100644 --- a/randomgen/tests/test_direct.py +++ b/randomgen/tests/test_direct.py @@ -38,7 +38,6 @@ ) from randomgen.common import interface from randomgen.seed_sequence import ISeedSequence -from randomgen.tests.data.compute_hashes import kwargs try: from numpy.random import SeedSequence @@ -1300,15 +1299,11 @@ def setup_class(cls): ] def test_seed_sequence(self): - bg = self.bit_generator_base( - number=self.number, width=self.width - ) + bg = self.bit_generator_base(number=self.number, width=self.width) assert isinstance(bg, self.bit_generator_base) assert isinstance(bg.seed_seq, SeedSequence) - bg = self.bit_generator_base( - 0, number=self.number, width=self.width - ) + bg = self.bit_generator_base(0, number=self.number, width=self.width) assert bg.seed_seq.entropy == 0 ss = SeedSequence(0) @@ -1573,9 +1568,7 @@ def setup_class(cls): cls.state_name = "key" def setup_bitgenerator(self, seed, **kwargs): - stream = 3735928559 * 2**64 + 3735928559 * 2**96 seed = [0] if None in seed else seed - key = seed[0] + stream + 2**128 * stream bg = self.bit_generator(*seed, **kwargs) return bg diff --git a/randomgen/tests/test_smoke.py b/randomgen/tests/test_smoke.py index 998557afd..ec764af84 100644 --- a/randomgen/tests/test_smoke.py +++ b/randomgen/tests/test_smoke.py @@ -151,7 +151,7 @@ def _extra_setup(cls): cls.seed_error = TypeError def init_generator(self, seed=None, mode="sequence"): - kwargs = {} if mode == "sequence" else {"mode":mode} + kwargs = {} if mode == "sequence" else {"mode": mode} if seed is not None: return np.random.Generator(self.bit_generator(*seed, **kwargs)) else: @@ -603,11 +603,6 @@ def test_array_scalar_seed_diff(self): assert_(not comp_state(state1, state2)) def test_seed_array_error(self): - if self.seed_vector_bits == 32: - out_of_bounds = 2**32 - else: - out_of_bounds = 2**64 - seed = -1 with pytest.raises(ValueError): self.rg.bit_generator.seed(seed) @@ -795,7 +790,7 @@ def test_output_fill_error(self): rg.standard_gamma(1.0, out=existing[::3]) def test_integers_broadcast(self, dtype): - if dtype == bool: + if dtype is bool: upper = 2 lower = 0 else: @@ -844,7 +839,7 @@ def test_integers_numpy(self, dtype): assert out.shape == (1,) def test_integers_broadcast_errors(self, dtype): - if dtype == bool: + if dtype is bool: upper = 2 lower = 0 else: @@ -967,16 +962,10 @@ def setup_class(cls): def test_seed_array_error(self): # GH #82 for error type changes - if self.seed_vector_bits == 32: - out_of_bounds = 2**32 - else: - out_of_bounds = 2**64 - seed = -1 with pytest.raises(ValueError): self.rg.bit_generator.seed(seed) - error_type = ValueError if self.seed_vector_bits else TypeError seed = np.array([-1], dtype=np.int32) with pytest.raises(ValueError): self.rg.bit_generator.seed(seed) @@ -985,7 +974,6 @@ def test_seed_array_error(self): with pytest.raises(ValueError): self.rg.bit_generator.seed(seed) - def test_array_scalar_seed_diff(self): pass diff --git a/requirements-dev.txt b/requirements-dev.txt index 3d510802b..78d601e35 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,4 +5,7 @@ pytest-cov pytest-xdist scipy>=1.13.1 setuptools_scm[toml]>=8.0.0,<9.0.0 -packaging>=21.0 \ No newline at end of file +packaging>=21.0 +ruff +flake8 +flake8-pyi diff --git a/setup.cfg b/setup.cfg index a1664677c..baebf4afc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,8 +4,8 @@ license_files = LICENSE.md [flake8] -max-line-length = 99 -ignore = E203,W503,BLK100 +max-line-length = 88 +extend-ignore = E203,E701 [isort] sections=FUTURE,COMPAT,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER