Patch #1071: Improve unicode.translate() so that you can pass unicode

characters as mapping keys and invalid mapping keys are recognized
and raise an error.
This commit is contained in:
Georg Brandl 2007-10-23 06:52:59 +00:00
parent 3b8cb17695
commit 94c2c75b5e
3 changed files with 52 additions and 6 deletions

View file

@ -160,12 +160,14 @@ class UnicodeTest(
self.checkequalnofix('bbbc', 'abababc', 'translate', {ord('a'):None})
self.checkequalnofix('iiic', 'abababc', 'translate', {ord('a'):None, ord('b'):ord('i')})
self.checkequalnofix('iiix', 'abababc', 'translate', {ord('a'):None, ord('b'):ord('i'), ord('c'):'x'})
self.checkequalnofix('<i><i><i>c', 'abababc', 'translate', {ord('a'):None, ord('b'):'<i>'})
self.checkequalnofix('<i><i><i>c', 'abababc', 'translate', {'a':None, 'b':'<i>'})
self.checkequalnofix('c', 'abababc', 'translate', {ord('a'):None, ord('b'):''})
self.checkequalnofix('xyyx', 'xzx', 'translate', {ord('z'):'yy'})
self.assertRaises(TypeError, 'hello'.translate)
self.assertRaises(TypeError, 'abababc'.translate, 'abc', 'xyz')
self.assertRaises(ValueError, 'abababc'.translate, {'xy':2})
self.assertRaises(TypeError, 'abababc'.translate, {(1,):2})
def test_split(self):
string_tests.CommonTest.test_split(self)