diff options
author | Raymond Hettinger <python@rcn.com> | 2003-09-02 05:42:02 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-09-02 05:42:02 (GMT) |
commit | eeca37e0b5a86bc8113f9f51cace145a71c56dd4 (patch) | |
tree | 7fdea651897ba52a430720ab4d11a44e140094dd /Lib | |
parent | 09c7b6075cf51d5438c76a19ad244b663d4cf048 (diff) | |
download | cpython-eeca37e0b5a86bc8113f9f51cace145a71c56dd4.zip cpython-eeca37e0b5a86bc8113f9f51cace145a71c56dd4.tar.gz cpython-eeca37e0b5a86bc8113f9f51cace145a71c56dd4.tar.bz2 |
SF bug #453515: filecmp.dircmp case sensitivity bug
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/filecmp.py | 12 | ||||
-rw-r--r-- | Lib/test/test_filecmp.py | 8 |
2 files changed, 12 insertions, 8 deletions
diff --git a/Lib/filecmp.py b/Lib/filecmp.py index 321ae0c..089c667 100644 --- a/Lib/filecmp.py +++ b/Lib/filecmp.py @@ -12,7 +12,7 @@ Functions: import os import stat import warnings -from itertools import ifilter, ifilterfalse +from itertools import ifilter, ifilterfalse, imap, izip __all__ = ["cmp","dircmp","cmpfiles"] @@ -135,11 +135,11 @@ class dircmp: self.right_list.sort() def phase1(self): # Compute common names - b = dict.fromkeys(self.right_list) - common = dict.fromkeys(ifilter(b.has_key, self.left_list)) - self.left_only = list(ifilterfalse(common.has_key, self.left_list)) - self.right_only = list(ifilterfalse(common.has_key, self.right_list)) - self.common = common.keys() + a = dict(izip(imap(os.path.normcase, self.left_list), self.left_list)) + b = dict(izip(imap(os.path.normcase, self.right_list), self.right_list)) + self.common = map(a.__getitem__, ifilter(b.has_key, a)) + self.left_only = map(a.__getitem__, ifilterfalse(b.has_key, a)) + self.right_only = map(b.__getitem__, ifilterfalse(a.has_key, b)) def phase2(self): # Distinguish files, directories, funnies self.common_dirs = [] diff --git a/Lib/test/test_filecmp.py b/Lib/test/test_filecmp.py index 0e5f297..b433ecc 100644 --- a/Lib/test/test_filecmp.py +++ b/Lib/test/test_filecmp.py @@ -49,7 +49,11 @@ class DirCompareTestCase(unittest.TestCase): data = 'Contents of file go here.\n' for dir in [self.dir, self.dir_same, self.dir_diff]: os.mkdir(dir) - output = open(os.path.join(dir, 'file'), 'w') + if dir is self.dir_same: + fn = 'FiLe' # Verify case-insensitive comparison + else: + fn = 'file' + output = open(os.path.join(dir, fn), 'w') output.write(data) output.close() @@ -93,7 +97,7 @@ class DirCompareTestCase(unittest.TestCase): def test_dircmp(self): # Check attributes for comparison of two identical directories d = filecmp.dircmp(self.dir, self.dir_same) - self.failUnless(d.left_list == d.right_list == ['file']) + self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']]) self.failUnless(d.common == ['file']) self.failUnless(d.left_only == d.right_only == []) self.failUnless(d.same_files == ['file']) |