| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  | # Test the Unicode versions of normal file functions | 
					
						
							|  |  |  | # open, os.open, os.stat. os.listdir, os.rename, os.remove, os.mkdir, os.chdir, os.rmdir | 
					
						
							| 
									
										
										
										
											2003-07-16 03:46:38 +00:00
										 |  |  | import sys, os, unittest | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  | from test import support | 
					
						
							| 
									
										
										
										
											2002-10-08 02:44:31 +00:00
										 |  |  | if not os.path.supports_unicode_filenames: | 
					
						
							| 
									
										
											  
											
												Merged revisions 70554,70588-70589,70598,70605,70611-70621,70623-70624,70626-70627 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
  r70554 | benjamin.peterson | 2009-03-23 16:25:15 -0500 (Mon, 23 Mar 2009) | 1 line
  complain when there's no last exception
........
  r70588 | benjamin.peterson | 2009-03-24 17:56:32 -0500 (Tue, 24 Mar 2009) | 1 line
  fix newline issue in test summary
........
  r70589 | benjamin.peterson | 2009-03-24 18:07:07 -0500 (Tue, 24 Mar 2009) | 1 line
  another style nit
........
  r70598 | benjamin.peterson | 2009-03-25 16:24:04 -0500 (Wed, 25 Mar 2009) | 1 line
  add shorthands for expected failures and unexpected success
........
  r70605 | benjamin.peterson | 2009-03-26 11:32:23 -0500 (Thu, 26 Mar 2009) | 1 line
  remove uneeded function
........
  r70611 | benjamin.peterson | 2009-03-26 13:35:37 -0500 (Thu, 26 Mar 2009) | 1 line
  add much better tests for python version information parsing
........
  r70612 | benjamin.peterson | 2009-03-26 13:55:48 -0500 (Thu, 26 Mar 2009) | 1 line
  more and more implementations now support sys.subversion
........
  r70613 | benjamin.peterson | 2009-03-26 13:58:30 -0500 (Thu, 26 Mar 2009) | 1 line
  roll old test in with new one
........
  r70614 | benjamin.peterson | 2009-03-26 14:09:21 -0500 (Thu, 26 Mar 2009) | 1 line
  add support for PyPy
........
  r70615 | benjamin.peterson | 2009-03-26 14:58:18 -0500 (Thu, 26 Mar 2009) | 5 lines
  add some useful utilities for skipping tests with unittest's new skipping ability
  most significantly apply a modified portion of the patch from #4242 with
  patches for skipping implementation details
........
  r70616 | benjamin.peterson | 2009-03-26 15:05:50 -0500 (Thu, 26 Mar 2009) | 1 line
  rename TestCase.skip() to skipTest() because it causes annoying problems with trial #5571
........
  r70617 | benjamin.peterson | 2009-03-26 15:17:27 -0500 (Thu, 26 Mar 2009) | 1 line
  apply the second part of #4242's patch; classify all the implementation details in test_descr
........
  r70618 | benjamin.peterson | 2009-03-26 15:48:25 -0500 (Thu, 26 Mar 2009) | 1 line
  remove test_support.TestSkipped and just use unittest.SkipTest
........
  r70619 | benjamin.peterson | 2009-03-26 15:49:40 -0500 (Thu, 26 Mar 2009) | 1 line
  fix naming
........
  r70620 | benjamin.peterson | 2009-03-26 16:10:30 -0500 (Thu, 26 Mar 2009) | 1 line
  fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
........
  r70621 | benjamin.peterson | 2009-03-26 16:11:16 -0500 (Thu, 26 Mar 2009) | 1 line
  must pass argument to get expected behavior ;)
........
  r70623 | benjamin.peterson | 2009-03-26 16:30:10 -0500 (Thu, 26 Mar 2009) | 1 line
  add missing import
........
  r70624 | benjamin.peterson | 2009-03-26 16:30:54 -0500 (Thu, 26 Mar 2009) | 1 line
  ** is required here
........
  r70626 | benjamin.peterson | 2009-03-26 16:40:29 -0500 (Thu, 26 Mar 2009) | 1 line
  update email tests to use SkipTest
........
  r70627 | benjamin.peterson | 2009-03-26 16:44:43 -0500 (Thu, 26 Mar 2009) | 1 line
  fix another name
........
											
										 
											2009-03-28 21:42:05 +00:00
										 |  |  |     raise unittest.SkipTest("test works only on NT+") | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | filenames = [ | 
					
						
							| 
									
										
										
										
											2002-10-07 17:27:15 +00:00
										 |  |  |     'abc', | 
					
						
							| 
									
										
										
										
											2007-05-02 19:09:54 +00:00
										 |  |  |     'ascii', | 
					
						
							|  |  |  |     'Gr\xfc\xdf-Gott', | 
					
						
							|  |  |  |     '\u0393\u03b5\u03b9\u03ac-\u03c3\u03b1\u03c2', | 
					
						
							|  |  |  |     '\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435', | 
					
						
							|  |  |  |     '\u306b\u307d\u3093', | 
					
						
							|  |  |  |     '\u05d4\u05e9\u05e7\u05e6\u05e5\u05e1', | 
					
						
							|  |  |  |     '\u66e8\u66e9\u66eb', | 
					
						
							|  |  |  |     '\u66e8\u05e9\u3093\u0434\u0393\xdf', | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-05 17:54:56 +00:00
										 |  |  | # Destroy directory dirname and all files under it, to one level. | 
					
						
							|  |  |  | def deltree(dirname): | 
					
						
							|  |  |  |     # Don't hide legitimate errors:  if one of these suckers exists, it's | 
					
						
							|  |  |  |     # an error if we can't remove it. | 
					
						
							|  |  |  |     if os.path.exists(dirname): | 
					
						
							| 
									
										
										
										
											2002-10-08 02:44:31 +00:00
										 |  |  |         # must pass unicode to os.listdir() so we get back unicode results. | 
					
						
							| 
									
										
										
										
											2007-05-02 19:09:54 +00:00
										 |  |  |         for fname in os.listdir(str(dirname)): | 
					
						
							| 
									
										
										
										
											2002-10-05 17:54:56 +00:00
										 |  |  |             os.unlink(os.path.join(dirname, fname)) | 
					
						
							|  |  |  |         os.rmdir(dirname) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  | class UnicodeFileTests(unittest.TestCase): | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  |     files = [os.path.join(support.TESTFN, f) for f in filenames] | 
					
						
							| 
									
										
										
										
											2002-10-05 17:54:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  |     def setUp(self): | 
					
						
							|  |  |  |         try: | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  |             os.mkdir(support.TESTFN) | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  |         except OSError: | 
					
						
							|  |  |  |             pass | 
					
						
							|  |  |  |         for name in self.files: | 
					
						
							| 
									
										
										
										
											2007-10-26 04:29:23 +00:00
										 |  |  |             f = open(name, 'wb') | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  |             f.write((name+'\n').encode("utf-8")) | 
					
						
							|  |  |  |             f.close() | 
					
						
							|  |  |  |             os.stat(name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def tearDown(self): | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  |         deltree(support.TESTFN) | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _apply_failure(self, fn, filename, expected_exception, | 
					
						
							|  |  |  |                        check_fn_in_exception = True): | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             fn(filename) | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  |             raise support.TestFailed("Expected to fail calling '%s(%r)'" | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  |                              % (fn.__name__, filename)) | 
					
						
							| 
									
										
										
										
											2007-01-10 16:19:56 +00:00
										 |  |  |         except expected_exception as details: | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  |             if check_fn_in_exception and details.filename != filename: | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  |                 raise support.TestFailed("Function '%s(%r) failed with " | 
					
						
							| 
									
										
										
										
											2002-11-09 05:26:15 +00:00
										 |  |  |                                  "bad filename in the exception: %r" | 
					
						
							|  |  |  |                                  % (fn.__name__, filename, | 
					
						
							|  |  |  |                                     details.filename)) | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_failures(self): | 
					
						
							|  |  |  |         # Pass non-existing Unicode filenames all over the place. | 
					
						
							|  |  |  |         for name in self.files: | 
					
						
							|  |  |  |             name = "not_" + name | 
					
						
							|  |  |  |             self._apply_failure(open, name, IOError) | 
					
						
							|  |  |  |             self._apply_failure(os.stat, name, OSError) | 
					
						
							|  |  |  |             self._apply_failure(os.chdir, name, OSError) | 
					
						
							|  |  |  |             self._apply_failure(os.rmdir, name, OSError) | 
					
						
							|  |  |  |             self._apply_failure(os.remove, name, OSError) | 
					
						
							|  |  |  |             # listdir may append a wildcard to the filename, so dont check | 
					
						
							|  |  |  |             self._apply_failure(os.listdir, name, OSError, False) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_open(self): | 
					
						
							|  |  |  |         for name in self.files: | 
					
						
							| 
									
										
										
										
											2007-10-26 04:29:23 +00:00
										 |  |  |             f = open(name, 'wb') | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  |             f.write((name+'\n').encode("utf-8")) | 
					
						
							|  |  |  |             f.close() | 
					
						
							|  |  |  |             os.stat(name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_listdir(self): | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  |         f1 = os.listdir(support.TESTFN) | 
					
						
							|  |  |  |         f2 = os.listdir(str(support.TESTFN.encode("utf-8"), | 
					
						
							| 
									
										
										
										
											2003-07-16 03:46:38 +00:00
										 |  |  |                                 sys.getfilesystemencoding())) | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  |         sf2 = set("\\".join((str(support.TESTFN), f)) | 
					
						
							| 
									
										
											  
											
												Merged revisions 59512-59540 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
  r59513 | raymond.hettinger | 2007-12-15 01:07:25 +0100 (Sat, 15 Dec 2007) | 6 lines
  Optimize PyList_AsTuple(). Improve cache performance by doing the
  pointer copy and object increment in one pass.  For small lists,
  save the overhead of the call to memcpy() -- this comes up in
  calls like f(*listcomp).
........
  r59519 | christian.heimes | 2007-12-15 06:38:35 +0100 (Sat, 15 Dec 2007) | 2 lines
  Fixed #1624: Remove output comparison for test_pep277
  I had to modify Brett's patch slightly.
........
  r59520 | georg.brandl | 2007-12-15 10:34:59 +0100 (Sat, 15 Dec 2007) | 2 lines
  Add note about future import needed for with statement.
........
  r59522 | georg.brandl | 2007-12-15 10:36:37 +0100 (Sat, 15 Dec 2007) | 2 lines
  Argh, wrong version.
........
  r59524 | georg.brandl | 2007-12-16 12:06:09 +0100 (Sun, 16 Dec 2007) | 2 lines
  Dummy commit to investigate #1617.
........
  r59525 | georg.brandl | 2007-12-16 12:21:48 +0100 (Sun, 16 Dec 2007) | 2 lines
  Revert dummy commit now that the build slave is building.
........
  r59527 | georg.brandl | 2007-12-16 16:47:46 +0100 (Sun, 16 Dec 2007) | 2 lines
  Remove orphaned footnote reference.
........
  r59528 | georg.brandl | 2007-12-16 16:53:49 +0100 (Sun, 16 Dec 2007) | 2 lines
  Remove gratuitous unicode character.
........
  r59529 | georg.brandl | 2007-12-16 16:59:19 +0100 (Sun, 16 Dec 2007) | 2 lines
  Remove another unnecessary Unicode character.
........
  r59530 | georg.brandl | 2007-12-16 17:00:36 +0100 (Sun, 16 Dec 2007) | 2 lines
  Remove curious space-like characters.
........
  r59532 | georg.brandl | 2007-12-16 20:36:51 +0100 (Sun, 16 Dec 2007) | 2 lines
  Adapt conf.py to new option names.
........
  r59533 | christian.heimes | 2007-12-16 22:39:43 +0100 (Sun, 16 Dec 2007) | 1 line
  Fixed #1638: %zd configure test fails on Linux
........
  r59536 | georg.brandl | 2007-12-17 00:11:16 +0100 (Mon, 17 Dec 2007) | 2 lines
  Simplify.
........
  r59537 | georg.brandl | 2007-12-17 00:13:29 +0100 (Mon, 17 Dec 2007) | 2 lines
  Use PEP 8.
........
  r59539 | georg.brandl | 2007-12-17 00:15:07 +0100 (Mon, 17 Dec 2007) | 2 lines
  Don't use quotes for non-string code.
........
  r59540 | facundo.batista | 2007-12-17 15:18:42 +0100 (Mon, 17 Dec 2007) | 4 lines
  Removed the private _rounding_decision: it was not needed, and the code
  is now simpler.  Thanks Mark Dickinson.
........
											
										 
											2007-12-17 20:04:13 +00:00
										 |  |  |                   for f in f2) | 
					
						
							|  |  |  |         self.failUnlessEqual(len(f1), len(self.files)) | 
					
						
							|  |  |  |         self.failUnlessEqual(sf2, set(self.files)) | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_rename(self): | 
					
						
							|  |  |  |         for name in self.files: | 
					
						
							|  |  |  |             os.rename(name,"tmp") | 
					
						
							|  |  |  |             os.rename("tmp",name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_directory(self): | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  |         dirname = os.path.join(support.TESTFN,'Gr\xfc\xdf-\u66e8\u66e9\u66eb') | 
					
						
							| 
									
										
										
										
											2007-05-02 19:09:54 +00:00
										 |  |  |         filename = '\xdf-\u66e8\u66e9\u66eb' | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  |         oldwd = os.getcwd() | 
					
						
							|  |  |  |         os.mkdir(dirname) | 
					
						
							|  |  |  |         os.chdir(dirname) | 
					
						
							| 
									
										
										
										
											2007-10-26 04:29:23 +00:00
										 |  |  |         f = open(filename, 'wb') | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  |         f.write((filename + '\n').encode("utf-8")) | 
					
						
							|  |  |  |         f.close() | 
					
						
							| 
									
										
										
										
											2003-09-12 16:25:38 +00:00
										 |  |  |         os.access(filename,os.R_OK) | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  |         os.remove(filename) | 
					
						
							|  |  |  |         os.chdir(oldwd) | 
					
						
							|  |  |  |         os.rmdir(dirname) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_main(): | 
					
						
							| 
									
										
										
										
											2002-10-05 17:54:56 +00:00
										 |  |  |     try: | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  |         support.run_unittest(UnicodeFileTests) | 
					
						
							| 
									
										
										
										
											2002-10-05 17:54:56 +00:00
										 |  |  |     finally: | 
					
						
							| 
									
										
										
										
											2008-05-20 21:35:26 +00:00
										 |  |  |         deltree(support.TESTFN) | 
					
						
							| 
									
										
										
										
											2002-10-03 23:14:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  |     test_main() |