[pypy-svn] r68290 - in pypy/trunk/pypy/lib: . test2

arigo at codespeak.net arigo at codespeak.net
Fri Oct 9 19:22:17 CEST 2009


Author: arigo
Date: Fri Oct  9 19:22:16 2009
New Revision: 68290

Added:
   pypy/trunk/pypy/lib/test2/test_grp_extra.py   (contents, props changed)
Modified:
   pypy/trunk/pypy/lib/grp.py
Log:
issue457 resolved

Test and fix for grp.getgrnam().  Thanks haypo.



Modified: pypy/trunk/pypy/lib/grp.py
==============================================================================
--- pypy/trunk/pypy/lib/grp.py	(original)
+++ pypy/trunk/pypy/lib/grp.py	Fri Oct  9 19:22:16 2009
@@ -71,10 +71,12 @@
         raise KeyError(gid)
     return _group_from_gstruct(res)
 
-def getgrnam(gid):
-    res = libc.getgrnam(gid)
+def getgrnam(name):
+    if not isinstance(name, str):
+        raise TypeError("expected string")
+    res = libc.getgrnam(name)
     if not res:
-        raise KeyError(gid)
+        raise KeyError(name)
     return _group_from_gstruct(res)
 
 def getgrall():

Added: pypy/trunk/pypy/lib/test2/test_grp_extra.py
==============================================================================
--- (empty file)
+++ pypy/trunk/pypy/lib/test2/test_grp_extra.py	Fri Oct  9 19:22:16 2009
@@ -0,0 +1,5 @@
+import py
+from pypy.lib import grp
+
+def test_extra():
+    py.test.raises(TypeError, grp.getgrnam, None)



More information about the Pypy-commit mailing list