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

Code before:
    def test_negative_binomial(self):
        # Ensure that the negative binomial results take floating point
        # arguments without truncation.
        random_state = self._create_state()[0]
        random_state.negative_binomial(0.5, 0.5)

    def test_get_state_warning(self):
        rs = random.RandomState(PCG64())
        with pytest.warns(RuntimeWarning):
            state = rs.get_state()
        assert isinstance(state, dict)
        assert state['bit_generator'] == 'PCG64'

    def test_invalid_legacy_state_setting(self):
        random_state, state = self._create_state()
        state = random_state.get_state()
        new_state = ('Unknown', ) + state[1:]
        assert_raises(ValueError, random_state.set_state, new_state)
        assert_raises(TypeError, random_state.set_state,
                      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

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

Code after:
    def test_negative_binomial(self):
        # Ensure that the negative binomial results take floating point
        # arguments without truncation.
        random_state, _ = self._create_state()
        random_state.negative_binomial(0.5, 0.5)

    def test_get_state_warning(self):
        rs = random.RandomState(PCG64())
        with pytest.warns(RuntimeWarning):
            state = rs.get_state()
        assert isinstance(state, dict)
        assert state['bit_generator'] == 'PCG64'

    def test_invalid_legacy_state_setting(self):
        random_state, state = self._create_state()
        state = random_state.get_state()
        new_state = ('Unknown', ) + state[1:]
        assert_raises(ValueError, random_state.set_state, new_state)
        assert_raises(TypeError, random_state.set_state,
                      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