from numpy.testing import *
from numpy.core import *
import numpy as np

class TestBasic(TestCase):
    def test_construction(self):
        A = np.array([['abc', '123'],
                      ['789', 'xyz']])
        A1 = A.view(np.chararray)
        A2 = np.chararray.__new__(np.chararray, A.shape, itemsize=A.itemsize,
                                  buffer=A)
        assert all(A1 == A2)


class TestWhitespace(TestCase):
    def setUp(self):
        self.A = np.array([['abc ', '123  '],
                           ['789 ', 'xyz ']]).view(np.chararray)
        self.B = np.array([['abc', '123'],
                           ['789', 'xyz']]).view(np.chararray)

    def test1(self):
        assert all(self.A == self.B)


class TestOperations(TestCase):
    def setUp(self):
        self.A = np.array([['abc', '123'],
                           ['789', 'xyz']]).view(np.chararray)
        self.B = np.array([['efg', '456'],
                           ['051', 'tuv']]).view(np.chararray)

    def test_add(self):
        AB = np.array([['abcefg', '123456'],
                       ['789051', 'xyztuv']]).view(np.chararray)
        assert all(AB == (self.A + self.B))

    def test_radd(self):
        QA = np.array([['qabc', 'q123'],
                       ['q789', 'qxyz']]).view(np.chararray)
        assert all(QA == ('q' + self.A))

    def test_mul(self):
        A = self.A
        for r in (2,3,5,7,197):
            Ar = np.array([[A[0,0]*r, A[0,1]*r],
                           [A[1,0]*r, A[1,1]*r]]).view(np.chararray)

            assert all(Ar == (self.A * r))
        
        for ob in [object(), 'qrs']:
            try:
                self.A * ob
            except ValueError:
                pass
            else:
                self.fail("chararray can only be multiplied by integers")

    def test_rmul(self):
        A = self.A
        for r in (2,3,5,7,197):
            Ar = np.array([[A[0,0]*r, A[0,1]*r],
                           [A[1,0]*r, A[1,1]*r]]).view(np.chararray)

            assert all(Ar == (r * self.A))
        
        for ob in [object(), 'qrs']:
            try:
                ob * self.A
            except ValueError:
                pass
            else:
                self.fail("chararray can only be multiplied by integers")

    def test_mod(self):
        pass

    def test_rmod(self):
        assert ("%s" % self.A) == str(self.A)
        assert ("%r" % self.A) == repr(self.A)
        
        for ob in [42, object()]:
            try:
                ob % self.A
            except TypeError:
                pass
            else:
                self.fail("chararray __rmod__ should fail with " \
                          "non-string objects")


if __name__ == "__main__":
    run_module_suite()

@@ -1370,32 +1370,33 @@
      A = self.A%0A
+#
         for r in
@@ -1403,32 +1403,33 @@
  (2,3,5,7,197):%0A
+#
             Ar =
@@ -1453,32 +1453,33 @@
 %5D*r, A%5B0,1%5D*r%5D,%0A
+#
                 
@@ -1523,33 +1523,35 @@
 w(np.chararray)%0A
-%0A
+#%0A#
             asse
@@ -1656,21 +1656,16 @@
         
-self.
 A * ob%0A 
@@ -1844,32 +1844,33 @@
      A = self.A%0A
+#
         for r in
@@ -1885,16 +1885,17 @@
 7,197):%0A
+#
         
@@ -1935,16 +1935,17 @@
 ,1%5D*r%5D,%0A
+#
         
@@ -2001,25 +2001,27 @@
 .chararray)%0A
-%0A
+#%0A#
             
@@ -2106,32 +2106,32 @@
            try:%0A
+
                 
@@ -2135,21 +2135,16 @@
    ob * 
-self.
 A%0A      

Comment out failing portions of __mul__ and __rmul__ until they are fixed in chararray.