diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2012-02-26 07:39:55 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2012-02-26 07:39:55 (GMT) |
commit | cda6b6d60d96e6f755da92deb5e4066839095791 (patch) | |
tree | 0835098963d975f54d46707bae270e08df2fc4fa /Lib | |
parent | 408026c7e8c019cf04372a4267c832241e18c62c (diff) | |
download | cpython-cda6b6d60d96e6f755da92deb5e4066839095791.zip cpython-cda6b6d60d96e6f755da92deb5e4066839095791.tar.gz cpython-cda6b6d60d96e6f755da92deb5e4066839095791.tar.bz2 |
#14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/string_tests.py | 24 | ||||
-rw-r--r-- | Lib/test/test_bytes.py | 16 |
2 files changed, 39 insertions, 1 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index feeb4ce..b7246eb 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -56,7 +56,7 @@ class BaseTest(unittest.TestCase): result = self.fixtype(result) obj = self.fixtype(obj) args = self.fixtype(args) - kwargs = self.fixtype(kwargs) + kwargs = {k: self.fixtype(v) for k,v in kwargs.items()} realresult = getattr(obj, methodname)(*args, **kwargs) self.assertEqual( result, @@ -389,6 +389,17 @@ class BaseTest(unittest.TestCase): self.checkequal(['a']*18 + ['aBLAHa'], ('aBLAH'*20)[:-4], 'split', 'BLAH', 18) + # with keyword args + self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', sep='|') + self.checkequal(['a', 'b|c|d'], + 'a|b|c|d', 'split', '|', maxsplit=1) + self.checkequal(['a', 'b|c|d'], + 'a|b|c|d', 'split', sep='|', maxsplit=1) + self.checkequal(['a', 'b|c|d'], + 'a|b|c|d', 'split', maxsplit=1, sep='|') + self.checkequal(['a', 'b c d'], + 'a b c d', 'split', maxsplit=1) + # argument type self.checkraises(TypeError, 'hello', 'split', 42, 42, 42) @@ -446,6 +457,17 @@ class BaseTest(unittest.TestCase): self.checkequal(['aBLAHa'] + ['a']*18, ('aBLAH'*20)[:-4], 'rsplit', 'BLAH', 18) + # with keyword args + self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', sep='|') + self.checkequal(['a|b|c', 'd'], + 'a|b|c|d', 'rsplit', '|', maxsplit=1) + self.checkequal(['a|b|c', 'd'], + 'a|b|c|d', 'rsplit', sep='|', maxsplit=1) + self.checkequal(['a|b|c', 'd'], + 'a|b|c|d', 'rsplit', maxsplit=1, sep='|') + self.checkequal(['a b c', 'd'], + 'a b c d', 'rsplit', maxsplit=1) + # argument type self.checkraises(TypeError, 'hello', 'rsplit', 42, 42, 42) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index bfb88de..203fc5c 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -435,6 +435,14 @@ class BaseBytesTest(unittest.TestCase): self.assertEqual(b.split(b'i'), [b'm', b'ss', b'ss', b'pp', b'']) self.assertEqual(b.split(b'ss'), [b'mi', b'i', b'ippi']) self.assertEqual(b.split(b'w'), [b]) + # with keyword args + b = self.type2test(b'a|b|c|d') + self.assertEqual(b.split(sep=b'|'), [b'a', b'b', b'c', b'd']) + self.assertEqual(b.split(b'|', maxsplit=1), [b'a', b'b|c|d']) + self.assertEqual(b.split(sep=b'|', maxsplit=1), [b'a', b'b|c|d']) + self.assertEqual(b.split(maxsplit=1, sep=b'|'), [b'a', b'b|c|d']) + b = self.type2test(b'a b c d') + self.assertEqual(b.split(maxsplit=1), [b'a', b'b c d']) def test_split_whitespace(self): for b in (b' arf barf ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf', @@ -463,6 +471,14 @@ class BaseBytesTest(unittest.TestCase): self.assertEqual(b.rsplit(b'i'), [b'm', b'ss', b'ss', b'pp', b'']) self.assertEqual(b.rsplit(b'ss'), [b'mi', b'i', b'ippi']) self.assertEqual(b.rsplit(b'w'), [b]) + # with keyword args + b = self.type2test(b'a|b|c|d') + self.assertEqual(b.rsplit(sep=b'|'), [b'a', b'b', b'c', b'd']) + self.assertEqual(b.rsplit(b'|', maxsplit=1), [b'a|b|c', b'd']) + self.assertEqual(b.rsplit(sep=b'|', maxsplit=1), [b'a|b|c', b'd']) + self.assertEqual(b.rsplit(maxsplit=1, sep=b'|'), [b'a|b|c', b'd']) + b = self.type2test(b'a b c d') + self.assertEqual(b.rsplit(maxsplit=1), [b'a b c', b'd']) def test_rsplit_whitespace(self): for b in (b' arf barf ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf', |