| 
									
										
										
										
											2010-03-18 00:23:44 +00:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  | import unittest | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  | from test import support | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 70734,70775,70856,70874,70876-70877 via svnmerge
........
  r70734 | r.david.murray | 2009-03-30 15:04:00 -0400 (Mon, 30 Mar 2009) | 7 lines
  Add import_function method to test.test_support, and modify a number of
  tests that expect to be skipped if imports fail or functions don't
  exist to use import_function and import_module.  The ultimate goal is
  to change regrtest to not skip automatically on ImportError.  Checking
  in now to make sure the buldbots don't show any errors on platforms
  I can't direct test on.
........
  r70775 | r.david.murray | 2009-03-30 19:05:48 -0400 (Mon, 30 Mar 2009) | 4 lines
  Change more tests to use import_module for the modules that
  should cause tests to be skipped.  Also rename import_function
  to the more descriptive get_attribute and add a docstring.
........
  r70856 | r.david.murray | 2009-03-31 14:32:17 -0400 (Tue, 31 Mar 2009) | 7 lines
  A few more test skips via import_module, and change import_module to
  return the error message produced by importlib, so that if an import
  in the package whose import is being wrapped is what failed the skip
  message will contain the name of that module instead of the name of the
  wrapped module.  Also fixed formatting of some previous comments.
........
  r70874 | r.david.murray | 2009-03-31 15:33:15 -0400 (Tue, 31 Mar 2009) | 5 lines
  Improve test_support.import_module docstring, remove
  deprecated flag from get_attribute since it isn't likely
  to do anything useful.
........
  r70876 | r.david.murray | 2009-03-31 15:49:15 -0400 (Tue, 31 Mar 2009) | 4 lines
  Remove the regrtest check that turns any ImportError into a skipped test.
  Hopefully all modules whose imports legitimately result in a skipped
  test have been properly wrapped by the previous commits.
........
  r70877 | r.david.murray | 2009-03-31 15:57:24 -0400 (Tue, 31 Mar 2009) | 2 lines
  Add NEWS entry for regrtest change.
........
											
										 
											2009-03-31 23:16:50 +00:00
										 |  |  | pwd = support.import_module('pwd') | 
					
						
							| 
									
										
										
										
											1996-12-11 16:53:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  | class PwdTest(unittest.TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_values(self): | 
					
						
							|  |  |  |         entries = pwd.getpwall() | 
					
						
							| 
									
										
										
										
											2003-04-22 11:05:57 +00:00
										 |  |  |         entriesbyname = {} | 
					
						
							| 
									
										
										
										
											2003-04-15 15:39:08 +00:00
										 |  |  |         entriesbyuid = {} | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for e in entries: | 
					
						
							|  |  |  |             self.assertEqual(len(e), 7) | 
					
						
							|  |  |  |             self.assertEqual(e[0], e.pw_name) | 
					
						
							| 
									
										
										
										
											2010-01-24 19:26:24 +00:00
										 |  |  |             self.assertIsInstance(e.pw_name, str) | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  |             self.assertEqual(e[1], e.pw_passwd) | 
					
						
							| 
									
										
										
										
											2010-01-24 19:26:24 +00:00
										 |  |  |             self.assertIsInstance(e.pw_passwd, str) | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  |             self.assertEqual(e[2], e.pw_uid) | 
					
						
							| 
									
										
										
										
											2010-01-24 19:26:24 +00:00
										 |  |  |             self.assertIsInstance(e.pw_uid, int) | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  |             self.assertEqual(e[3], e.pw_gid) | 
					
						
							| 
									
										
										
										
											2010-01-24 19:26:24 +00:00
										 |  |  |             self.assertIsInstance(e.pw_gid, int) | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  |             self.assertEqual(e[4], e.pw_gecos) | 
					
						
							| 
									
										
										
										
											2010-01-24 19:26:24 +00:00
										 |  |  |             self.assertIsInstance(e.pw_gecos, str) | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  |             self.assertEqual(e[5], e.pw_dir) | 
					
						
							| 
									
										
										
										
											2010-01-24 19:26:24 +00:00
										 |  |  |             self.assertIsInstance(e.pw_dir, str) | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  |             self.assertEqual(e[6], e.pw_shell) | 
					
						
							| 
									
										
										
										
											2010-01-24 19:26:24 +00:00
										 |  |  |             self.assertIsInstance(e.pw_shell, str) | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-15 15:39:08 +00:00
										 |  |  |             # The following won't work, because of duplicate entries | 
					
						
							|  |  |  |             # for one uid | 
					
						
							|  |  |  |             #    self.assertEqual(pwd.getpwuid(e.pw_uid), e) | 
					
						
							|  |  |  |             # instead of this collect all entries for one uid | 
					
						
							|  |  |  |             # and check afterwards | 
					
						
							| 
									
										
										
										
											2003-04-22 11:05:57 +00:00
										 |  |  |             entriesbyname.setdefault(e.pw_name, []).append(e) | 
					
						
							| 
									
										
										
										
											2003-04-15 15:39:08 +00:00
										 |  |  |             entriesbyuid.setdefault(e.pw_uid, []).append(e) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 60176-60209 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
  r60178 | georg.brandl | 2008-01-21 22:05:49 +0100 (Mon, 21 Jan 2008) | 2 lines
  #1715: include sub-extension modules in pydoc text output.
........
  r60179 | georg.brandl | 2008-01-21 22:14:21 +0100 (Mon, 21 Jan 2008) | 2 lines
  Add a "const" to make gcc happy.
........
  r60180 | georg.brandl | 2008-01-21 22:19:07 +0100 (Mon, 21 Jan 2008) | 2 lines
  Add the correct build dir when building with pydebug.
........
  r60181 | georg.brandl | 2008-01-21 22:23:15 +0100 (Mon, 21 Jan 2008) | 3 lines
  Patch #1720595: add T_BOOL to the range of structmember types.
  Patch by Angelo Mottola, reviewed by MvL, tests by me.
........
  r60182 | georg.brandl | 2008-01-21 22:28:32 +0100 (Mon, 21 Jan 2008) | 2 lines
  Reformat some ugly code.
........
  r60187 | brett.cannon | 2008-01-22 00:50:16 +0100 (Tue, 22 Jan 2008) | 4 lines
  Make's MAKEFLAGS variable is set to a string containing the single-letter
  arguments to Make. This means there are no hyphens. Fix the '-s' check to
  silence distutils to now work.
........
  r60188 | gregory.p.smith | 2008-01-22 01:19:41 +0100 (Tue, 22 Jan 2008) | 3 lines
  accepts and closes issue #1221598: adds an optional callback to ftplib.FTP
  storbinary() and storlines() methods.
........
  r60189 | gregory.p.smith | 2008-01-22 02:12:02 +0100 (Tue, 22 Jan 2008) | 2 lines
  Replace spam.acquire() try: ... finally: spam.release() with "with spam:"
........
  r60190 | gregory.p.smith | 2008-01-22 02:20:42 +0100 (Tue, 22 Jan 2008) | 4 lines
  - Fix Issue #1703448: A joined thread could show up in the
    threading.enumerate() list after the join() for a brief period until
    it actually exited.
........
  r60193 | georg.brandl | 2008-01-22 08:53:31 +0100 (Tue, 22 Jan 2008) | 2 lines
  Fix \xhh specs, #1889.
........
  r60198 | christian.heimes | 2008-01-22 16:01:25 +0100 (Tue, 22 Jan 2008) | 1 line
  Fixed a missing (X) in define
........
  r60199 | christian.heimes | 2008-01-22 16:25:18 +0100 (Tue, 22 Jan 2008) | 2 lines
  Don't repeat yourself
  Added the macros PyModule_AddIntMacro and PyModule_AddStringMacro. They shorten PyModule_AddIntConstant(m, "AF_INET", AF_INET) to PyModule_AddIntMacro(m, AF_INET)
........
  r60201 | raymond.hettinger | 2008-01-22 20:51:41 +0100 (Tue, 22 Jan 2008) | 1 line
  Document when to use izip_longest().
........
  r60202 | georg.brandl | 2008-01-22 20:56:03 +0100 (Tue, 22 Jan 2008) | 2 lines
  Fix for #1087741 patch.
........
  r60203 | raymond.hettinger | 2008-01-22 21:18:53 +0100 (Tue, 22 Jan 2008) | 1 line
  Give zip() the same guarantee as izip() for left-to-right evaluation.
........
  r60204 | raymond.hettinger | 2008-01-22 23:09:26 +0100 (Tue, 22 Jan 2008) | 1 line
  Improve variable name in sample code
........
  r60205 | gregory.p.smith | 2008-01-23 00:15:34 +0100 (Wed, 23 Jan 2008) | 2 lines
  docstring and comment updates suggested by Giampaolo Rodola'
........
  r60207 | raymond.hettinger | 2008-01-23 01:04:40 +0100 (Wed, 23 Jan 2008) | 1 line
  Let pprint() support sets and frozensets (suggested by David Mertz).
........
  r60208 | guido.van.rossum | 2008-01-23 02:18:27 +0100 (Wed, 23 Jan 2008) | 4 lines
  I'm tired of these tests breaking at Google due to our large number of
  users and groups in LDAP/NIS.  So I'm limiting the extra-heavy part of
  the tests to passwd/group files with at most 1000 entries.
........
											
										 
											2008-01-23 08:24:23 +00:00
										 |  |  |         if len(entries) > 1000:  # Huge passwd file (NIS?) -- skip the rest | 
					
						
							|  |  |  |             return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-15 15:39:08 +00:00
										 |  |  |         # check whether the entry returned by getpwuid() | 
					
						
							|  |  |  |         # for each uid is among those from getpwall() for this uid | 
					
						
							|  |  |  |         for e in entries: | 
					
						
							| 
									
										
										
										
											2005-12-12 20:53:40 +00:00
										 |  |  |             if not e[0] or e[0] == '+': | 
					
						
							|  |  |  |                 continue # skip NIS entries etc. | 
					
						
							| 
									
										
										
										
											2010-01-19 00:09:57 +00:00
										 |  |  |             self.assertIn(pwd.getpwnam(e.pw_name), entriesbyname[e.pw_name]) | 
					
						
							|  |  |  |             self.assertIn(pwd.getpwuid(e.pw_uid), entriesbyuid[e.pw_uid]) | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_errors(self): | 
					
						
							|  |  |  |         self.assertRaises(TypeError, pwd.getpwuid) | 
					
						
							|  |  |  |         self.assertRaises(TypeError, pwd.getpwnam) | 
					
						
							|  |  |  |         self.assertRaises(TypeError, pwd.getpwall, 42) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # try to get some errors | 
					
						
							|  |  |  |         bynames = {} | 
					
						
							|  |  |  |         byuids = {} | 
					
						
							|  |  |  |         for (n, p, u, g, gecos, d, s) in pwd.getpwall(): | 
					
						
							|  |  |  |             bynames[n] = u | 
					
						
							|  |  |  |             byuids[u] = n | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-11 18:54:18 +00:00
										 |  |  |         allnames = list(bynames.keys()) | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  |         namei = 0 | 
					
						
							|  |  |  |         fakename = allnames[namei] | 
					
						
							|  |  |  |         while fakename in bynames: | 
					
						
							| 
									
										
											  
											
												Merged revisions 56125-56153 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
........
  r56127 | georg.brandl | 2007-06-30 09:32:49 +0200 (Sat, 30 Jun 2007) | 2 lines
  Fix a place where floor division would be in order.
........
  r56135 | guido.van.rossum | 2007-07-01 06:13:54 +0200 (Sun, 01 Jul 2007) | 28 lines
  Make map() and filter() identical to itertools.imap() and .ifilter(),
  respectively.
  I fixed two bootstrap issues, due to the dynamic import of itertools:
  1. Starting python requires that map() and filter() are not used until
     site.py has added build/lib.<arch> to sys.path.
  2. Building python requires that setup.py and distutils and everything
     they use is free of map() and filter() calls.
  Beyond this, I only fixed the tests in test_builtin.py.
  Others, please help fixing the remaining tests that are now broken!
  The fixes are usually simple:
  a. map(None, X) -> list(X)
  b. map(F, X) -> list(map(F, X))
  c. map(lambda x: F(x), X) -> [F(x) for x in X]
  d. filter(F, X) -> list(filter(F, X))
  e. filter(lambda x: P(x), X) -> [x for x in X if P(x)]
  Someone, please also contribute a fixer for 2to3 to do this.
  It can leave map()/filter() calls alone that are already
  inside a list() or sorted() call or for-loop.
  Only in rare cases have I seen code that depends on map() of lists
  of different lengths going to the end of the longest, or on filter()
  of a string or tuple returning an object of the same type; these
  will need more thought to fix.
........
  r56136 | guido.van.rossum | 2007-07-01 06:22:01 +0200 (Sun, 01 Jul 2007) | 3 lines
  Make it so that test_decimal fails instead of hangs, to help automated
  test runners.
........
  r56139 | georg.brandl | 2007-07-01 18:20:58 +0200 (Sun, 01 Jul 2007) | 2 lines
  Fix a few test cases after the map->imap change.
........
  r56142 | neal.norwitz | 2007-07-02 06:38:12 +0200 (Mon, 02 Jul 2007) | 1 line
  Get a bunch more tests passing after converting map/filter to return iterators.
........
  r56147 | guido.van.rossum | 2007-07-02 15:32:02 +0200 (Mon, 02 Jul 2007) | 4 lines
  Fix the remaining failing unit tests (at least on OSX).
  Also tweaked urllib2 so it doesn't raise socket.gaierror when
  all network interfaces are turned off.
........
											
										 
											2007-07-03 08:25:58 +00:00
										 |  |  |             chars = list(fakename) | 
					
						
							| 
									
										
										
										
											2007-05-07 22:24:25 +00:00
										 |  |  |             for i in range(len(chars)): | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  |                 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 | 
					
						
							| 
									
										
											  
											
												Merged revisions 56125-56153 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
........
  r56127 | georg.brandl | 2007-06-30 09:32:49 +0200 (Sat, 30 Jun 2007) | 2 lines
  Fix a place where floor division would be in order.
........
  r56135 | guido.van.rossum | 2007-07-01 06:13:54 +0200 (Sun, 01 Jul 2007) | 28 lines
  Make map() and filter() identical to itertools.imap() and .ifilter(),
  respectively.
  I fixed two bootstrap issues, due to the dynamic import of itertools:
  1. Starting python requires that map() and filter() are not used until
     site.py has added build/lib.<arch> to sys.path.
  2. Building python requires that setup.py and distutils and everything
     they use is free of map() and filter() calls.
  Beyond this, I only fixed the tests in test_builtin.py.
  Others, please help fixing the remaining tests that are now broken!
  The fixes are usually simple:
  a. map(None, X) -> list(X)
  b. map(F, X) -> list(map(F, X))
  c. map(lambda x: F(x), X) -> [F(x) for x in X]
  d. filter(F, X) -> list(filter(F, X))
  e. filter(lambda x: P(x), X) -> [x for x in X if P(x)]
  Someone, please also contribute a fixer for 2to3 to do this.
  It can leave map()/filter() calls alone that are already
  inside a list() or sorted() call or for-loop.
  Only in rare cases have I seen code that depends on map() of lists
  of different lengths going to the end of the longest, or on filter()
  of a string or tuple returning an object of the same type; these
  will need more thought to fix.
........
  r56136 | guido.van.rossum | 2007-07-01 06:22:01 +0200 (Sun, 01 Jul 2007) | 3 lines
  Make it so that test_decimal fails instead of hangs, to help automated
  test runners.
........
  r56139 | georg.brandl | 2007-07-01 18:20:58 +0200 (Sun, 01 Jul 2007) | 2 lines
  Fix a few test cases after the map->imap change.
........
  r56142 | neal.norwitz | 2007-07-02 06:38:12 +0200 (Mon, 02 Jul 2007) | 1 line
  Get a bunch more tests passing after converting map/filter to return iterators.
........
  r56147 | guido.van.rossum | 2007-07-02 15:32:02 +0200 (Mon, 02 Jul 2007) | 4 lines
  Fix the remaining failing unit tests (at least on OSX).
  Also tweaked urllib2 so it doesn't raise socket.gaierror when
  all network interfaces are turned off.
........
											
										 
											2007-07-03 08:25:58 +00:00
										 |  |  |             fakename = ''.join(chars) | 
					
						
							| 
									
										
										
										
											1996-12-11 16:53:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  |         self.assertRaises(KeyError, pwd.getpwnam, fakename) | 
					
						
							| 
									
										
										
										
											1996-12-11 16:53:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-18 00:23:44 +00:00
										 |  |  |         # 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) | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  |         self.assertRaises(KeyError, pwd.getpwuid, fakeuid) | 
					
						
							| 
									
										
										
										
											2000-10-23 17:22:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  | def test_main(): | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  |     support.run_unittest(PwdTest) | 
					
						
							| 
									
										
										
										
											1996-12-11 16:53:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-15 11:10:33 +00:00
										 |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  |     test_main() |