mirror of
https://github.com/python/cpython.git
synced 2025-09-09 18:32:22 +00:00
Port test_pwd.py to PyUnit. Check that getpwall() and
getpwnam()/getpwuid() return consistent data. Change test_grp to check that getgrall() and getgrnam()/getgrgid() return consistent data. Add error checks similar to test_pwd.py. Port test___all__.py to PyUnit. From SF patch #662807.
This commit is contained in:
parent
255a3d08a1
commit
b1ded1e508
4 changed files with 319 additions and 239 deletions
|
@ -1,7 +0,0 @@
|
||||||
test_pwd
|
|
||||||
pwd.getpwall()
|
|
||||||
pwd.getpwuid()
|
|
||||||
pwd.getpwnam()
|
|
||||||
name matches uid
|
|
||||||
caught expected exception
|
|
||||||
caught expected exception
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import unittest
|
||||||
|
from test import test_support
|
||||||
|
|
||||||
from test.test_support import verify, verbose
|
from test.test_support import verify, verbose
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
|
@ -9,166 +12,189 @@ warnings.filterwarnings("ignore", ".* regsub .*", DeprecationWarning,
|
||||||
warnings.filterwarnings("ignore", ".* statcache .*", DeprecationWarning,
|
warnings.filterwarnings("ignore", ".* statcache .*", DeprecationWarning,
|
||||||
r'statcache$')
|
r'statcache$')
|
||||||
|
|
||||||
def check_all(modname):
|
class AllTest(unittest.TestCase):
|
||||||
names = {}
|
|
||||||
try:
|
def check_all(self, modname):
|
||||||
exec "import %s" % modname in names
|
names = {}
|
||||||
except ImportError:
|
|
||||||
# Silent fail here seems the best route since some modules
|
|
||||||
# may not be available in all environments.
|
|
||||||
# Since an ImportError may leave a partial module object in
|
|
||||||
# sys.modules, get rid of that first. Here's what happens if
|
|
||||||
# you don't: importing pty fails on Windows because pty tries to
|
|
||||||
# import FCNTL, which doesn't exist. That raises an ImportError,
|
|
||||||
# caught here. It also leaves a partial pty module in sys.modules.
|
|
||||||
# So when test_pty is called later, the import of pty succeeds,
|
|
||||||
# but shouldn't. As a result, test_pty crashes with an
|
|
||||||
# AttributeError instead of an ImportError, and regrtest interprets
|
|
||||||
# the latter as a test failure (ImportError is treated as "test
|
|
||||||
# skipped" -- which is what test_pty should say on Windows).
|
|
||||||
try:
|
try:
|
||||||
del sys.modules[modname]
|
exec "import %s" % modname in names
|
||||||
except KeyError:
|
except ImportError:
|
||||||
pass
|
# Silent fail here seems the best route since some modules
|
||||||
return
|
# may not be available in all environments.
|
||||||
verify(hasattr(sys.modules[modname], "__all__"),
|
# Since an ImportError may leave a partial module object in
|
||||||
"%s has no __all__ attribute" % modname)
|
# sys.modules, get rid of that first. Here's what happens if
|
||||||
names = {}
|
# you don't: importing pty fails on Windows because pty tries to
|
||||||
exec "from %s import *" % modname in names
|
# import FCNTL, which doesn't exist. That raises an ImportError,
|
||||||
if names.has_key("__builtins__"):
|
# caught here. It also leaves a partial pty module in sys.modules.
|
||||||
del names["__builtins__"]
|
# So when test_pty is called later, the import of pty succeeds,
|
||||||
keys = names.keys()
|
# but shouldn't. As a result, test_pty crashes with an
|
||||||
keys.sort()
|
# AttributeError instead of an ImportError, and regrtest interprets
|
||||||
all = list(sys.modules[modname].__all__) # in case it's a tuple
|
# the latter as a test failure (ImportError is treated as "test
|
||||||
all.sort()
|
# skipped" -- which is what test_pty should say on Windows).
|
||||||
verify(keys==all, "%s != %s" % (keys, all))
|
try:
|
||||||
|
del sys.modules[modname]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
return
|
||||||
|
verify(hasattr(sys.modules[modname], "__all__"),
|
||||||
|
"%s has no __all__ attribute" % modname)
|
||||||
|
names = {}
|
||||||
|
exec "from %s import *" % modname in names
|
||||||
|
if names.has_key("__builtins__"):
|
||||||
|
del names["__builtins__"]
|
||||||
|
keys = names.keys()
|
||||||
|
keys.sort()
|
||||||
|
all = list(sys.modules[modname].__all__) # in case it's a tuple
|
||||||
|
all.sort()
|
||||||
|
verify(keys==all, "%s != %s" % (keys, all))
|
||||||
|
|
||||||
if not sys.platform.startswith('java'):
|
def test_all(self):
|
||||||
# In case _socket fails to build, make this test fail more gracefully
|
if not sys.platform.startswith('java'):
|
||||||
# than an AttributeError somewhere deep in CGIHTTPServer.
|
# In case _socket fails to build, make this test fail more gracefully
|
||||||
import _socket
|
# than an AttributeError somewhere deep in CGIHTTPServer.
|
||||||
|
import _socket
|
||||||
|
|
||||||
check_all("BaseHTTPServer")
|
self.check_all("BaseHTTPServer")
|
||||||
check_all("CGIHTTPServer")
|
self.check_all("CGIHTTPServer")
|
||||||
check_all("ConfigParser")
|
self.check_all("ConfigParser")
|
||||||
check_all("Cookie")
|
self.check_all("Cookie")
|
||||||
check_all("MimeWriter")
|
self.check_all("MimeWriter")
|
||||||
check_all("SimpleHTTPServer")
|
self.check_all("SimpleHTTPServer")
|
||||||
check_all("SocketServer")
|
self.check_all("SocketServer")
|
||||||
check_all("StringIO")
|
self.check_all("StringIO")
|
||||||
check_all("UserString")
|
self.check_all("UserString")
|
||||||
check_all("aifc")
|
self.check_all("aifc")
|
||||||
check_all("atexit")
|
self.check_all("atexit")
|
||||||
check_all("audiodev")
|
self.check_all("audiodev")
|
||||||
check_all("base64")
|
self.check_all("base64")
|
||||||
check_all("bdb")
|
self.check_all("bdb")
|
||||||
check_all("binhex")
|
self.check_all("binhex")
|
||||||
check_all("calendar")
|
self.check_all("calendar")
|
||||||
check_all("cgi")
|
self.check_all("cgi")
|
||||||
check_all("cmd")
|
self.check_all("cmd")
|
||||||
check_all("code")
|
self.check_all("code")
|
||||||
check_all("codecs")
|
self.check_all("codecs")
|
||||||
check_all("codeop")
|
self.check_all("codeop")
|
||||||
check_all("colorsys")
|
self.check_all("colorsys")
|
||||||
check_all("commands")
|
self.check_all("commands")
|
||||||
check_all("compileall")
|
self.check_all("compileall")
|
||||||
check_all("copy")
|
self.check_all("copy")
|
||||||
check_all("copy_reg")
|
self.check_all("copy_reg")
|
||||||
check_all("dbhash")
|
self.check_all("dbhash")
|
||||||
check_all("dircache")
|
self.check_all("difflib")
|
||||||
check_all("dis")
|
self.check_all("dircache")
|
||||||
check_all("doctest")
|
self.check_all("dis")
|
||||||
check_all("dospath")
|
self.check_all("doctest")
|
||||||
check_all("filecmp")
|
self.check_all("dummy_thread")
|
||||||
check_all("fileinput")
|
self.check_all("dummy_threading")
|
||||||
check_all("fnmatch")
|
self.check_all("filecmp")
|
||||||
check_all("fpformat")
|
self.check_all("fileinput")
|
||||||
check_all("ftplib")
|
self.check_all("fnmatch")
|
||||||
check_all("getopt")
|
self.check_all("fpformat")
|
||||||
check_all("getpass")
|
self.check_all("ftplib")
|
||||||
check_all("gettext")
|
self.check_all("getopt")
|
||||||
check_all("glob")
|
self.check_all("getpass")
|
||||||
check_all("gopherlib")
|
self.check_all("gettext")
|
||||||
check_all("gzip")
|
self.check_all("glob")
|
||||||
check_all("htmllib")
|
self.check_all("gopherlib")
|
||||||
check_all("httplib")
|
self.check_all("gzip")
|
||||||
check_all("ihooks")
|
self.check_all("heapq")
|
||||||
check_all("imaplib")
|
self.check_all("htmllib")
|
||||||
check_all("imghdr")
|
self.check_all("httplib")
|
||||||
check_all("imputil")
|
self.check_all("ihooks")
|
||||||
check_all("keyword")
|
self.check_all("imaplib")
|
||||||
check_all("linecache")
|
self.check_all("imghdr")
|
||||||
check_all("locale")
|
self.check_all("imputil")
|
||||||
check_all("macpath")
|
self.check_all("keyword")
|
||||||
check_all("macurl2path")
|
self.check_all("linecache")
|
||||||
check_all("mailbox")
|
self.check_all("locale")
|
||||||
check_all("mhlib")
|
self.check_all("macpath")
|
||||||
check_all("mimetools")
|
self.check_all("macurl2path")
|
||||||
check_all("mimetypes")
|
self.check_all("mailbox")
|
||||||
check_all("mimify")
|
self.check_all("mailcap")
|
||||||
check_all("multifile")
|
self.check_all("mhlib")
|
||||||
check_all("netrc")
|
self.check_all("mimetools")
|
||||||
check_all("nntplib")
|
self.check_all("mimetypes")
|
||||||
check_all("ntpath")
|
self.check_all("mimify")
|
||||||
check_all("os")
|
self.check_all("multifile")
|
||||||
check_all("pdb")
|
self.check_all("netrc")
|
||||||
check_all("pickle")
|
self.check_all("nntplib")
|
||||||
check_all("pipes")
|
self.check_all("ntpath")
|
||||||
check_all("popen2")
|
self.check_all("opcode")
|
||||||
check_all("poplib")
|
self.check_all("os")
|
||||||
check_all("posixpath")
|
self.check_all("os2emxpath")
|
||||||
check_all("pprint")
|
self.check_all("pdb")
|
||||||
check_all("pre") # deprecated
|
self.check_all("pickle")
|
||||||
check_all("profile")
|
self.check_all("pipes")
|
||||||
check_all("pstats")
|
self.check_all("popen2")
|
||||||
check_all("pty")
|
self.check_all("poplib")
|
||||||
check_all("py_compile")
|
self.check_all("posixpath")
|
||||||
check_all("pyclbr")
|
self.check_all("pprint")
|
||||||
check_all("quopri")
|
self.check_all("pre") # deprecated
|
||||||
check_all("random")
|
self.check_all("profile")
|
||||||
check_all("re")
|
self.check_all("pstats")
|
||||||
check_all("reconvert")
|
self.check_all("pty")
|
||||||
check_all("regsub")
|
self.check_all("py_compile")
|
||||||
check_all("repr")
|
self.check_all("pyclbr")
|
||||||
check_all("rexec")
|
self.check_all("quopri")
|
||||||
check_all("rfc822")
|
self.check_all("random")
|
||||||
check_all("robotparser")
|
self.check_all("re")
|
||||||
check_all("sched")
|
self.check_all("reconvert")
|
||||||
check_all("sgmllib")
|
self.check_all("regsub")
|
||||||
check_all("shelve")
|
self.check_all("repr")
|
||||||
check_all("shlex")
|
self.check_all("rexec")
|
||||||
check_all("shutil")
|
self.check_all("rfc822")
|
||||||
check_all("smtpd")
|
self.check_all("robotparser")
|
||||||
check_all("smtplib")
|
self.check_all("sched")
|
||||||
check_all("sndhdr")
|
self.check_all("sets")
|
||||||
check_all("socket")
|
self.check_all("sgmllib")
|
||||||
check_all("sre")
|
self.check_all("shelve")
|
||||||
check_all("stat_cache")
|
self.check_all("shlex")
|
||||||
check_all("tabnanny")
|
self.check_all("shutil")
|
||||||
check_all("telnetlib")
|
self.check_all("smtpd")
|
||||||
check_all("tempfile")
|
self.check_all("smtplib")
|
||||||
check_all("toaiff")
|
self.check_all("sndhdr")
|
||||||
check_all("tokenize")
|
self.check_all("socket")
|
||||||
check_all("traceback")
|
self.check_all("sre")
|
||||||
check_all("tty")
|
self.check_all("statcache")
|
||||||
check_all("urllib")
|
self.check_all("symtable")
|
||||||
check_all("urlparse")
|
self.check_all("tabnanny")
|
||||||
check_all("uu")
|
self.check_all("tarfile")
|
||||||
check_all("warnings")
|
self.check_all("telnetlib")
|
||||||
check_all("wave")
|
self.check_all("tempfile")
|
||||||
check_all("weakref")
|
self.check_all("textwrap")
|
||||||
check_all("webbrowser")
|
self.check_all("threading")
|
||||||
check_all("xdrlib")
|
self.check_all("toaiff")
|
||||||
check_all("zipfile")
|
self.check_all("tokenize")
|
||||||
|
self.check_all("traceback")
|
||||||
|
self.check_all("tty")
|
||||||
|
self.check_all("urllib")
|
||||||
|
self.check_all("urlparse")
|
||||||
|
self.check_all("uu")
|
||||||
|
self.check_all("warnings")
|
||||||
|
self.check_all("wave")
|
||||||
|
self.check_all("weakref")
|
||||||
|
self.check_all("webbrowser")
|
||||||
|
self.check_all("xdrlib")
|
||||||
|
self.check_all("zipfile")
|
||||||
|
|
||||||
# rlcompleter needs special consideration; it import readline which
|
# rlcompleter needs special consideration; it import readline which
|
||||||
# initializes GNU readline which calls setlocale(LC_CTYPE, "")... :-(
|
# initializes GNU readline which calls setlocale(LC_CTYPE, "")... :-(
|
||||||
try:
|
try:
|
||||||
check_all("rlcompleter")
|
self.check_all("rlcompleter")
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
import locale
|
import locale
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
locale.setlocale(locale.LC_CTYPE, 'C')
|
locale.setlocale(locale.LC_CTYPE, 'C')
|
||||||
|
|
||||||
|
|
||||||
|
def test_main():
|
||||||
|
suite = unittest.TestSuite()
|
||||||
|
suite.addTest(unittest.makeSuite(AllTest))
|
||||||
|
test_support.run_suite(suite)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test_main()
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
"""Test script for the grp module."""
|
"""Test script for the grp module."""
|
||||||
|
|
||||||
# XXX This really needs some work, but what are the expected invariants?
|
|
||||||
|
|
||||||
import grp
|
import grp
|
||||||
import unittest
|
import unittest
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
@ -9,19 +7,71 @@ from test import test_support
|
||||||
|
|
||||||
class GroupDatabaseTestCase(unittest.TestCase):
|
class GroupDatabaseTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def test_values(self):
|
||||||
self.groups = grp.getgrall()
|
entries = grp.getgrall()
|
||||||
|
|
||||||
def test_getgrgid(self):
|
for e in entries:
|
||||||
entry = grp.getgrgid(self.groups[0][2])
|
self.assertEqual(len(e), 4)
|
||||||
|
self.assertEqual(e[0], e.gr_name)
|
||||||
|
self.assert_(isinstance(e.gr_name, basestring))
|
||||||
|
self.assertEqual(e[1], e.gr_passwd)
|
||||||
|
self.assert_(isinstance(e.gr_passwd, basestring))
|
||||||
|
self.assertEqual(e[2], e.gr_gid)
|
||||||
|
self.assert_(isinstance(e.gr_gid, int))
|
||||||
|
self.assertEqual(e[3], e.gr_mem)
|
||||||
|
self.assert_(isinstance(e.gr_mem, list))
|
||||||
|
|
||||||
def test_getgrnam(self):
|
self.assertEqual(grp.getgrnam(e.gr_name), e)
|
||||||
entry = grp.getgrnam(self.groups[0][0])
|
self.assertEqual(grp.getgrgid(e.gr_gid), e)
|
||||||
|
|
||||||
|
def test_errors(self):
|
||||||
|
self.assertRaises(TypeError, grp.getgrgid)
|
||||||
|
self.assertRaises(TypeError, grp.getgrnam)
|
||||||
|
self.assertRaises(TypeError, grp.getgrall, 42)
|
||||||
|
|
||||||
|
# try to get some errors
|
||||||
|
bynames = {}
|
||||||
|
bygids = {}
|
||||||
|
for (n, p, g, mem) in grp.getgrall():
|
||||||
|
bynames[n] = g
|
||||||
|
bygids[g] = n
|
||||||
|
|
||||||
|
allnames = bynames.keys()
|
||||||
|
namei = 0
|
||||||
|
fakename = allnames[namei]
|
||||||
|
while fakename in bynames:
|
||||||
|
chars = map(None, fakename)
|
||||||
|
for i in xrange(len(chars)):
|
||||||
|
if chars[i] == 'z':
|
||||||
|
chars[i] = 'A'
|
||||||
|
break
|
||||||
|
elif chars[i] == 'Z':
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
chars[i] = chr(ord(chars[i]) + 1)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
namei = namei + 1
|
||||||
|
try:
|
||||||
|
fakename = allnames[namei]
|
||||||
|
except IndexError:
|
||||||
|
# should never happen... if so, just forget it
|
||||||
|
break
|
||||||
|
fakename = ''.join(map(None, chars))
|
||||||
|
|
||||||
|
self.assertRaises(KeyError, grp.getgrnam, fakename)
|
||||||
|
|
||||||
|
# Choose a non-existent gid.
|
||||||
|
fakegid = 4127
|
||||||
|
while fakegid in bygids:
|
||||||
|
fakegid = (fakegid * 3) % 0x10000
|
||||||
|
|
||||||
|
self.assertRaises(KeyError, grp.getgrgid, fakegid)
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
test_support.run_unittest(GroupDatabaseTestCase)
|
suite = unittest.TestSuite()
|
||||||
|
suite.addTest(unittest.makeSuite(GroupDatabaseTestCase))
|
||||||
|
test_support.run_suite(suite)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
test_main()
|
||||||
|
|
|
@ -1,71 +1,82 @@
|
||||||
from test.test_support import verbose
|
import unittest
|
||||||
|
from test import test_support
|
||||||
|
|
||||||
import pwd
|
import pwd
|
||||||
|
|
||||||
print 'pwd.getpwall()'
|
class PwdTest(unittest.TestCase):
|
||||||
entries = pwd.getpwall()
|
|
||||||
|
|
||||||
for e in entries:
|
def test_values(self):
|
||||||
name = e[0]
|
entries = pwd.getpwall()
|
||||||
uid = e[2]
|
|
||||||
if verbose:
|
|
||||||
print name, uid
|
|
||||||
print 'pwd.getpwuid()'
|
|
||||||
dbuid = pwd.getpwuid(uid)
|
|
||||||
if dbuid[0] != name:
|
|
||||||
print 'Mismatch in pwd.getpwuid()'
|
|
||||||
print 'pwd.getpwnam()'
|
|
||||||
dbname = pwd.getpwnam(name)
|
|
||||||
if dbname[2] != uid:
|
|
||||||
print 'Mismatch in pwd.getpwnam()'
|
|
||||||
else:
|
|
||||||
print 'name matches uid'
|
|
||||||
break
|
|
||||||
|
|
||||||
# try to get some errors
|
for e in entries:
|
||||||
bynames = {}
|
self.assertEqual(len(e), 7)
|
||||||
byuids = {}
|
self.assertEqual(e[0], e.pw_name)
|
||||||
for n, p, u, g, gecos, d, s in entries:
|
self.assert_(isinstance(e.pw_name, basestring))
|
||||||
bynames[n] = u
|
self.assertEqual(e[1], e.pw_passwd)
|
||||||
byuids[u] = n
|
self.assert_(isinstance(e.pw_passwd, basestring))
|
||||||
|
self.assertEqual(e[2], e.pw_uid)
|
||||||
|
self.assert_(isinstance(e.pw_uid, int))
|
||||||
|
self.assertEqual(e[3], e.pw_gid)
|
||||||
|
self.assert_(isinstance(e.pw_gid, int))
|
||||||
|
self.assertEqual(e[4], e.pw_gecos)
|
||||||
|
self.assert_(isinstance(e.pw_gecos, basestring))
|
||||||
|
self.assertEqual(e[5], e.pw_dir)
|
||||||
|
self.assert_(isinstance(e.pw_dir, basestring))
|
||||||
|
self.assertEqual(e[6], e.pw_shell)
|
||||||
|
self.assert_(isinstance(e.pw_shell, basestring))
|
||||||
|
|
||||||
allnames = bynames.keys()
|
self.assertEqual(pwd.getpwnam(e.pw_name), e)
|
||||||
namei = 0
|
self.assertEqual(pwd.getpwuid(e.pw_uid), e)
|
||||||
fakename = allnames[namei]
|
|
||||||
while bynames.has_key(fakename):
|
|
||||||
chars = map(None, fakename)
|
|
||||||
for i in range(len(chars)):
|
|
||||||
if chars[i] == 'z':
|
|
||||||
chars[i] = 'A'
|
|
||||||
break
|
|
||||||
elif chars[i] == 'Z':
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
chars[i] = chr(ord(chars[i]) + 1)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
namei = namei + 1
|
|
||||||
try:
|
|
||||||
fakename = allnames[namei]
|
|
||||||
except IndexError:
|
|
||||||
# should never happen... if so, just forget it
|
|
||||||
break
|
|
||||||
fakename = ''.join(map(None, chars))
|
|
||||||
|
|
||||||
try:
|
def test_errors(self):
|
||||||
pwd.getpwnam(fakename)
|
self.assertRaises(TypeError, pwd.getpwuid)
|
||||||
except KeyError:
|
self.assertRaises(TypeError, pwd.getpwnam)
|
||||||
print 'caught expected exception'
|
self.assertRaises(TypeError, pwd.getpwall, 42)
|
||||||
else:
|
|
||||||
print 'fakename', fakename, 'did not except pwd.getpwnam()'
|
|
||||||
|
|
||||||
# Choose a non-existent uid.
|
# try to get some errors
|
||||||
fakeuid = 4127
|
bynames = {}
|
||||||
while byuids.has_key(fakeuid):
|
byuids = {}
|
||||||
fakeuid = (fakeuid * 3) % 0x10000
|
for (n, p, u, g, gecos, d, s) in pwd.getpwall():
|
||||||
|
bynames[n] = u
|
||||||
|
byuids[u] = n
|
||||||
|
|
||||||
|
allnames = bynames.keys()
|
||||||
|
namei = 0
|
||||||
|
fakename = allnames[namei]
|
||||||
|
while fakename in bynames:
|
||||||
|
chars = map(None, fakename)
|
||||||
|
for i in xrange(len(chars)):
|
||||||
|
if chars[i] == 'z':
|
||||||
|
chars[i] = 'A'
|
||||||
|
break
|
||||||
|
elif chars[i] == 'Z':
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
chars[i] = chr(ord(chars[i]) + 1)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
namei = namei + 1
|
||||||
|
try:
|
||||||
|
fakename = allnames[namei]
|
||||||
|
except IndexError:
|
||||||
|
# should never happen... if so, just forget it
|
||||||
|
break
|
||||||
|
fakename = ''.join(map(None, chars))
|
||||||
|
|
||||||
|
self.assertRaises(KeyError, pwd.getpwnam, fakename)
|
||||||
|
|
||||||
|
# Choose a non-existent uid.
|
||||||
|
fakeuid = 4127
|
||||||
|
while fakeuid in byuids:
|
||||||
|
fakeuid = (fakeuid * 3) % 0x10000
|
||||||
|
|
||||||
|
self.assertRaises(KeyError, pwd.getpwuid, fakeuid)
|
||||||
|
|
||||||
|
def test_main():
|
||||||
|
suite = unittest.TestSuite()
|
||||||
|
suite.addTest(unittest.makeSuite(PwdTest))
|
||||||
|
test_support.run_suite(suite)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test_main()
|
||||||
|
|
||||||
try:
|
|
||||||
pwd.getpwuid(fakeuid)
|
|
||||||
except KeyError:
|
|
||||||
print 'caught expected exception'
|
|
||||||
else:
|
|
||||||
print 'fakeuid', fakeuid, 'did not except pwd.getpwuid()'
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue