diff options
Diffstat (limited to 'Lib/test/test_unicode_file.py')
| -rw-r--r-- | Lib/test/test_unicode_file.py | 68 |
1 files changed, 43 insertions, 25 deletions
diff --git a/Lib/test/test_unicode_file.py b/Lib/test/test_unicode_file.py index ede1b17..5f0681e 100644 --- a/Lib/test/test_unicode_file.py +++ b/Lib/test/test_unicode_file.py @@ -49,6 +49,22 @@ class TestUnicodeFiles(unittest.TestCase): self.failUnless(base in file_list) + # Do as many "equivalancy' tests as we can - ie, check that although we + # have different types for the filename, they refer to the same file. + def _do_equivalent(self, filename1, filename2): + # Note we only check "filename1 against filename2" - we don't bother + # checking "filename2 against 1", as we assume we are called again with + # the args reversed. + self.failUnless(type(filename1)!=type(filename2), + "No point checking equivalent filenames of the same type") + # stat and lstat should return the same results. + self.failUnlessEqual(os.stat(filename1), + os.stat(filename2)) + self.failUnlessEqual(os.lstat(filename1), + os.lstat(filename2)) + # Copy/rename etc tests using equivalent filename + self._do_copyish(filename1, filename2) + # Tests that copy, move, etc one file to another. def _do_copyish(self, filename1, filename2): # Should be able to rename the file using either name. @@ -58,31 +74,20 @@ class TestUnicodeFiles(unittest.TestCase): os.rename(filename1 + ".new", filename2) self.failUnless(os.path.isfile(filename2)) - # Try using shutil on the filenames. - try: - filename1==filename2 - except UnicodeDecodeError: - # these filenames can't be compared - shutil.copy tries to do - # just that. This is really a bug in 'shutil' - if one of shutil's - # 2 params are Unicode and the other isn't, it should coerce the - # string to Unicode with the filesystem encoding before comparison. - pass - else: - # filenames can be compared. - shutil.copy(filename1, filename2 + ".new") - os.unlink(filename1 + ".new") # remove using equiv name. - # And a couple of moves, one using each name. - shutil.move(filename1, filename2 + ".new") - self.failUnless(not os.path.exists(filename2)) - shutil.move(filename1 + ".new", filename2) - self.failUnless(os.path.exists(filename1)) - # Note - due to the implementation of shutil.move, - # it tries a rename first. This only fails on Windows when on - # different file systems - and this test can't ensure that. - # So we test the shutil.copy2 function, which is the thing most - # likely to fail. - shutil.copy2(filename1, filename2 + ".new") - os.unlink(filename1 + ".new") + shutil.copy(filename1, filename2 + ".new") + os.unlink(filename1 + ".new") # remove using equiv name. + # And a couple of moves, one using each name. + shutil.move(filename1, filename2 + ".new") + self.failUnless(not os.path.exists(filename2)) + shutil.move(filename1 + ".new", filename2) + self.failUnless(os.path.exists(filename1)) + # Note - due to the implementation of shutil.move, + # it tries a rename first. This only fails on Windows when on + # different file systems - and this test can't ensure that. + # So we test the shutil.copy2 function, which is the thing most + # likely to fail. + shutil.copy2(filename1, filename2 + ".new") + os.unlink(filename1 + ".new") def _do_directory(self, make_name, chdir_name, encoded): cwd = os.getcwd() @@ -127,6 +132,16 @@ class TestUnicodeFiles(unittest.TestCase): finally: os.unlink(filename) + def _test_equivalent(self, filename1, filename2): + remove_if_exists(filename1) + self.failUnless(not os.path.exists(filename2)) + f = file(filename1, "w") + f.close() + try: + self._do_equivalent(filename1, filename2) + finally: + os.unlink(filename1) + # The 'test' functions are unittest entry points, and simply call our # _test functions with each of the filename combinations we wish to test def test_single_files(self): @@ -135,6 +150,9 @@ class TestUnicodeFiles(unittest.TestCase): self._test_single(TESTFN_UNICODE_UNENCODEABLE) def test_directories(self): + # For all 'equivalent' combinations: + # Make dir with encoded, chdir with unicode, checkdir with encoded + # (or unicode/encoded/unicode, etc ext = ".dir" self._do_directory(TESTFN_UNICODE+ext, TESTFN_UNICODE+ext, False) # Our directory name that can't use a non-unicode name. |
