diff options
Diffstat (limited to 'Lib/test/test_pwd.py')
-rw-r--r-- | Lib/test/test_pwd.py | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py index 406578a70d1..ae1c8feca6a 100644 --- a/Lib/test/test_pwd.py +++ b/Lib/test/test_pwd.py @@ -1,3 +1,4 @@ +import sys import unittest from test import support @@ -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.assertTrue(isinstance(e.pw_name, str)) + self.assertIsInstance(e.pw_name, str) self.assertEqual(e[1], e.pw_passwd) - self.assertTrue(isinstance(e.pw_passwd, str)) + self.assertIsInstance(e.pw_passwd, str) self.assertEqual(e[2], e.pw_uid) - self.assertTrue(isinstance(e.pw_uid, int)) + self.assertIsInstance(e.pw_uid, int) self.assertEqual(e[3], e.pw_gid) - self.assertTrue(isinstance(e.pw_gid, int)) + self.assertIsInstance(e.pw_gid, int) self.assertEqual(e[4], e.pw_gecos) - self.assertTrue(isinstance(e.pw_gecos, str)) + self.assertIsInstance(e.pw_gecos, str) self.assertEqual(e[5], e.pw_dir) - self.assertTrue(isinstance(e.pw_dir, str)) + self.assertIsInstance(e.pw_dir, str) self.assertEqual(e[6], e.pw_shell) - self.assertTrue(isinstance(e.pw_shell, str)) + self.assertIsInstance(e.pw_shell, str) # 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.assertTrue(pwd.getpwnam(e.pw_name) in entriesbyname[e.pw_name]) - self.assertTrue(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.maxsize + self.assertNotIn(fakeuid, byuids) self.assertRaises(KeyError, pwd.getpwuid, fakeuid) def test_main(): |