From 43bc1f18dbf18b9a7639f0933b829cf83d05c382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20D=C3=B6rwald?= Date: Tue, 15 Apr 2003 15:59:36 +0000 Subject: [PATCH] Fix the test so that it works even when /etc/group has two entries for the same gid. --- Lib/test/test_grp.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_grp.py b/Lib/test/test_grp.py index 85a52c1f2c6..f27ef8cf1e5 100755 --- a/Lib/test/test_grp.py +++ b/Lib/test/test_grp.py @@ -9,6 +9,7 @@ class GroupDatabaseTestCase(unittest.TestCase): def test_values(self): entries = grp.getgrall() + entriesbygid = {} for e in entries: self.assertEqual(len(e), 4) @@ -22,7 +23,17 @@ class GroupDatabaseTestCase(unittest.TestCase): self.assert_(isinstance(e.gr_mem, list)) self.assertEqual(grp.getgrnam(e.gr_name), e) - self.assertEqual(grp.getgrgid(e.gr_gid), e) + # The following won't work, because of duplicate entries + # for one gid + # self.assertEqual(grp.getgrgid(e.gr_gid), e) + # instead of this collect all entries for one uid + # and check afterwards + entriesbygid.setdefault(e.gr_gid, []).append(e) + + # check whether the entry returned by getgrgid() + # for each uid is among those from getgrall() for this uid + for e in entries: + self.assert_(grp.getgrgid(e.gr_gid) in entriesbygid[e.gr_gid]) def test_errors(self): self.assertRaises(TypeError, grp.getgrgid)