[pypy-svn] r66662 - in pypy/branch/pyjitpl5/pypy/lib: . app_test
arigo at codespeak.net
arigo at codespeak.net
Wed Jul 29 14:19:53 CEST 2009
Author: arigo
Date: Wed Jul 29 14:19:52 2009
New Revision: 66662
Modified:
pypy/branch/pyjitpl5/pypy/lib/app_test/test_dbm_extra.py
pypy/branch/pyjitpl5/pypy/lib/dbm.py
Log:
Test and fix (correlated to CPython's dbm by changing the import
at the start of the test).
Modified: pypy/branch/pyjitpl5/pypy/lib/app_test/test_dbm_extra.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/lib/app_test/test_dbm_extra.py (original)
+++ pypy/branch/pyjitpl5/pypy/lib/app_test/test_dbm_extra.py Wed Jul 29 14:19:52 2009
@@ -1,3 +1,4 @@
+import py
from pypy.lib import dbm
from pypy.tool.udir import udir
@@ -7,3 +8,10 @@
x = d.get("42")
assert x is None
d.close()
+
+def test_set_nonstring():
+ path = str(udir.join('test_dbm_extra.test_set_nonstring'))
+ d = dbm.open(path, 'c')
+ py.test.raises(TypeError, "d[123] = 'xyz'")
+ py.test.raises(TypeError, "d['xyz'] = 123")
+ d.close()
Modified: pypy/branch/pyjitpl5/pypy/lib/dbm.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/lib/dbm.py (original)
+++ pypy/branch/pyjitpl5/pypy/lib/dbm.py Wed Jul 29 14:19:52 2009
@@ -57,11 +57,13 @@
raise KeyError
return value
- def _set(self, key, value):
+ def __setitem__(self, key, value):
if not self._aobj:
raise error('DBM object has already been closed')
if not isinstance(key, str):
raise TypeError("dbm mappings have string indices only")
+ if not isinstance(value, str):
+ raise TypeError("dbm mappings have string values only")
dat = datum()
dat.dptr = c_char_p(key)
dat.dsize = c_int(len(key))
@@ -115,11 +117,6 @@
return True
return False
- def __setitem__(self, key, value):
- if not isinstance(key, str) and isinstance(value, str):
- raise error("dbm mappings have string indices only")
- self._set(key, value)
-
def __delitem__(self, key):
if not isinstance(key, str):
raise error("dbm mappings have string indices only")
More information about the Pypy-commit
mailing list