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

Code before:
                           ['789 ', 'xyz ']]).view(np.char.chararray)
        B = np.array([['abc', '123'],
                           ['789', 'xyz']]).view(np.char.chararray)
        assert_(np.all(A == B))
        assert_(np.all(A >= B))
        assert_(np.all(A <= B))
        assert_(not np.any(A > B))
        assert_(not np.any(A < B))
        assert_(not np.any(A != B))


class TestChar:
    def test_it(self):
        A = np.array('abc1', dtype='c').view(np.char.chararray)
        assert_equal(A.shape, (4,))
        assert_equal(A.upper()[:2].tobytes(), b'AB')


class TestComparisons:
    def _create_array_a(self):
        return np.array([['abc', 'abcc', '123'],
                            ['789', 'abc', 'xyz']]).view(np.char.chararray)

    def _create_array_b(self):
        return np.array([['efg', 'efg', '123  '],
                            ['051', 'efgg', 'tuv']]).view(np.char.chararray)

    def test_not_equal(self):
        (A, B) = (self._create_array_a(), self._create_array_b())
        assert_array_equal((A != B),
                           [[True, True, False], [True, True, True]])

    def test_equal(self):
        (A, B) = (self._create_array_a(), self._create_array_b())
        assert_array_equal((A == B),
                           [[False, False, True], [False, False, False]])

    def test_greater_equal(self):
        (A, B) = (self._create_array_a(), self._create_array_b())
        assert_array_equal((A >= B),
                           [[False, False, True], [True, False, True]])

    def test_less_equal(self):
        (A, B) = (self._create_array_a(), self._create_array_b())
        assert_array_equal((A <= B),
                           [[True, True, True], [False, True, False]])

    def test_greater(self):
        (A, B) = (self._create_array_a(), self._create_array_b())
        assert_array_equal((A > B),
                           [[False, False, False], [True, False, True]])

Review comment (suggestion):
IMO this should be 

```
def _create_arrays(self):
    return (
        np.array([['abc', 'abcc', '123'], ['789', 'abc', 'xyz']]).view(np.char.chararray),
        np.array([['efg', 'efg', '123  '], ['051', 'efgg', 'tuv']]).view(np.char.chararray)
    )
```

Since in all cases this is what you want anyway, it's a little clearer just with one function call.

Code after:
                      ['789', 'xyz']]).view(np.char.chararray)
        assert_(np.all(A == B))
        assert_(np.all(A >= B))
        assert_(np.all(A <= B))
        assert_(not np.any(A > B))
        assert_(not np.any(A < B))
        assert_(not np.any(A != B))

class TestChar:
    def test_it(self):
        A = np.array('abc1', dtype='c').view(np.char.chararray)
        assert_equal(A.shape, (4,))
        assert_equal(A.upper()[:2].tobytes(), b'AB')

class TestComparisons:
    def A(self):
        return np.array([['abc', 'abcc', '123'],
                         ['789', 'abc', 'xyz']]).view(np.char.chararray)

    def B(self):
        return np.array([['efg', 'efg', '123  '],
                         ['051', 'efgg', 'tuv']]).view(np.char.chararray)

    def test_not_equal(self):
        A, B = self.A(), self.B()
        assert_array_equal((A != B),
                           [[True, True, False], [True, True, True]])

    def test_equal(self):
        A, B = self.A(), self.B()
        assert_array_equal((A == B),
                           [[False, False, True], [False, False, False]])

    def test_greater_equal(self):
        A, B = self.A(), self.B()
        assert_array_equal((A >= B),
                           [[False, False, True], [True, False, True]])

    def test_less_equal(self):
        A, B = self.A(), self.B()
        assert_array_equal((A <= B),
                           [[True, True, True], [False, True, False]])

    def test_greater(self):
        A, B = self.A(), self.B()
        assert_array_equal((A > B),
                           [[False, False, False], [True, False, True]])

    def test_less(self):
        A, B = self.A(), self.B()
        assert_array_equal((A < B),