diff options
Diffstat (limited to 'Lib/test/test_pwd.py')
-rw-r--r-- | Lib/test/test_pwd.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py index 255a34c6d4..67e11b6859 100644 --- a/Lib/test/test_pwd.py +++ b/Lib/test/test_pwd.py @@ -1,7 +1,8 @@ +import sys import unittest from test import test_support -import pwd +pwd = test_support.import_module('pwd') class PwdTest(unittest.TestCase): @@ -13,19 +14,19 @@ class PwdTest(unittest.TestCase): for e in entries: self.assertEqual(len(e), 7) self.assertEqual(e[0], e.pw_name) - self.assert_(isinstance(e.pw_name, basestring)) + self.assertIsInstance(e.pw_name, basestring) self.assertEqual(e[1], e.pw_passwd) - self.assert_(isinstance(e.pw_passwd, basestring)) + self.assertIsInstance(e.pw_passwd, basestring) self.assertEqual(e[2], e.pw_uid) - self.assert_(isinstance(e.pw_uid, int)) + self.assertIsInstance(e.pw_uid, int) self.assertEqual(e[3], e.pw_gid) - self.assert_(isinstance(e.pw_gid, int)) + self.assertIsInstance(e.pw_gid, int) self.assertEqual(e[4], e.pw_gecos) - self.assert_(isinstance(e.pw_gecos, basestring)) + self.assertIsInstance(e.pw_gecos, basestring) self.assertEqual(e[5], e.pw_dir) - self.assert_(isinstance(e.pw_dir, basestring)) + self.assertIsInstance(e.pw_dir, basestring) self.assertEqual(e[6], e.pw_shell) - self.assert_(isinstance(e.pw_shell, basestring)) + self.assertIsInstance(e.pw_shell, basestring) # The following won't work, because of duplicate entries # for one uid @@ -43,8 +44,8 @@ class PwdTest(unittest.TestCase): for e in entries: if not e[0] or e[0] == '+': continue # skip NIS entries etc. - self.assert_(pwd.getpwnam(e.pw_name) in entriesbyname[e.pw_name]) - self.assert_(pwd.getpwuid(e.pw_uid) in entriesbyuid[e.pw_uid]) + self.assertIn(pwd.getpwnam(e.pw_name), entriesbyname[e.pw_name]) + self.assertIn(pwd.getpwuid(e.pw_uid), entriesbyuid[e.pw_uid]) def test_errors(self): self.assertRaises(TypeError, pwd.getpwuid) @@ -83,11 +84,13 @@ class PwdTest(unittest.TestCase): self.assertRaises(KeyError, pwd.getpwnam, fakename) - # Choose a non-existent uid. - fakeuid = 4127 - while fakeuid in byuids: - fakeuid = (fakeuid * 3) % 0x10000 - + # In some cases, byuids isn't a complete list of all users in the + # system, so if we try to pick a value not in byuids (via a perturbing + # loop, say), pwd.getpwuid() might still be able to find data for that + # uid. Using sys.maxint may provoke the same problems, but hopefully + # it will be a more repeatable failure. + fakeuid = sys.maxint + self.assertNotIn(fakeuid, byuids) self.assertRaises(KeyError, pwd.getpwuid, fakeuid) def test_main(): |