Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r74330:85a12a7d5a34
Date: 2014-11-03 11:47 +0100
http://bitbucket.org/pypy/pypy/changeset/85a12a7d5a34/

Log:    Issue #1920: test and fix

diff --git a/lib_pypy/grp.py b/lib_pypy/grp.py
--- a/lib_pypy/grp.py
+++ b/lib_pypy/grp.py
@@ -66,11 +66,12 @@
 
 @builtinify
 def getgrnam(name):
-    if not isinstance(name, str):
+    if not isinstance(name, basestring):
         raise TypeError("expected string")
+    name = str(name)
     res = libc.getgrnam(name)
     if not res:
-        raise KeyError(name)
+        raise KeyError("'getgrnam(): name not found: %s'" % name)
     return _group_from_gstruct(res)
 
 @builtinify
diff --git a/pypy/module/test_lib_pypy/test_grp_extra.py 
b/pypy/module/test_lib_pypy/test_grp_extra.py
--- a/pypy/module/test_lib_pypy/test_grp_extra.py
+++ b/pypy/module/test_lib_pypy/test_grp_extra.py
@@ -9,7 +9,8 @@
                                     "No grp module on this platform")
 
     def test_basic(self):
-        raises(KeyError, self.grp.getgrnam, "dEkLofcG")
+        e = raises(KeyError, self.grp.getgrnam, "dEkLofcG")
+        assert e.value.args[0] == "'getgrnam(): name not found: dEkLofcG'"
         for name in ["root", "wheel"]:
             try:
                 g = self.grp.getgrnam(name)
@@ -19,6 +20,8 @@
             assert 'root' in g.gr_mem or g.gr_mem == []
             assert g.gr_name == name
             assert isinstance(g.gr_passwd, str)    # usually just 'x', don't 
hope :-)
+            g2 = self.grp.getgrnam(unicode(name))
+            assert g2 == g
             break
         else:
             raise
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to