[pypy-svn] r23091 - in pypy/dist/pypy/objspace/std: . test

arigo at codespeak.net arigo at codespeak.net
Tue Feb 7 11:23:00 CET 2006


Author: arigo
Date: Tue Feb  7 11:22:58 2006
New Revision: 23091

Modified:
   pypy/dist/pypy/objspace/std/stringobject.py
   pypy/dist/pypy/objspace/std/test/test_stringobject.py
Log:
str.translate() should complain on tables too long as well as too short.


Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py	(original)
+++ pypy/dist/pypy/objspace/std/stringobject.py	Tue Feb  7 11:22:58 2006
@@ -936,7 +936,7 @@
         remaining characters have been mapped through the given translation table, 
         which must be a string of length 256"""
 
-        if len(table) < 256:
+        if len(table) != 256:
             raise ValueError("translation table must be 256 characters long")
 
         L =  [ table[ord(s[i])] for i in range(len(s)) if s[i] not in deletechars ]

Modified: pypy/dist/pypy/objspace/std/test/test_stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_stringobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_stringobject.py	Tue Feb  7 11:22:58 2006
@@ -551,8 +551,9 @@
         assert 'xyz' == 'xyz'.translate(table)
         assert 'yz' ==  'xyz'.translate(table, 'x')
         
-        #self.assertRaises(ValueError, 'xyz'.translate('too short', 'strip'))
-        #self.assertRaises(ValueError, 'xyz'.translate('too short'))
+        raises(ValueError, 'xyz'.translate, 'too short', 'strip')
+        raises(ValueError, 'xyz'.translate, 'too short')
+        raises(ValueError, 'xyz'.translate, 'too long'*33)
 
     def test_iter(self):
         l=[]



More information about the Pypy-commit mailing list