Repository: numpy/numpy
File: numpy/random/tests/test_randomstate.py (Python)

Code before:
                      np.array(new_state, dtype=object))
        state = random_state.get_state(legacy=False)
        del state['bit_generator']
        assert_raises(ValueError, random_state.set_state, state)

    def test_pickle(self):
        random_state = self._create_state()[0]
        random_state.seed(0)
        random_state.random_sample(100)
        random_state.standard_normal()
        pickled = random_state.get_state(legacy=False)
        assert_equal(pickled['has_gauss'], 1)
        rs_unpick = pickle.loads(pickle.dumps(random_state))
        unpickled = rs_unpick.get_state(legacy=False)
        assert_mt19937_state_equal(pickled, unpickled)

    def test_state_setting(self):
        random_state, state = self._create_state()
        attr_state = random_state.__getstate__()
        random_state.standard_normal()
        random_state.__setstate__(attr_state)
        state = random_state.get_state(legacy=False)
        assert_mt19937_state_equal(attr_state, state)

    def test_repr(self):
        random_state = self._create_state()[0]
        assert repr(random_state).startswith('RandomState(MT19937)')


class TestRandint:

    rfunc = random.randint

    # valid integer/boolean types
    itype = [np.bool, np.int8, np.uint8, np.int16, np.uint16,
             np.int32, np.uint32, np.int64, np.uint64]

    def test_unsupported_type(self):
        assert_raises(TypeError, self.rfunc, 1, dtype=float)

    def test_bounds_checking(self):
        for dt in self.itype:
            lbnd = 0 if dt is np.bool else np.iinfo(dt).min
            ubnd = 2 if dt is np.bool else np.iinfo(dt).max + 1
            assert_raises(ValueError, self.rfunc, lbnd - 1, ubnd, dtype=dt)
            assert_raises(ValueError, self.rfunc, lbnd, ubnd + 1, dtype=dt)
            assert_raises(ValueError, self.rfunc, ubnd, lbnd, dtype=dt)
            assert_raises(ValueError, self.rfunc, 1, 0, dtype=dt)

    def test_rng_zero_and_extremes(self):
        for dt in self.itype:

Review comment (suggestion):
```suggestion
        random_state, _ = self._create_state()
```

Code after:
                      np.array(new_state, dtype=object))
        state = random_state.get_state(legacy=False)
        del state['bit_generator']
        assert_raises(ValueError, random_state.set_state, state)

    def test_pickle(self):
        random_state, _ = self._create_state()
        random_state.seed(0)
        random_state.random_sample(100)
        random_state.standard_normal()
        pickled = random_state.get_state(legacy=False)
        assert_equal(pickled['has_gauss'], 1)
        rs_unpick = pickle.loads(pickle.dumps(random_state))
        unpickled = rs_unpick.get_state(legacy=False)
        assert_mt19937_state_equal(pickled, unpickled)

    def test_state_setting(self):
        random_state, state = self._create_state()
        attr_state = random_state.__getstate__()
        random_state.standard_normal()
        random_state.__setstate__(attr_state)
        state = random_state.get_state(legacy=False)
        assert_mt19937_state_equal(attr_state, state)

    def test_repr(self):
        random_state, _ = self._create_state()
        assert repr(random_state).startswith('RandomState(MT19937)')


class TestRandint:

    rfunc = random.randint

    # valid integer/boolean types
    itype = [np.bool, np.int8, np.uint8, np.int16, np.uint16,
             np.int32, np.uint32, np.int64, np.uint64]

    def test_unsupported_type(self):
        assert_raises(TypeError, self.rfunc, 1, dtype=float)

    def test_bounds_checking(self):
        for dt in self.itype:
            lbnd = 0 if dt is np.bool else np.iinfo(dt).min
            ubnd = 2 if dt is np.bool else np.iinfo(dt).max + 1
            assert_raises(ValueError, self.rfunc, lbnd - 1, ubnd, dtype=dt)
            assert_raises(ValueError, self.rfunc, lbnd, ubnd + 1, dtype=dt)
            assert_raises(ValueError, self.rfunc, ubnd, lbnd, dtype=dt)
            assert_raises(ValueError, self.rfunc, 1, 0, dtype=dt)

    def test_rng_zero_and_extremes(self):
        for dt in self.itype: