Repository: numpy/numpy
File: numpy/_core/tests/test_numeric.py (Python)

Code before:

    def test_no_overwrite(self):
        d = np.ones(100)
        k = np.ones(3)
        np.convolve(d, k)
        assert_array_equal(d, np.ones(100))
        assert_array_equal(k, np.ones(3))

    def test_mode(self):
        d = np.ones(100)
        k = np.ones(3)
        default_mode = np.convolve(d, k, mode='full')
        with assert_raises(ValueError):
            np.convolve(d, k, mode='f')
        # integer mode
        with assert_raises(ValueError):
            np.convolve(d, k, mode=-1)
        assert_array_equal(np.convolve(d, k, mode=2), default_mode)
        # illegal arguments
        with assert_raises(TypeError):
            np.convolve(d, k, mode=None)

    def test_convolve_empty_input_error_message(self):
        """
        Test that convolve raises the correct error message when inputs are empty.
        Regression test for gh-issue-number (variable swapping bug).
        """
        with pytest.raises(ValueError, match="a cannot be empty"):
            np.convolve(np.array([]), np.array([1, 2]))

        with pytest.raises(ValueError, match="v cannot be empty"):
            np.convolve(np.array([1, 2]), np.array([]))

class TestArgwhere:

    @pytest.mark.parametrize('nd', [0, 1, 2])
    def test_nd(self, nd):
        # get an nd array with multiple elements in every dimension
        x = np.empty((2,) * nd, bool)

        # none
        x[...] = False
        assert_equal(np.argwhere(x).shape, (0, nd))

        # only one
        x[...] = False
        x.flat[0] = True
        assert_equal(np.argwhere(x).shape, (1, nd))

        # all but one
        x[...] = True

Review comment (bug):
```suggestion
        Regression test for gh-30272 (variable swapping bug).
```

Code after:

    def test_no_overwrite(self):
        d = np.ones(100)
        k = np.ones(3)
        np.convolve(d, k)
        assert_array_equal(d, np.ones(100))
        assert_array_equal(k, np.ones(3))

    def test_mode(self):
        d = np.ones(100)
        k = np.ones(3)
        default_mode = np.convolve(d, k, mode='full')
        with assert_raises(ValueError):
            np.convolve(d, k, mode='f')
        # integer mode
        with assert_raises(ValueError):
            np.convolve(d, k, mode=-1)
        assert_array_equal(np.convolve(d, k, mode=2), default_mode)
        # illegal arguments
        with assert_raises(TypeError):
            np.convolve(d, k, mode=None)

    def test_convolve_empty_input_error_message(self):
        """
        Test that convolve raises the correct error message when inputs are empty.
        Regression test for gh-30272 (variable swapping bug).
        """
        with pytest.raises(ValueError, match="a cannot be empty"):
            np.convolve(np.array([]), np.array([1, 2]))

        with pytest.raises(ValueError, match="v cannot be empty"):
            np.convolve(np.array([1, 2]), np.array([]))

class TestArgwhere:

    @pytest.mark.parametrize('nd', [0, 1, 2])
    def test_nd(self, nd):
        # get an nd array with multiple elements in every dimension
        x = np.empty((2,) * nd, bool)

        # none
        x[...] = False
        assert_equal(np.argwhere(x).shape, (0, nd))

        # only one
        x[...] = False
        x.flat[0] = True
        assert_equal(np.argwhere(x).shape, (1, nd))

        # all but one
        x[...] = True