summaryrefslogtreecommitdiffstats
path: root/Lib/test/string_tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/string_tests.py')
-rw-r--r--Lib/test/string_tests.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index 09622dd..24a4a57 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -172,6 +172,9 @@ class BaseTest(unittest.TestCase):
self.checkequal(-1, '', 'find', 'xx', 1, 1)
self.checkequal(-1, '', 'find', 'xx', sys.maxsize, 0)
+ # issue 7458
+ self.checkequal(-1, 'ab', 'find', 'xxx', sys.maxsize + 1, 0)
+
# For a variety of combinations,
# verify that str.find() matches __contains__
# and that the found substring is really at that location
@@ -191,8 +194,7 @@ class BaseTest(unittest.TestCase):
loc = i.find(j)
r1 = (loc != -1)
r2 = j in i
- if r1 != r2:
- self.assertEqual(r1, r2)
+ self.assertEqual(r1, r2)
if loc != -1:
self.assertEqual(i[loc:loc+len(j)], j)
@@ -216,6 +218,32 @@ class BaseTest(unittest.TestCase):
self.checkraises(TypeError, 'hello', 'rfind')
self.checkraises(TypeError, 'hello', 'rfind', 42)
+ # For a variety of combinations,
+ # verify that str.rfind() matches __contains__
+ # and that the found substring is really at that location
+ charset = ['', 'a', 'b', 'c']
+ digits = 5
+ base = len(charset)
+ teststrings = set()
+ for i in range(base ** digits):
+ entry = []
+ for j in range(digits):
+ i, m = divmod(i, base)
+ entry.append(charset[m])
+ teststrings.add(''.join(entry))
+ teststrings = [self.fixtype(ts) for ts in teststrings]
+ for i in teststrings:
+ for j in teststrings:
+ loc = i.rfind(j)
+ r1 = (loc != -1)
+ r2 = j in i
+ self.assertEqual(r1, r2)
+ if loc != -1:
+ self.assertEqual(i[loc:loc+len(j)], j)
+
+ # issue 7458
+ self.checkequal(-1, 'ab', 'rfind', 'xxx', sys.maxsize + 1, 0)
+
def test_index(self):
self.checkequal(0, 'abcdefghiabc', 'index', '')
self.checkequal(3, 'abcdefghiabc', 'index', 'def')
@@ -1071,7 +1099,6 @@ class MixinStrUnicodeUserStringTest:
longvalue = sys.maxsize + 10
slongvalue = str(longvalue)
- if slongvalue[-1] in ("L","l"): slongvalue = slongvalue[:-1]
self.checkequal(' 42', '%3ld', '__mod__', 42)
self.checkequal('42', '%d', '__mod__', 42.0)
self.checkequal(slongvalue, '%d', '__mod__', longvalue)
@@ -1086,7 +1113,7 @@ class MixinStrUnicodeUserStringTest:
self.checkraises(ValueError, '%(foo', '__mod__', {})
self.checkraises(TypeError, '%(foo)s %(bar)s', '__mod__', ('foo', 42))
self.checkraises(TypeError, '%d', '__mod__', "42") # not numeric
- self.checkraises(TypeError, '%d', '__mod__', (42+0j)) # no int/long conversion provided
+ self.checkraises(TypeError, '%d', '__mod__', (42+0j)) # no int conversion provided
# argument names with properly nested brackets are supported
self.checkequal('bar', '%((foo))s', '__mod__', {'(foo)': 'bar'})
@@ -1104,7 +1131,7 @@ class MixinStrUnicodeUserStringTest:
format = '%%.%if' % prec
value = 0.01
for x in range(60):
- value = value * 3.141592655 / 3.0 * 10.0
+ value = value * 3.14159265359 / 3.0 * 10.0
self.checkcall(format, "__mod__", value)
def test_inplace_rewrites(self):