Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(11)

Unified Diff: Lib/test/string_tests.py

Issue 8706: accept keyword arguments on all base type methods and builtins
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/collections/__init__.py ('k') | Lib/test/test_userstring.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/string_tests.py Sun Feb 26 18:09:50 2012 +0100
+++ b/Lib/test/string_tests.py Sun Feb 26 20:28:46 2012 +0100
@@ -45,7 +45,7 @@
return tuple([self.fixtype(x) for x in obj])
elif isinstance(obj, dict):
return dict([
- (self.fixtype(key), self.fixtype(value))
+ (key, self.fixtype(value))
for (key, value) in obj.items()
])
else:
@@ -75,14 +75,15 @@
realresult = getattr(obj, methodname)(*args)
self.assertIsNot(obj, realresult)
- # check that obj.method(*args) raises exc
- def checkraises(self, exc, obj, methodname, *args):
+ # check that obj.method(*args, **kwargs) raises exc
+ def checkraises(self, exc, obj, methodname, *args, **kwargs):
obj = self.fixtype(obj)
args = self.fixtype(args)
+ kwargs = self.fixtype(kwargs)
self.assertRaises(
exc,
getattr(obj, methodname),
- *args
+ *args, **kwargs
)
# call obj.method(*args) without any checks
@@ -93,40 +94,67 @@
def test_count(self):
self.checkequal(3, 'aaa', 'count', 'a')
+ self.checkequal(3, 'aaa', 'count', sub='a')
+ self.checkequal(0, 'aaa', 'count', 'b')
+ self.checkequal(0, 'aaa', 'count', sub='b')
+ self.checkequal(3, 'aaa', 'count', 'a')
+ self.checkequal(3, 'aaa', 'count', sub='a')
self.checkequal(0, 'aaa', 'count', 'b')
self.checkequal(3, 'aaa', 'count', 'a')
+ self.checkequal(3, 'aaa', 'count', sub='a')
self.checkequal(0, 'aaa', 'count', 'b')
- self.checkequal(3, 'aaa', 'count', 'a')
+ self.checkequal(0, 'aaa', 'count', sub='b')
self.checkequal(0, 'aaa', 'count', 'b')
- self.checkequal(0, 'aaa', 'count', 'b')
+ self.checkequal(0, 'aaa', 'count', sub='b')
self.checkequal(2, 'aaa', 'count', 'a', 1)
+ self.checkequal(2, 'aaa', 'count', 'a', start=1)
self.checkequal(0, 'aaa', 'count', 'a', 10)
+ self.checkequal(0, 'aaa', 'count', 'a', start=10)
self.checkequal(1, 'aaa', 'count', 'a', -1)
+ self.checkequal(1, 'aaa', 'count', 'a', start=-1)
self.checkequal(3, 'aaa', 'count', 'a', -10)
+ self.checkequal(3, 'aaa', 'count', 'a', start=-10)
self.checkequal(1, 'aaa', 'count', 'a', 0, 1)
+ self.checkequal(1, 'aaa', 'count', 'a', start=0, end=1)
self.checkequal(3, 'aaa', 'count', 'a', 0, 10)
+ self.checkequal(3, 'aaa', 'count', 'a', start=0, end=10)
self.checkequal(2, 'aaa', 'count', 'a', 0, -1)
+ self.checkequal(2, 'aaa', 'count', 'a', start=0, end=-1)
self.checkequal(0, 'aaa', 'count', 'a', 0, -10)
+ self.checkequal(0, 'aaa', 'count', sub='a', start=0, end=-10)
self.checkequal(3, 'aaa', 'count', '', 1)
+ self.checkequal(3, 'aaa', 'count', '', start=1)
self.checkequal(1, 'aaa', 'count', '', 3)
+ self.checkequal(1, 'aaa', 'count', '', start=3)
self.checkequal(0, 'aaa', 'count', '', 10)
+ self.checkequal(0, 'aaa', 'count', sub='', start=10)
self.checkequal(2, 'aaa', 'count', '', -1)
+ self.checkequal(2, 'aaa', 'count', sub='', start=-1)
self.checkequal(4, 'aaa', 'count', '', -10)
+ self.checkequal(4, 'aaa', 'count', sub='', start=-10)
self.checkequal(1, '', 'count', '')
+ self.checkequal(1, '', 'count', sub='')
self.checkequal(0, '', 'count', '', 1, 1)
+ self.checkequal(0, '', 'count', sub='', start=1, end=1)
self.checkequal(0, '', 'count', '', sys.maxsize, 0)
+ self.checkequal(0, '', 'count', sub='', start=sys.maxsize, end=0)
self.checkequal(0, '', 'count', 'xx')
+ self.checkequal(0, '', 'count', sub='xx')
self.checkequal(0, '', 'count', 'xx', 1, 1)
+ self.checkequal(0, '', 'count', sub='xx', start=1, end=1)
self.checkequal(0, '', 'count', 'xx', sys.maxsize, 0)
+ self.checkequal(0, '', 'count', sub='xx', start=sys.maxsize, end=0)
self.checkraises(TypeError, 'hello', 'count')
if self.contains_bytes:
self.checkequal(0, 'hello', 'count', 42)
+ self.checkequal(0, 'hello', 'count', sub=42)
else:
self.checkraises(TypeError, 'hello', 'count', 42)
+ self.checkraises(TypeError, 'hello', 'count', sub=42)
# For a variety of combinations,
# verify that str.count() matches an equivalent function
@@ -157,37 +185,58 @@
def test_find(self):
self.checkequal(0, 'abcdefghiabc', 'find', 'abc')
+ self.checkequal(0, 'abcdefghiabc', 'find', sub='abc')
self.checkequal(9, 'abcdefghiabc', 'find', 'abc', 1)
+ self.checkequal(9, 'abcdefghiabc', 'find', sub='abc', start=1)
self.checkequal(-1, 'abcdefghiabc', 'find', 'def', 4)
+ self.checkequal(-1, 'abcdefghiabc', 'find', sub='def', start=4)
self.checkequal(0, 'abc', 'find', '', 0)
+ self.checkequal(0, 'abc', 'find', sub='', start=0)
self.checkequal(3, 'abc', 'find', '', 3)
+ self.checkequal(3, 'abc', 'find', sub='', start=3)
self.checkequal(-1, 'abc', 'find', '', 4)
+ self.checkequal(-1, 'abc', 'find', sub='', start=4)
# to check the ability to pass None as defaults
self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a')
+ self.checkequal( 2, 'rrarrrrrrrrra', 'find', sub='a')
self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4)
+ self.checkequal(12, 'rrarrrrrrrrra', 'find', sub='a', start=4)
self.checkequal(-1, 'rrarrrrrrrrra', 'find', 'a', 4, 6)
+ self.checkequal(-1, 'rrarrrrrrrrra', 'find', sub='a', start=4, end=6)
self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4, None)
+ self.checkequal(12, 'rrarrrrrrrrra', 'find', sub='a', start=4, end=None)
self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a', None, 6)
+ self.checkequal( 2, 'rrarrrrrrrrra', 'find', sub='a', start=None, end=6)
self.checkraises(TypeError, 'hello', 'find')
if self.contains_bytes:
self.checkequal(-1, 'hello', 'find', 42)
+ self.checkequal(-1, 'hello', 'find', sub=42)
else:
self.checkraises(TypeError, 'hello', 'find', 42)
+ self.checkraises(TypeError, 'hello', 'find', sub=42)
self.checkequal(0, '', 'find', '')
+ self.checkequal(0, '', 'find', sub='')
self.checkequal(-1, '', 'find', '', 1, 1)
+ self.checkequal(-1, '', 'find', sub='', start=1, end=1)
self.checkequal(-1, '', 'find', '', sys.maxsize, 0)
+ self.checkequal(-1, '', 'find', sub='', start=sys.maxsize, end=0)
self.checkequal(-1, '', 'find', 'xx')
+ self.checkequal(-1, '', 'find', sub='xx')
self.checkequal(-1, '', 'find', 'xx', 1, 1)
+ self.checkequal(-1, '', 'find', sub='xx', start=1, end=1)
self.checkequal(-1, '', 'find', 'xx', sys.maxsize, 0)
+ self.checkequal(-1, '', 'find', sub='xx', start=sys.maxsize, end=0)
# issue 7458
self.checkequal(-1, 'ab', 'find', 'xxx', sys.maxsize + 1, 0)
+ self.checkequal(-1, 'ab', 'find', sub='xxx', start=sys.maxsize + 1,
+ end=0)
# For a variety of combinations,
# verify that str.find() matches __contains__
@@ -214,27 +263,42 @@
def test_rfind(self):
self.checkequal(9, 'abcdefghiabc', 'rfind', 'abc')
+ self.checkequal(9, 'abcdefghiabc', 'rfind', sub='abc')
self.checkequal(12, 'abcdefghiabc', 'rfind', '')
+ self.checkequal(12, 'abcdefghiabc', 'rfind', sub='')
self.checkequal(0, 'abcdefghiabc', 'rfind', 'abcd')
+ self.checkequal(0, 'abcdefghiabc', 'rfind', sub='abcd')
self.checkequal(-1, 'abcdefghiabc', 'rfind', 'abcz')
+ self.checkequal(-1, 'abcdefghiabc', 'rfind', sub='abcz')
self.checkequal(3, 'abc', 'rfind', '', 0)
+ self.checkequal(3, 'abc', 'rfind', sub='', start=0)
self.checkequal(3, 'abc', 'rfind', '', 3)
+ self.checkequal(3, 'abc', 'rfind', sub='', start=3)
self.checkequal(-1, 'abc', 'rfind', '', 4)
+ self.checkequal(-1, 'abc', 'rfind', sub='', start=4)
# to check the ability to pass None as defaults
self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a')
+ self.checkequal(12, 'rrarrrrrrrrra', 'rfind', sub='a')
self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4)
+ self.checkequal(12, 'rrarrrrrrrrra', 'rfind', sub='a', start=4)
self.checkequal(-1, 'rrarrrrrrrrra', 'rfind', 'a', 4, 6)
+ self.checkequal(-1, 'rrarrrrrrrrra', 'rfind', sub='a', start=4, end=6)
self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4, None)
- self.checkequal( 2, 'rrarrrrrrrrra', 'rfind', 'a', None, 6)
+ self.checkequal(12, 'rrarrrrrrrrra', 'rfind', sub='a', start=4,
+ end=None)
+ self.checkequal(2, 'rrarrrrrrrrra', 'rfind', 'a', None, 6)
+ self.checkequal(2, 'rrarrrrrrrrra', 'rfind', sub='a', start=None, end=6)
self.checkraises(TypeError, 'hello', 'rfind')
if self.contains_bytes:
self.checkequal(-1, 'hello', 'rfind', 42)
+ self.checkequal(-1, 'hello', 'rfind', sub=42)
else:
self.checkraises(TypeError, 'hello', 'rfind', 42)
+ self.checkraises(TypeError, 'hello', 'rfind', sub=42)
# For a variety of combinations,
# verify that str.rfind() matches __contains__
@@ -264,54 +328,93 @@
def test_index(self):
self.checkequal(0, 'abcdefghiabc', 'index', '')
+ self.checkequal(0, 'abcdefghiabc', 'index', sub='')
self.checkequal(3, 'abcdefghiabc', 'index', 'def')
+ self.checkequal(3, 'abcdefghiabc', 'index', sub='def')
self.checkequal(0, 'abcdefghiabc', 'index', 'abc')
+ self.checkequal(0, 'abcdefghiabc', 'index', sub='abc')
self.checkequal(9, 'abcdefghiabc', 'index', 'abc', 1)
+ self.checkequal(9, 'abcdefghiabc', 'index', sub='abc', start=1)
self.checkraises(ValueError, 'abcdefghiabc', 'index', 'hib')
+ self.checkraises(ValueError, 'abcdefghiabc', 'index', sub='hib')
self.checkraises(ValueError, 'abcdefghiab', 'index', 'abc', 1)
+ self.checkraises(ValueError, 'abcdefghiab', 'index', sub='abc', start=1)
self.checkraises(ValueError, 'abcdefghi', 'index', 'ghi', 8)
+ self.checkraises(ValueError, 'abcdefghi', 'index', sub='ghi', start=8)
self.checkraises(ValueError, 'abcdefghi', 'index', 'ghi', -1)
+ self.checkraises(ValueError, 'abcdefghi', 'index', sub='ghi', start=-1)
# to check the ability to pass None as defaults
- self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a')
+ self.checkequal(2, 'rrarrrrrrrrra', 'index', 'a')
+ self.checkequal(2, 'rrarrrrrrrrra', 'index', sub='a')
self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4)
+ self.checkequal(12, 'rrarrrrrrrrra', 'index', sub='a', start=4)
self.checkraises(ValueError, 'rrarrrrrrrrra', 'index', 'a', 4, 6)
+ self.checkraises(ValueError, 'rrarrrrrrrrra', 'index', sub='a', start=4,
+ end=6)
self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4, None)
- self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a', None, 6)
+ self.checkequal(12, 'rrarrrrrrrrra', 'index', sub='a', start=4,
+ end=None)
+ self.checkequal(2, 'rrarrrrrrrrra', 'index', sub='a', start=None,
+ end=6)
self.checkraises(TypeError, 'hello', 'index')
if self.contains_bytes:
self.checkraises(ValueError, 'hello', 'index', 42)
+ self.checkraises(ValueError, 'hello', 'index', sub=42)
else:
self.checkraises(TypeError, 'hello', 'index', 42)
+ self.checkraises(TypeError, 'hello', 'index', sub=42)
def test_rindex(self):
self.checkequal(12, 'abcdefghiabc', 'rindex', '')
+ self.checkequal(12, 'abcdefghiabc', 'rindex', sub='')
self.checkequal(3, 'abcdefghiabc', 'rindex', 'def')
+ self.checkequal(3, 'abcdefghiabc', 'rindex', sub='def')
self.checkequal(9, 'abcdefghiabc', 'rindex', 'abc')
+ self.checkequal(9, 'abcdefghiabc', 'rindex', sub='abc')
self.checkequal(0, 'abcdefghiabc', 'rindex', 'abc', 0, -1)
+ self.checkequal(0, 'abcdefghiabc', 'rindex', sub='abc', start=0,
+ end=-1)
self.checkraises(ValueError, 'abcdefghiabc', 'rindex', 'hib')
+ self.checkraises(ValueError, 'abcdefghiabc', 'rindex', sub='hib')
self.checkraises(ValueError, 'defghiabc', 'rindex', 'def', 1)
+ self.checkraises(ValueError, 'defghiabc', 'rindex', sub='def', start=1)
self.checkraises(ValueError, 'defghiabc', 'rindex', 'abc', 0, -1)
+ self.checkraises(ValueError, 'defghiabc', 'rindex', sub='abc', start=0,
+ end=-1)
self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, 8)
- self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, -1)
+ self.checkraises(ValueError, 'abcdefghi', 'rindex', sub='ghi', start=0,
+ end=8)
+ self.checkraises(ValueError, 'abcdefghi', 'rindex', sub='ghi', start=0,
+ end=-1)
# to check the ability to pass None as defaults
self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a')
+ self.checkequal(12, 'rrarrrrrrrrra', 'rindex', sub='a')
self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4)
+ self.checkequal(12, 'rrarrrrrrrrra', 'rindex', sub='a', start=4)
self.checkraises(ValueError, 'rrarrrrrrrrra', 'rindex', 'a', 4, 6)
+ self.checkraises(ValueError, 'rrarrrrrrrrra', 'rindex', sub='a',
+ start=4, end=6)
self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4, None)
- self.checkequal( 2, 'rrarrrrrrrrra', 'rindex', 'a', None, 6)
+ self.checkequal(12, 'rrarrrrrrrrra', 'rindex', sub='a', start=4,
+ end=None)
+ self.checkequal(2, 'rrarrrrrrrrra', 'rindex', 'a', None, 6)
+ self.checkequal(2, 'rrarrrrrrrrra', 'rindex', sub='a', start=None,
+ end=6)
self.checkraises(TypeError, 'hello', 'rindex')
if self.contains_bytes:
self.checkraises(ValueError, 'hello', 'rindex', 42)
+ self.checkraises(ValueError, 'hello', 'rindex', sub=42)
else:
self.checkraises(TypeError, 'hello', 'rindex', 42)
+ self.checkraises(TypeError, 'hello', 'rindex', sub=42)
def test_lower(self):
self.checkequal('hello', 'HeLLo', 'lower')
@@ -969,97 +1072,197 @@
def test_startswith(self):
self.checkequal(True, 'hello', 'startswith', 'he')
+ self.checkequal(True, 'hello', 'startswith', sub='he')
self.checkequal(True, 'hello', 'startswith', 'hello')
+ self.checkequal(True, 'hello', 'startswith', sub='hello')
self.checkequal(False, 'hello', 'startswith', 'hello world')
+ self.checkequal(False, 'hello', 'startswith', sub='hello world')
self.checkequal(True, 'hello', 'startswith', '')
+ self.checkequal(True, 'hello', 'startswith', sub='')
self.checkequal(False, 'hello', 'startswith', 'ello')
+ self.checkequal(False, 'hello', 'startswith', sub='ello')
self.checkequal(True, 'hello', 'startswith', 'ello', 1)
+ self.checkequal(True, 'hello', 'startswith', sub='ello', start=1)
self.checkequal(True, 'hello', 'startswith', 'o', 4)
+ self.checkequal(True, 'hello', 'startswith', sub='o', start=4)
self.checkequal(False, 'hello', 'startswith', 'o', 5)
+ self.checkequal(False, 'hello', 'startswith', sub='o', start=5)
self.checkequal(True, 'hello', 'startswith', '', 5)
+ self.checkequal(True, 'hello', 'startswith', sub='', start=5)
self.checkequal(False, 'hello', 'startswith', 'lo', 6)
+ self.checkequal(False, 'hello', 'startswith', sub='lo', start=6)
self.checkequal(True, 'helloworld', 'startswith', 'lowo', 3)
+ self.checkequal(True, 'helloworld', 'startswith', sub='lowo', start=3)
self.checkequal(True, 'helloworld', 'startswith', 'lowo', 3, 7)
- self.checkequal(False, 'helloworld', 'startswith', 'lowo', 3, 6)
+ self.checkequal(True, 'helloworld', 'startswith', sub='lowo', start=3,
+ end=7)
+ self.checkequal(False, 'helloworld', 'startswith', sub='lowo', start=3,
+ end=6)
# test negative indices
self.checkequal(True, 'hello', 'startswith', 'he', 0, -1)
+ self.checkequal(True, 'hello', 'startswith', sub='he', start=0, end=-1)
self.checkequal(True, 'hello', 'startswith', 'he', -53, -1)
+ self.checkequal(True, 'hello', 'startswith', sub='he', start=-53,
+ end=-1)
self.checkequal(False, 'hello', 'startswith', 'hello', 0, -1)
+ self.checkequal(False, 'hello', 'startswith', sub='hello', start=0,
+ end=-1)
self.checkequal(False, 'hello', 'startswith', 'hello world', -1, -10)
+ self.checkequal(False, 'hello', 'startswith', sub='hello world',
+ start=-1, end=-10)
self.checkequal(False, 'hello', 'startswith', 'ello', -5)
+ self.checkequal(False, 'hello', 'startswith', sub='ello', start=-5)
self.checkequal(True, 'hello', 'startswith', 'ello', -4)
+ self.checkequal(True, 'hello', 'startswith', sub='ello', start=-4)
self.checkequal(False, 'hello', 'startswith', 'o', -2)
+ self.checkequal(False, 'hello', 'startswith', sub='o', start=-2)
self.checkequal(True, 'hello', 'startswith', 'o', -1)
+ self.checkequal(True, 'hello', 'startswith', sub='o', start=-1)
self.checkequal(True, 'hello', 'startswith', '', -3, -3)
+ self.checkequal(True, 'hello', 'startswith', sub='', start=-3, end=-3)
self.checkequal(False, 'hello', 'startswith', 'lo', -9)
+ self.checkequal(False, 'hello', 'startswith', sub='lo', start=-9)
self.checkraises(TypeError, 'hello', 'startswith')
self.checkraises(TypeError, 'hello', 'startswith', 42)
+ self.checkraises(TypeError, 'hello', 'startswith', sub=42)
# test tuple arguments
self.checkequal(True, 'hello', 'startswith', ('he', 'ha'))
+ self.checkequal(True, 'hello', 'startswith', sub=('he', 'ha'))
self.checkequal(False, 'hello', 'startswith', ('lo', 'llo'))
+ self.checkequal(False, 'hello', 'startswith', sub=('lo', 'llo'))
self.checkequal(True, 'hello', 'startswith', ('hellox', 'hello'))
+ self.checkequal(True, 'hello', 'startswith', sub=('hellox', 'hello'))
self.checkequal(False, 'hello', 'startswith', ())
+ self.checkequal(False, 'hello', 'startswith', sub=())
self.checkequal(True, 'helloworld', 'startswith', ('hellowo',
'rld', 'lowo'), 3)
+ self.checkequal(True, 'helloworld', 'startswith',
+ sub=('hellowo', 'rld', 'lowo'), start=3)
self.checkequal(False, 'helloworld', 'startswith', ('hellowo', 'ello',
'rld'), 3)
+ self.checkequal(False, 'helloworld', 'startswith',
+ sub=('hellowo', 'ello', 'rld'), start=3)
self.checkequal(True, 'hello', 'startswith', ('lo', 'he'), 0, -1)
+ self.checkequal(True, 'hello', 'startswith', sub=('lo', 'he'), start=0,
+ end=-1)
self.checkequal(False, 'hello', 'startswith', ('he', 'hel'), 0, 1)
+ self.checkequal(False, 'hello', 'startswith', sub=('he', 'hel'),
+ start=0, end=1)
self.checkequal(True, 'hello', 'startswith', ('he', 'hel'), 0, 2)
+ self.checkequal(True, 'hello', 'startswith', sub=('he', 'hel'),
+ start=0, end=2)
self.checkraises(TypeError, 'hello', 'startswith', (42,))
+ self.checkraises(TypeError, 'hello', 'startswith', sub=(42,))
def test_endswith(self):
self.checkequal(True, 'hello', 'endswith', 'lo')
+ self.checkequal(True, 'hello', 'endswith', sub='lo')
self.checkequal(False, 'hello', 'endswith', 'he')
+ self.checkequal(False, 'hello', 'endswith', sub='he')
self.checkequal(True, 'hello', 'endswith', '')
+ self.checkequal(True, 'hello', 'endswith', sub='')
self.checkequal(False, 'hello', 'endswith', 'hello world')
+ self.checkequal(False, 'hello', 'endswith', sub='hello world')
self.checkequal(False, 'helloworld', 'endswith', 'worl')
+ self.checkequal(False, 'helloworld', 'endswith', sub='worl')
self.checkequal(True, 'helloworld', 'endswith', 'worl', 3, 9)
+ self.checkequal(True, 'helloworld', 'endswith', sub='worl', start=3,
+ end=9)
self.checkequal(True, 'helloworld', 'endswith', 'world', 3, 12)
+ self.checkequal(True, 'helloworld', 'endswith', sub='world', start=3,
+ end=12)
self.checkequal(True, 'helloworld', 'endswith', 'lowo', 1, 7)
+ self.checkequal(True, 'helloworld', 'endswith', sub='lowo', start=1,
+ end=7)
self.checkequal(True, 'helloworld', 'endswith', 'lowo', 2, 7)
+ self.checkequal(True, 'helloworld', 'endswith', sub='lowo', start=2,
+ end=7)
self.checkequal(True, 'helloworld', 'endswith', 'lowo', 3, 7)
+ self.checkequal(True, 'helloworld', 'endswith', sub='lowo', start=3,
+ end=7)
self.checkequal(False, 'helloworld', 'endswith', 'lowo', 4, 7)
+ self.checkequal(False, 'helloworld', 'endswith', sub='lowo', start=4,
+ end=7)
self.checkequal(False, 'helloworld', 'endswith', 'lowo', 3, 8)
+ self.checkequal(False, 'helloworld', 'endswith', sub='lowo', start=3,
+ end=8)
self.checkequal(False, 'ab', 'endswith', 'ab', 0, 1)
+ self.checkequal(False, 'ab', 'endswith', sub='ab', start=0, end=1)
self.checkequal(False, 'ab', 'endswith', 'ab', 0, 0)
+ self.checkequal(False, 'ab', 'endswith', sub='ab', start=0, end=0)
# test negative indices
self.checkequal(True, 'hello', 'endswith', 'lo', -2)
+ self.checkequal(True, 'hello', 'endswith', sub='lo', start=-2)
self.checkequal(False, 'hello', 'endswith', 'he', -2)
+ self.checkequal(False, 'hello', 'endswith', sub='he', start=-2)
self.checkequal(True, 'hello', 'endswith', '', -3, -3)
+ self.checkequal(True, 'hello', 'endswith', sub='', start=-3, end=-3)
self.checkequal(False, 'hello', 'endswith', 'hello world', -10, -2)
+ self.checkequal(False, 'hello', 'endswith', sub='hello world',
+ start=-10, end=-2)
self.checkequal(False, 'helloworld', 'endswith', 'worl', -6)
+ self.checkequal(False, 'helloworld', 'endswith', sub='worl', start=-6)
self.checkequal(True, 'helloworld', 'endswith', 'worl', -5, -1)
+ self.checkequal(True, 'helloworld', 'endswith', sub='worl', start=-5,
+ end=-1)
self.checkequal(True, 'helloworld', 'endswith', 'worl', -5, 9)
+ self.checkequal(True, 'helloworld', 'endswith', sub='worl', start=-5,
+ end=9)
self.checkequal(True, 'helloworld', 'endswith', 'world', -7, 12)
+ self.checkequal(True, 'helloworld', 'endswith', sub='world', start=-7,
+ end=12)
self.checkequal(True, 'helloworld', 'endswith', 'lowo', -99, -3)
+ self.checkequal(True, 'helloworld', 'endswith', sub='lowo', start=-99,
+ end=-3)
self.checkequal(True, 'helloworld', 'endswith', 'lowo', -8, -3)
+ self.checkequal(True, 'helloworld', 'endswith', sub='lowo', start=-8,
+ end=-3)
self.checkequal(True, 'helloworld', 'endswith', 'lowo', -7, -3)
+ self.checkequal(True, 'helloworld', 'endswith', sub='lowo', start=-7,
+ end=-3)
self.checkequal(False, 'helloworld', 'endswith', 'lowo', 3, -4)
+ self.checkequal(False, 'helloworld', 'endswith', sub='lowo', start=3,
+ end=-4)
self.checkequal(False, 'helloworld', 'endswith', 'lowo', -8, -2)
+ self.checkequal(False, 'helloworld', 'endswith', sub='lowo', start=-8,
+ end=-2)
self.checkraises(TypeError, 'hello', 'endswith')
self.checkraises(TypeError, 'hello', 'endswith', 42)
+ self.checkraises(TypeError, 'hello', 'endswith', sub=42)
# test tuple arguments
self.checkequal(False, 'hello', 'endswith', ('he', 'ha'))
+ self.checkequal(False, 'hello', 'endswith', sub=('he', 'ha'))
self.checkequal(True, 'hello', 'endswith', ('lo', 'llo'))
+ self.checkequal(True, 'hello', 'endswith', sub=('lo', 'llo'))
self.checkequal(True, 'hello', 'endswith', ('hellox', 'hello'))
+ self.checkequal(True, 'hello', 'endswith', sub=('hellox', 'hello'))
self.checkequal(False, 'hello', 'endswith', ())
+ self.checkequal(False, 'hello', 'endswith', sub=())
self.checkequal(True, 'helloworld', 'endswith', ('hellowo',
'rld', 'lowo'), 3)
+ self.checkequal(True, 'helloworld', 'endswith',
+ sub=('hellowo','rld', 'lowo'), start=3)
self.checkequal(False, 'helloworld', 'endswith', ('hellowo', 'ello',
'rld'), 3, -1)
+ self.checkequal(False, 'helloworld', 'endswith',
+ sub=('hellowo', 'ello','rld'), start=3, end=-1)
self.checkequal(True, 'hello', 'endswith', ('hell', 'ell'), 0, -1)
- self.checkequal(False, 'hello', 'endswith', ('he', 'hel'), 0, 1)
- self.checkequal(True, 'hello', 'endswith', ('he', 'hell'), 0, 4)
+ self.checkequal(True, 'hello', 'endswith', sub=('hell', 'ell'), start=0,
+ end=-1)
+ self.checkequal(False, 'hello', 'endswith', sub=('he', 'hel'), start=0,
+ end=1)
+ self.checkequal(True, 'hello', 'endswith', sub=('he', 'hell'), start=0,
+ end=4)
self.checkraises(TypeError, 'hello', 'endswith', (42,))
+ self.checkraises(TypeError, 'hello', 'endswith', sub=(42,))
def test___contains__(self):
self.checkequal(True, '', '__contains__', '')
« no previous file with comments | « Lib/collections/__init__.py ('k') | Lib/test/test_userstring.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+