Changeset 391 for python/trunk/Lib/test/test_pwd.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_pwd.py
r2 r391 1 import sys 1 2 import unittest 2 3 from test import test_support 3 4 4 import pwd 5 pwd = test_support.import_module('pwd') 5 6 6 7 class PwdTest(unittest.TestCase): … … 14 15 self.assertEqual(len(e), 7) 15 16 self.assertEqual(e[0], e.pw_name) 16 self.assert _(isinstance(e.pw_name, basestring))17 self.assertIsInstance(e.pw_name, basestring) 17 18 self.assertEqual(e[1], e.pw_passwd) 18 self.assert _(isinstance(e.pw_passwd, basestring))19 self.assertIsInstance(e.pw_passwd, basestring) 19 20 self.assertEqual(e[2], e.pw_uid) 20 self.assert _(isinstance(e.pw_uid, int))21 self.assertIsInstance(e.pw_uid, (int, long)) 21 22 self.assertEqual(e[3], e.pw_gid) 22 self.assert _(isinstance(e.pw_gid, int))23 self.assertIsInstance(e.pw_gid, (int, long)) 23 24 self.assertEqual(e[4], e.pw_gecos) 24 self.assert _(isinstance(e.pw_gecos, basestring))25 self.assertIsInstance(e.pw_gecos, basestring) 25 26 self.assertEqual(e[5], e.pw_dir) 26 self.assert _(isinstance(e.pw_dir, basestring))27 self.assertIsInstance(e.pw_dir, basestring) 27 28 self.assertEqual(e[6], e.pw_shell) 28 self.assert _(isinstance(e.pw_shell, basestring))29 self.assertIsInstance(e.pw_shell, basestring) 29 30 30 31 # The following won't work, because of duplicate entries … … 44 45 if not e[0] or e[0] == '+': 45 46 continue # skip NIS entries etc. 46 self.assert _(pwd.getpwnam(e.pw_name) inentriesbyname[e.pw_name])47 self.assert _(pwd.getpwuid(e.pw_uid) inentriesbyuid[e.pw_uid])47 self.assertIn(pwd.getpwnam(e.pw_name), entriesbyname[e.pw_name]) 48 self.assertIn(pwd.getpwuid(e.pw_uid), entriesbyuid[e.pw_uid]) 48 49 49 50 def test_errors(self): 50 51 self.assertRaises(TypeError, pwd.getpwuid) 52 self.assertRaises(TypeError, pwd.getpwuid, 3.14) 51 53 self.assertRaises(TypeError, pwd.getpwnam) 54 self.assertRaises(TypeError, pwd.getpwnam, 42) 52 55 self.assertRaises(TypeError, pwd.getpwall, 42) 53 56 … … 84 87 self.assertRaises(KeyError, pwd.getpwnam, fakename) 85 88 86 # Choose a non-existent uid. 87 fakeuid = 4127 88 while fakeuid in byuids: 89 fakeuid = (fakeuid * 3) % 0x10000 89 # In some cases, byuids isn't a complete list of all users in the 90 # system, so if we try to pick a value not in byuids (via a perturbing 91 # loop, say), pwd.getpwuid() might still be able to find data for that 92 # uid. Using sys.maxint may provoke the same problems, but hopefully 93 # it will be a more repeatable failure. 94 fakeuid = sys.maxint 95 self.assertNotIn(fakeuid, byuids) 96 self.assertRaises(KeyError, pwd.getpwuid, fakeuid) 90 97 91 self.assertRaises(KeyError, pwd.getpwuid, fakeuid) 98 # -1 shouldn't be a valid uid because it has a special meaning in many 99 # uid-related functions 100 self.assertRaises(KeyError, pwd.getpwuid, -1) 101 # should be out of uid_t range 102 self.assertRaises(KeyError, pwd.getpwuid, 2**128) 103 self.assertRaises(KeyError, pwd.getpwuid, -2**128) 92 104 93 105 def test_main():
Note:
See TracChangeset
for help on using the changeset viewer.