@@ -142,9 +142,7 @@ def test_count(self):
142142 # For a variety of combinations,
143143 # verify that str.count() matches an equivalent function
144144 # replacing all occurrences and then differencing the string lengths
145- charset = ['' , 'a' , 'b' ]
146- digits = 7
147- teststrings = self ._get_teststrings (charset , digits )
145+ teststrings = self ._get_teststrings (['' , 'a' , 'b' ], 7 )
148146 for i in teststrings :
149147 n = len (i )
150148 for j in teststrings :
@@ -201,9 +199,7 @@ def test_find(self):
201199 # For a variety of combinations,
202200 # verify that str.find() matches __contains__
203201 # and that the found substring is really at that location
204- charset = ['' , 'a' , 'b' , 'c' ]
205- digits = 5
206- teststrings = self ._get_teststrings (charset , digits )
202+ teststrings = self ._get_teststrings (['' , 'a' , 'b' , 'c' ], 5 )
207203 for i in teststrings :
208204 for j in teststrings :
209205 loc = i .find (j )
@@ -240,9 +236,7 @@ def test_rfind(self):
240236 # For a variety of combinations,
241237 # verify that str.rfind() matches __contains__
242238 # and that the found substring is really at that location
243- charset = ['' , 'a' , 'b' , 'c' ]
244- digits = 5
245- teststrings = self ._get_teststrings (charset , digits )
239+ teststrings = self ._get_teststrings (['' , 'a' , 'b' , 'c' ], 5 )
246240 for i in teststrings :
247241 for j in teststrings :
248242 loc = i .rfind (j )
@@ -286,21 +280,15 @@ def test_index(self):
286280 # For a variety of combinations,
287281 # verify that str.index() matches __contains__
288282 # and that the found substring is really at that location
289- charset = ['' , 'a' , 'b' , 'c' ]
290- digits = 5
291- teststrings = self ._get_teststrings (charset , digits )
283+ teststrings = self ._get_teststrings (['' , 'a' , 'b' , 'c' ], 5 )
292284 for i in teststrings :
293285 for j in teststrings :
294286 if j in i :
295287 loc = i .index (j )
288+ self .assertGreaterEqual (loc , 0 )
289+ self .assertEqual (i [loc :loc + len (j )], j )
296290 else :
297291 self .assertRaises (ValueError , i .index , j )
298- loc = - 1
299- r1 = (loc != - 1 )
300- r2 = j in i
301- self .assertEqual (r1 , r2 )
302- if loc != - 1 :
303- self .assertEqual (i [loc :loc + len (j )], j )
304292
305293 def test_rindex (self ):
306294 self .checkequal (12 , 'abcdefghiabc' , 'rindex' , '' )
@@ -331,21 +319,15 @@ def test_rindex(self):
331319 # For a variety of combinations,
332320 # verify that str.rindex() matches __contains__
333321 # and that the found substring is really at that location
334- charset = ['' , 'a' , 'b' , 'c' ]
335- digits = 5
336- teststrings = self ._get_teststrings (charset , digits )
322+ teststrings = self ._get_teststrings (['' , 'a' , 'b' , 'c' ], 5 )
337323 for i in teststrings :
338324 for j in teststrings :
339325 if j in i :
340326 loc = i .rindex (j )
327+ self .assertGreaterEqual (loc , 0 )
328+ self .assertEqual (i [loc :loc + len (j )], j )
341329 else :
342330 self .assertRaises (ValueError , i .rindex , j )
343- loc = - 1
344- r1 = (loc != - 1 )
345- r2 = j in i
346- self .assertEqual (r1 , r2 )
347- if loc != - 1 :
348- self .assertEqual (i [loc :loc + len (j )], j )
349331
350332 def test_find_periodic_pattern (self ):
351333 """Cover the special path for periodic patterns."""
0 commit comments