Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.test_bytes.ByteArrayAsStringTest Class Reference
Inheritance diagram for test.test_bytes.ByteArrayAsStringTest:
Inheritance graph
[legend]
Collaboration diagram for test.test_bytes.ByteArrayAsStringTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def fixtype
def test_contains
def test_expandtabs
def test_upper
def test_lower
def checkequal
def checkraises
def checkcall
def test_count
def test_find
def test_rfind
def test_index
def test_rindex
def test_split
def test_rsplit
def test_replace

Static Public Attributes

 type2test = bytearray

Detailed Description

Definition at line 1106 of file test_bytes.py.


Member Function Documentation

def test.string_tests.BaseTest.checkcall (   self,
  obj,
  methodname,
  args 
) [inherited]

Reimplemented in test.test_userstring.UserStringTest.

Definition at line 83 of file string_tests.py.

00083 
00084     def checkcall(self, obj, methodname, *args):
00085         obj = self.fixtype(obj)
00086         args = self.fixtype(args)
00087         getattr(obj, methodname)(*args)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.string_tests.BaseTest.checkequal (   self,
  result,
  obj,
  methodname,
  args 
) [inherited]

Reimplemented in test.test_userstring.UserStringTest.

Definition at line 50 of file string_tests.py.

00050 
00051     def checkequal(self, result, obj, methodname, *args):
00052         result = self.fixtype(result)
00053         obj = self.fixtype(obj)
00054         args = self.fixtype(args)
00055         realresult = getattr(obj, methodname)(*args)
00056         self.assertEqual(
00057             result,
00058             realresult
00059         )
00060         # if the original is returned make sure that
00061         # this doesn't happen with subclasses
00062         if obj is realresult:
00063             try:
00064                 class subtype(self.__class__.type2test):
00065                     pass
00066             except TypeError:
00067                 pass  # Skip this if we can't subclass
00068             else:
00069                 obj = subtype(obj)
00070                 realresult = getattr(obj, methodname)(*args)
00071                 self.assertIsNot(obj, realresult)

Here is the call graph for this function:

def test.string_tests.BaseTest.checkraises (   self,
  exc,
  obj,
  methodname,
  args 
) [inherited]

Reimplemented in test.test_userstring.UserStringTest.

Definition at line 73 of file string_tests.py.

00073 
00074     def checkraises(self, exc, obj, methodname, *args):
00075         obj = self.fixtype(obj)
00076         args = self.fixtype(args)
00077         self.assertRaises(
00078             exc,
00079             getattr(obj, methodname),
00080             *args
00081         )

Here is the call graph for this function:

def test.test_bytes.FixedStringTest.fixtype (   self,
  obj 
) [inherited]

Reimplemented from test.string_tests.BaseTest.

Definition at line 1089 of file test_bytes.py.

01089 
01090     def fixtype(self, obj):
01091         if isinstance(obj, str):
01092             return obj.encode("utf-8")
01093         return super().fixtype(obj)

Here is the caller graph for this function:

Definition at line 1097 of file test_bytes.py.

01097 
01098     def test_contains(self):
        pass
def test.string_tests.BaseTest.test_count (   self) [inherited]

Reimplemented in test.test_unicode.UnicodeTest.

Definition at line 88 of file string_tests.py.

00088 
00089     def test_count(self):
00090         self.checkequal(3, 'aaa', 'count', 'a')
00091         self.checkequal(0, 'aaa', 'count', 'b')
00092         self.checkequal(3, 'aaa', 'count', 'a')
00093         self.checkequal(0, 'aaa', 'count', 'b')
00094         self.checkequal(3, 'aaa', 'count', 'a')
00095         self.checkequal(0, 'aaa', 'count', 'b')
00096         self.checkequal(0, 'aaa', 'count', 'b')
00097         self.checkequal(2, 'aaa', 'count', 'a', 1)
00098         self.checkequal(0, 'aaa', 'count', 'a', 10)
00099         self.checkequal(1, 'aaa', 'count', 'a', -1)
00100         self.checkequal(3, 'aaa', 'count', 'a', -10)
00101         self.checkequal(1, 'aaa', 'count', 'a', 0, 1)
00102         self.checkequal(3, 'aaa', 'count', 'a', 0, 10)
00103         self.checkequal(2, 'aaa', 'count', 'a', 0, -1)
00104         self.checkequal(0, 'aaa', 'count', 'a', 0, -10)
00105         self.checkequal(3, 'aaa', 'count', '', 1)
00106         self.checkequal(1, 'aaa', 'count', '', 3)
00107         self.checkequal(0, 'aaa', 'count', '', 10)
00108         self.checkequal(2, 'aaa', 'count', '', -1)
00109         self.checkequal(4, 'aaa', 'count', '', -10)
00110 
00111         self.checkequal(1, '', 'count', '')
00112         self.checkequal(0, '', 'count', '', 1, 1)
00113         self.checkequal(0, '', 'count', '', sys.maxsize, 0)
00114 
00115         self.checkequal(0, '', 'count', 'xx')
00116         self.checkequal(0, '', 'count', 'xx', 1, 1)
00117         self.checkequal(0, '', 'count', 'xx', sys.maxsize, 0)
00118 
00119         self.checkraises(TypeError, 'hello', 'count')
00120         self.checkraises(TypeError, 'hello', 'count', 42)
00121 
00122         # For a variety of combinations,
00123         #    verify that str.count() matches an equivalent function
00124         #    replacing all occurrences and then differencing the string lengths
00125         charset = ['', 'a', 'b']
00126         digits = 7
00127         base = len(charset)
00128         teststrings = set()
00129         for i in range(base ** digits):
00130             entry = []
00131             for j in range(digits):
00132                 i, m = divmod(i, base)
00133                 entry.append(charset[m])
00134             teststrings.add(''.join(entry))
00135         teststrings = [self.fixtype(ts) for ts in teststrings]
00136         for i in teststrings:
00137             n = len(i)
00138             for j in teststrings:
00139                 r1 = i.count(j)
00140                 if j:
00141                     r2, rem = divmod(n - len(i.replace(j, self.fixtype(''))),
00142                                      len(j))
00143                 else:
00144                     r2, rem = len(i)+1, 0
00145                 if rem or r1 != r2:
00146                     self.assertEqual(rem, 0, '%s != 0 for %s' % (rem, i))
00147                     self.assertEqual(r1, r2, '%s != %s for %s' % (r1, r2, i))

Here is the call graph for this function:

Reimplemented from test.string_tests.BaseTest.

Definition at line 1099 of file test_bytes.py.

01099 
01100     def test_expandtabs(self):
        pass
def test.string_tests.BaseTest.test_find (   self) [inherited]

Reimplemented in test.test_unicode.UnicodeTest.

Definition at line 148 of file string_tests.py.

00148 
00149     def test_find(self):
00150         self.checkequal(0, 'abcdefghiabc', 'find', 'abc')
00151         self.checkequal(9, 'abcdefghiabc', 'find', 'abc', 1)
00152         self.checkequal(-1, 'abcdefghiabc', 'find', 'def', 4)
00153 
00154         self.checkequal(0, 'abc', 'find', '', 0)
00155         self.checkequal(3, 'abc', 'find', '', 3)
00156         self.checkequal(-1, 'abc', 'find', '', 4)
00157 
00158         # to check the ability to pass None as defaults
00159         self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a')
00160         self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4)
00161         self.checkequal(-1, 'rrarrrrrrrrra', 'find', 'a', 4, 6)
00162         self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4, None)
00163         self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a', None, 6)
00164 
00165         self.checkraises(TypeError, 'hello', 'find')
00166         self.checkraises(TypeError, 'hello', 'find', 42)
00167 
00168         self.checkequal(0, '', 'find', '')
00169         self.checkequal(-1, '', 'find', '', 1, 1)
00170         self.checkequal(-1, '', 'find', '', sys.maxsize, 0)
00171 
00172         self.checkequal(-1, '', 'find', 'xx')
00173         self.checkequal(-1, '', 'find', 'xx', 1, 1)
00174         self.checkequal(-1, '', 'find', 'xx', sys.maxsize, 0)
00175 
00176         # issue 7458
00177         self.checkequal(-1, 'ab', 'find', 'xxx', sys.maxsize + 1, 0)
00178 
00179         # For a variety of combinations,
00180         #    verify that str.find() matches __contains__
00181         #    and that the found substring is really at that location
00182         charset = ['', 'a', 'b', 'c']
00183         digits = 5
00184         base = len(charset)
00185         teststrings = set()
00186         for i in range(base ** digits):
00187             entry = []
00188             for j in range(digits):
00189                 i, m = divmod(i, base)
00190                 entry.append(charset[m])
00191             teststrings.add(''.join(entry))
00192         teststrings = [self.fixtype(ts) for ts in teststrings]
00193         for i in teststrings:
00194             for j in teststrings:
00195                 loc = i.find(j)
00196                 r1 = (loc != -1)
00197                 r2 = j in i
00198                 self.assertEqual(r1, r2)
00199                 if loc != -1:
00200                     self.assertEqual(i[loc:loc+len(j)], j)

Here is the call graph for this function:

def test.string_tests.BaseTest.test_index (   self) [inherited]

Reimplemented in test.test_unicode.UnicodeTest.

Definition at line 247 of file string_tests.py.

00247 
00248     def test_index(self):
00249         self.checkequal(0, 'abcdefghiabc', 'index', '')
00250         self.checkequal(3, 'abcdefghiabc', 'index', 'def')
00251         self.checkequal(0, 'abcdefghiabc', 'index', 'abc')
00252         self.checkequal(9, 'abcdefghiabc', 'index', 'abc', 1)
00253 
00254         self.checkraises(ValueError, 'abcdefghiabc', 'index', 'hib')
00255         self.checkraises(ValueError, 'abcdefghiab', 'index', 'abc', 1)
00256         self.checkraises(ValueError, 'abcdefghi', 'index', 'ghi', 8)
00257         self.checkraises(ValueError, 'abcdefghi', 'index', 'ghi', -1)
00258 
00259         # to check the ability to pass None as defaults
00260         self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a')
00261         self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4)
00262         self.checkraises(ValueError, 'rrarrrrrrrrra', 'index', 'a', 4, 6)
00263         self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4, None)
00264         self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a', None, 6)
00265 
00266         self.checkraises(TypeError, 'hello', 'index')
00267         self.checkraises(TypeError, 'hello', 'index', 42)

Here is the call graph for this function:

def test.test_bytes.FixedStringTest.test_lower (   self) [inherited]

Reimplemented from test.string_tests.BaseTest.

Definition at line 1103 of file test_bytes.py.

01103 
01104     def test_lower(self):
01105         pass

def test.string_tests.BaseTest.test_replace (   self) [inherited]

Reimplemented in test.test_unicode.UnicodeTest.

Definition at line 430 of file string_tests.py.

00430 
00431     def test_replace(self):
00432         EQ = self.checkequal
00433 
00434         # Operations on the empty string
00435         EQ("", "", "replace", "", "")
00436         EQ("A", "", "replace", "", "A")
00437         EQ("", "", "replace", "A", "")
00438         EQ("", "", "replace", "A", "A")
00439         EQ("", "", "replace", "", "", 100)
00440         EQ("", "", "replace", "", "", sys.maxsize)
00441 
00442         # interleave (from=="", 'to' gets inserted everywhere)
00443         EQ("A", "A", "replace", "", "")
00444         EQ("*A*", "A", "replace", "", "*")
00445         EQ("*1A*1", "A", "replace", "", "*1")
00446         EQ("*-#A*-#", "A", "replace", "", "*-#")
00447         EQ("*-A*-A*-", "AA", "replace", "", "*-")
00448         EQ("*-A*-A*-", "AA", "replace", "", "*-", -1)
00449         EQ("*-A*-A*-", "AA", "replace", "", "*-", sys.maxsize)
00450         EQ("*-A*-A*-", "AA", "replace", "", "*-", 4)
00451         EQ("*-A*-A*-", "AA", "replace", "", "*-", 3)
00452         EQ("*-A*-A", "AA", "replace", "", "*-", 2)
00453         EQ("*-AA", "AA", "replace", "", "*-", 1)
00454         EQ("AA", "AA", "replace", "", "*-", 0)
00455 
00456         # single character deletion (from=="A", to=="")
00457         EQ("", "A", "replace", "A", "")
00458         EQ("", "AAA", "replace", "A", "")
00459         EQ("", "AAA", "replace", "A", "", -1)
00460         EQ("", "AAA", "replace", "A", "", sys.maxsize)
00461         EQ("", "AAA", "replace", "A", "", 4)
00462         EQ("", "AAA", "replace", "A", "", 3)
00463         EQ("A", "AAA", "replace", "A", "", 2)
00464         EQ("AA", "AAA", "replace", "A", "", 1)
00465         EQ("AAA", "AAA", "replace", "A", "", 0)
00466         EQ("", "AAAAAAAAAA", "replace", "A", "")
00467         EQ("BCD", "ABACADA", "replace", "A", "")
00468         EQ("BCD", "ABACADA", "replace", "A", "", -1)
00469         EQ("BCD", "ABACADA", "replace", "A", "", sys.maxsize)
00470         EQ("BCD", "ABACADA", "replace", "A", "", 5)
00471         EQ("BCD", "ABACADA", "replace", "A", "", 4)
00472         EQ("BCDA", "ABACADA", "replace", "A", "", 3)
00473         EQ("BCADA", "ABACADA", "replace", "A", "", 2)
00474         EQ("BACADA", "ABACADA", "replace", "A", "", 1)
00475         EQ("ABACADA", "ABACADA", "replace", "A", "", 0)
00476         EQ("BCD", "ABCAD", "replace", "A", "")
00477         EQ("BCD", "ABCADAA", "replace", "A", "")
00478         EQ("BCD", "BCD", "replace", "A", "")
00479         EQ("*************", "*************", "replace", "A", "")
00480         EQ("^A^", "^"+"A"*1000+"^", "replace", "A", "", 999)
00481 
00482         # substring deletion (from=="the", to=="")
00483         EQ("", "the", "replace", "the", "")
00484         EQ("ater", "theater", "replace", "the", "")
00485         EQ("", "thethe", "replace", "the", "")
00486         EQ("", "thethethethe", "replace", "the", "")
00487         EQ("aaaa", "theatheatheathea", "replace", "the", "")
00488         EQ("that", "that", "replace", "the", "")
00489         EQ("thaet", "thaet", "replace", "the", "")
00490         EQ("here and re", "here and there", "replace", "the", "")
00491         EQ("here and re and re", "here and there and there",
00492            "replace", "the", "", sys.maxsize)
00493         EQ("here and re and re", "here and there and there",
00494            "replace", "the", "", -1)
00495         EQ("here and re and re", "here and there and there",
00496            "replace", "the", "", 3)
00497         EQ("here and re and re", "here and there and there",
00498            "replace", "the", "", 2)
00499         EQ("here and re and there", "here and there and there",
00500            "replace", "the", "", 1)
00501         EQ("here and there and there", "here and there and there",
00502            "replace", "the", "", 0)
00503         EQ("here and re and re", "here and there and there", "replace", "the", "")
00504 
00505         EQ("abc", "abc", "replace", "the", "")
00506         EQ("abcdefg", "abcdefg", "replace", "the", "")
00507 
00508         # substring deletion (from=="bob", to=="")
00509         EQ("bob", "bbobob", "replace", "bob", "")
00510         EQ("bobXbob", "bbobobXbbobob", "replace", "bob", "")
00511         EQ("aaaaaaa", "aaaaaaabob", "replace", "bob", "")
00512         EQ("aaaaaaa", "aaaaaaa", "replace", "bob", "")
00513 
00514         # single character replace in place (len(from)==len(to)==1)
00515         EQ("Who goes there?", "Who goes there?", "replace", "o", "o")
00516         EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O")
00517         EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", sys.maxsize)
00518         EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", -1)
00519         EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", 3)
00520         EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", 2)
00521         EQ("WhO goes there?", "Who goes there?", "replace", "o", "O", 1)
00522         EQ("Who goes there?", "Who goes there?", "replace", "o", "O", 0)
00523 
00524         EQ("Who goes there?", "Who goes there?", "replace", "a", "q")
00525         EQ("who goes there?", "Who goes there?", "replace", "W", "w")
00526         EQ("wwho goes there?ww", "WWho goes there?WW", "replace", "W", "w")
00527         EQ("Who goes there!", "Who goes there?", "replace", "?", "!")
00528         EQ("Who goes there!!", "Who goes there??", "replace", "?", "!")
00529 
00530         EQ("Who goes there?", "Who goes there?", "replace", ".", "!")
00531 
00532         # substring replace in place (len(from)==len(to) > 1)
00533         EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**")
00534         EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", sys.maxsize)
00535         EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", -1)
00536         EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", 4)
00537         EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", 3)
00538         EQ("Th** ** a tissue", "This is a tissue", "replace", "is", "**", 2)
00539         EQ("Th** is a tissue", "This is a tissue", "replace", "is", "**", 1)
00540         EQ("This is a tissue", "This is a tissue", "replace", "is", "**", 0)
00541         EQ("cobob", "bobob", "replace", "bob", "cob")
00542         EQ("cobobXcobocob", "bobobXbobobob", "replace", "bob", "cob")
00543         EQ("bobob", "bobob", "replace", "bot", "bot")
00544 
00545         # replace single character (len(from)==1, len(to)>1)
00546         EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK")
00547         EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", -1)
00548         EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", sys.maxsize)
00549         EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", 2)
00550         EQ("ReyKKjavik", "Reykjavik", "replace", "k", "KK", 1)
00551         EQ("Reykjavik", "Reykjavik", "replace", "k", "KK", 0)
00552         EQ("A----B----C----", "A.B.C.", "replace", ".", "----")
00553 
00554         EQ("Reykjavik", "Reykjavik", "replace", "q", "KK")
00555 
00556         # replace substring (len(from)>1, len(to)!=len(from))
00557         EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
00558            "replace", "spam", "ham")
00559         EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
00560            "replace", "spam", "ham", sys.maxsize)
00561         EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
00562            "replace", "spam", "ham", -1)
00563         EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
00564            "replace", "spam", "ham", 4)
00565         EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
00566            "replace", "spam", "ham", 3)
00567         EQ("ham, ham, eggs and spam", "spam, spam, eggs and spam",
00568            "replace", "spam", "ham", 2)
00569         EQ("ham, spam, eggs and spam", "spam, spam, eggs and spam",
00570            "replace", "spam", "ham", 1)
00571         EQ("spam, spam, eggs and spam", "spam, spam, eggs and spam",
00572            "replace", "spam", "ham", 0)
00573 
00574         EQ("bobob", "bobobob", "replace", "bobob", "bob")
00575         EQ("bobobXbobob", "bobobobXbobobob", "replace", "bobob", "bob")
00576         EQ("BOBOBOB", "BOBOBOB", "replace", "bob", "bobby")
00577 
00578         # XXX Commented out. Is there any reason to support buffer objects
        # as arguments for str.replace()?  GvR

Here is the call graph for this function:

def test.string_tests.BaseTest.test_rfind (   self) [inherited]

Reimplemented in test.test_unicode.UnicodeTest.

Definition at line 201 of file string_tests.py.

00201 
00202     def test_rfind(self):
00203         self.checkequal(9,  'abcdefghiabc', 'rfind', 'abc')
00204         self.checkequal(12, 'abcdefghiabc', 'rfind', '')
00205         self.checkequal(0, 'abcdefghiabc', 'rfind', 'abcd')
00206         self.checkequal(-1, 'abcdefghiabc', 'rfind', 'abcz')
00207 
00208         self.checkequal(3, 'abc', 'rfind', '', 0)
00209         self.checkequal(3, 'abc', 'rfind', '', 3)
00210         self.checkequal(-1, 'abc', 'rfind', '', 4)
00211 
00212         # to check the ability to pass None as defaults
00213         self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a')
00214         self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4)
00215         self.checkequal(-1, 'rrarrrrrrrrra', 'rfind', 'a', 4, 6)
00216         self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4, None)
00217         self.checkequal( 2, 'rrarrrrrrrrra', 'rfind', 'a', None, 6)
00218 
00219         self.checkraises(TypeError, 'hello', 'rfind')
00220         self.checkraises(TypeError, 'hello', 'rfind', 42)
00221 
00222         # For a variety of combinations,
00223         #    verify that str.rfind() matches __contains__
00224         #    and that the found substring is really at that location
00225         charset = ['', 'a', 'b', 'c']
00226         digits = 5
00227         base = len(charset)
00228         teststrings = set()
00229         for i in range(base ** digits):
00230             entry = []
00231             for j in range(digits):
00232                 i, m = divmod(i, base)
00233                 entry.append(charset[m])
00234             teststrings.add(''.join(entry))
00235         teststrings = [self.fixtype(ts) for ts in teststrings]
00236         for i in teststrings:
00237             for j in teststrings:
00238                 loc = i.rfind(j)
00239                 r1 = (loc != -1)
00240                 r2 = j in i
00241                 self.assertEqual(r1, r2)
00242                 if loc != -1:
00243                     self.assertEqual(i[loc:loc+len(j)], j)
00244 
00245         # issue 7458
00246         self.checkequal(-1, 'ab', 'rfind', 'xxx', sys.maxsize + 1, 0)

Here is the call graph for this function:

def test.string_tests.BaseTest.test_rindex (   self) [inherited]

Reimplemented in test.test_unicode.UnicodeTest.

Definition at line 268 of file string_tests.py.

00268 
00269     def test_rindex(self):
00270         self.checkequal(12, 'abcdefghiabc', 'rindex', '')
00271         self.checkequal(3,  'abcdefghiabc', 'rindex', 'def')
00272         self.checkequal(9,  'abcdefghiabc', 'rindex', 'abc')
00273         self.checkequal(0,  'abcdefghiabc', 'rindex', 'abc', 0, -1)
00274 
00275         self.checkraises(ValueError, 'abcdefghiabc', 'rindex', 'hib')
00276         self.checkraises(ValueError, 'defghiabc', 'rindex', 'def', 1)
00277         self.checkraises(ValueError, 'defghiabc', 'rindex', 'abc', 0, -1)
00278         self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, 8)
00279         self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, -1)
00280 
00281         # to check the ability to pass None as defaults
00282         self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a')
00283         self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4)
00284         self.checkraises(ValueError, 'rrarrrrrrrrra', 'rindex', 'a', 4, 6)
00285         self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4, None)
00286         self.checkequal( 2, 'rrarrrrrrrrra', 'rindex', 'a', None, 6)
00287 
00288         self.checkraises(TypeError, 'hello', 'rindex')
00289         self.checkraises(TypeError, 'hello', 'rindex', 42)

Here is the call graph for this function:

def test.string_tests.BaseTest.test_rsplit (   self) [inherited]

Definition at line 373 of file string_tests.py.

00373 
00374     def test_rsplit(self):
00375         # by a char
00376         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|')
00377         self.checkequal(['a|b|c', 'd'], 'a|b|c|d', 'rsplit', '|', 1)
00378         self.checkequal(['a|b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 2)
00379         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 3)
00380         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 4)
00381         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|',
00382                         sys.maxsize-100)
00383         self.checkequal(['a|b|c|d'], 'a|b|c|d', 'rsplit', '|', 0)
00384         self.checkequal(['a||b||c', '', 'd'], 'a||b||c||d', 'rsplit', '|', 2)
00385         self.checkequal(['', ' begincase'], '| begincase', 'rsplit', '|')
00386         self.checkequal(['endcase ', ''], 'endcase |', 'rsplit', '|')
00387         self.checkequal(['', 'bothcase', ''], '|bothcase|', 'rsplit', '|')
00388 
00389         self.checkequal(['a\x00\x00b', 'c', 'd'], 'a\x00\x00b\x00c\x00d', 'rsplit', '\x00', 2)
00390 
00391         self.checkequal(['a']*20, ('a|'*20)[:-1], 'rsplit', '|')
00392         self.checkequal(['a|a|a|a|a']+['a']*15,
00393                         ('a|'*20)[:-1], 'rsplit', '|', 15)
00394 
00395         # by string
00396         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//')
00397         self.checkequal(['a//b//c', 'd'], 'a//b//c//d', 'rsplit', '//', 1)
00398         self.checkequal(['a//b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 2)
00399         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 3)
00400         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 4)
00401         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//',
00402                         sys.maxsize-5)
00403         self.checkequal(['a//b//c//d'], 'a//b//c//d', 'rsplit', '//', 0)
00404         self.checkequal(['a////b////c', '', 'd'], 'a////b////c////d', 'rsplit', '//', 2)
00405         self.checkequal(['', ' begincase'], 'test begincase', 'rsplit', 'test')
00406         self.checkequal(['endcase ', ''], 'endcase test', 'rsplit', 'test')
00407         self.checkequal(['', ' bothcase ', ''], 'test bothcase test',
00408                         'rsplit', 'test')
00409         self.checkequal(['ab', 'c'], 'abbbc', 'rsplit', 'bb')
00410         self.checkequal(['', ''], 'aaa', 'rsplit', 'aaa')
00411         self.checkequal(['aaa'], 'aaa', 'rsplit', 'aaa', 0)
00412         self.checkequal(['ab', 'ab'], 'abbaab', 'rsplit', 'ba')
00413         self.checkequal(['aaaa'], 'aaaa', 'rsplit', 'aab')
00414         self.checkequal([''], '', 'rsplit', 'aaa')
00415         self.checkequal(['aa'], 'aa', 'rsplit', 'aaa')
00416         self.checkequal(['bbob', 'A'], 'bbobbbobbA', 'rsplit', 'bbobb')
00417         self.checkequal(['', 'B', 'A'], 'bbobbBbbobbA', 'rsplit', 'bbobb')
00418 
00419         self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'rsplit', 'BLAH')
00420         self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'rsplit', 'BLAH', 19)
00421         self.checkequal(['aBLAHa'] + ['a']*18, ('aBLAH'*20)[:-4],
00422                         'rsplit', 'BLAH', 18)
00423 
00424         # argument type
00425         self.checkraises(TypeError, 'hello', 'rsplit', 42, 42, 42)
00426 
00427         # null case
00428         self.checkraises(ValueError, 'hello', 'rsplit', '')
00429         self.checkraises(ValueError, 'hello', 'rsplit', '', 0)

Here is the call graph for this function:

def test.string_tests.BaseTest.test_split (   self) [inherited]

Reimplemented in test.test_unicode.UnicodeTest.

Definition at line 316 of file string_tests.py.

00316 
00317     def test_split(self):
00318         # by a char
00319         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|')
00320         self.checkequal(['a|b|c|d'], 'a|b|c|d', 'split', '|', 0)
00321         self.checkequal(['a', 'b|c|d'], 'a|b|c|d', 'split', '|', 1)
00322         self.checkequal(['a', 'b', 'c|d'], 'a|b|c|d', 'split', '|', 2)
00323         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', 3)
00324         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', 4)
00325         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|',
00326                         sys.maxsize-2)
00327         self.checkequal(['a|b|c|d'], 'a|b|c|d', 'split', '|', 0)
00328         self.checkequal(['a', '', 'b||c||d'], 'a||b||c||d', 'split', '|', 2)
00329         self.checkequal(['endcase ', ''], 'endcase |', 'split', '|')
00330         self.checkequal(['', ' startcase'], '| startcase', 'split', '|')
00331         self.checkequal(['', 'bothcase', ''], '|bothcase|', 'split', '|')
00332         self.checkequal(['a', '', 'b\x00c\x00d'], 'a\x00\x00b\x00c\x00d', 'split', '\x00', 2)
00333 
00334         self.checkequal(['a']*20, ('a|'*20)[:-1], 'split', '|')
00335         self.checkequal(['a']*15 +['a|a|a|a|a'],
00336                                    ('a|'*20)[:-1], 'split', '|', 15)
00337 
00338         # by string
00339         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//')
00340         self.checkequal(['a', 'b//c//d'], 'a//b//c//d', 'split', '//', 1)
00341         self.checkequal(['a', 'b', 'c//d'], 'a//b//c//d', 'split', '//', 2)
00342         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', 3)
00343         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', 4)
00344         self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//',
00345                         sys.maxsize-10)
00346         self.checkequal(['a//b//c//d'], 'a//b//c//d', 'split', '//', 0)
00347         self.checkequal(['a', '', 'b////c////d'], 'a////b////c////d', 'split', '//', 2)
00348         self.checkequal(['endcase ', ''], 'endcase test', 'split', 'test')
00349         self.checkequal(['', ' begincase'], 'test begincase', 'split', 'test')
00350         self.checkequal(['', ' bothcase ', ''], 'test bothcase test',
00351                         'split', 'test')
00352         self.checkequal(['a', 'bc'], 'abbbc', 'split', 'bb')
00353         self.checkequal(['', ''], 'aaa', 'split', 'aaa')
00354         self.checkequal(['aaa'], 'aaa', 'split', 'aaa', 0)
00355         self.checkequal(['ab', 'ab'], 'abbaab', 'split', 'ba')
00356         self.checkequal(['aaaa'], 'aaaa', 'split', 'aab')
00357         self.checkequal([''], '', 'split', 'aaa')
00358         self.checkequal(['aa'], 'aa', 'split', 'aaa')
00359         self.checkequal(['A', 'bobb'], 'Abbobbbobb', 'split', 'bbobb')
00360         self.checkequal(['A', 'B', ''], 'AbbobbBbbobb', 'split', 'bbobb')
00361 
00362         self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'split', 'BLAH')
00363         self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'split', 'BLAH', 19)
00364         self.checkequal(['a']*18 + ['aBLAHa'], ('aBLAH'*20)[:-4],
00365                         'split', 'BLAH', 18)
00366 
00367         # argument type
00368         self.checkraises(TypeError, 'hello', 'split', 42, 42, 42)
00369 
00370         # null case
00371         self.checkraises(ValueError, 'hello', 'split', '')
00372         self.checkraises(ValueError, 'hello', 'split', '', 0)

Here is the call graph for this function:

def test.test_bytes.FixedStringTest.test_upper (   self) [inherited]

Reimplemented from test.string_tests.BaseTest.

Definition at line 1101 of file test_bytes.py.

01101 
01102     def test_upper(self):
        pass

Member Data Documentation

Reimplemented from test.string_tests.BaseTest.

Definition at line 1107 of file test_bytes.py.


The documentation for this class was generated from the following file: