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

Code before:
    def test1(self):
        A = np.array([['abc ', '123  '],
                           ['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 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]])

Review comment (suggestion):
```suggestion
    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)
```

Let's make these formatted a little more nicely

Code after:
    def test1(self):
        A = np.array([['abc ', '123  '],
                      ['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 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]])