Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_pwd.py

    r2 r391  
     1import sys
    12import unittest
    23from test import test_support
    34
    4 import pwd
     5pwd = test_support.import_module('pwd')
    56
    67class PwdTest(unittest.TestCase):
     
    1415            self.assertEqual(len(e), 7)
    1516            self.assertEqual(e[0], e.pw_name)
    16             self.assert_(isinstance(e.pw_name, basestring))
     17            self.assertIsInstance(e.pw_name, basestring)
    1718            self.assertEqual(e[1], e.pw_passwd)
    18             self.assert_(isinstance(e.pw_passwd, basestring))
     19            self.assertIsInstance(e.pw_passwd, basestring)
    1920            self.assertEqual(e[2], e.pw_uid)
    20             self.assert_(isinstance(e.pw_uid, int))
     21            self.assertIsInstance(e.pw_uid, (int, long))
    2122            self.assertEqual(e[3], e.pw_gid)
    22             self.assert_(isinstance(e.pw_gid, int))
     23            self.assertIsInstance(e.pw_gid, (int, long))
    2324            self.assertEqual(e[4], e.pw_gecos)
    24             self.assert_(isinstance(e.pw_gecos, basestring))
     25            self.assertIsInstance(e.pw_gecos, basestring)
    2526            self.assertEqual(e[5], e.pw_dir)
    26             self.assert_(isinstance(e.pw_dir, basestring))
     27            self.assertIsInstance(e.pw_dir, basestring)
    2728            self.assertEqual(e[6], e.pw_shell)
    28             self.assert_(isinstance(e.pw_shell, basestring))
     29            self.assertIsInstance(e.pw_shell, basestring)
    2930
    3031            # The following won't work, because of duplicate entries
     
    4445            if not e[0] or e[0] == '+':
    4546                continue # skip NIS entries etc.
    46             self.assert_(pwd.getpwnam(e.pw_name) in entriesbyname[e.pw_name])
    47             self.assert_(pwd.getpwuid(e.pw_uid) in entriesbyuid[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])
    4849
    4950    def test_errors(self):
    5051        self.assertRaises(TypeError, pwd.getpwuid)
     52        self.assertRaises(TypeError, pwd.getpwuid, 3.14)
    5153        self.assertRaises(TypeError, pwd.getpwnam)
     54        self.assertRaises(TypeError, pwd.getpwnam, 42)
    5255        self.assertRaises(TypeError, pwd.getpwall, 42)
    5356
     
    8487        self.assertRaises(KeyError, pwd.getpwnam, fakename)
    8588
    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)
    9097
    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)
    92104
    93105def test_main():
Note: See TracChangeset for help on using the changeset viewer.