Commit 5366fbae authored by Armin Rigo's avatar Armin Rigo

Issue #1920: test and fix

parent 3742b81d
......@@ -66,11 +66,12 @@ def getgrgid(gid):
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)
......@@ -9,7 +9,8 @@ class AppTestGrp:
"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"]:
g = self.grp.getgrnam(name)
......@@ -19,6 +20,8 @@ class AppTestGrp:
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
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment