Index: test_filecmp.py =================================================================== --- test_filecmp.py (revision 84904) +++ test_filecmp.py (working copy) @@ -1,5 +1,5 @@ -import os, filecmp, shutil, tempfile +import os, filecmp, shutil, tempfile, fnmatch import unittest from test import support @@ -52,10 +52,21 @@ shutil.rmtree(dir, True) os.mkdir(dir) if self.caseinsensitive and dir is self.dir_same: - fn = 'FiLe' # Verify case-insensitive comparison + fn1 = 'FiLe' # Verify case-insensitive comparison + fn2 = fn1 + '.TMP' + dir_ign = os.path.join(dir, 'Dir-Ignore') else: - fn = 'file' - output = open(os.path.join(dir, fn), 'w') + fn1 = 'file' + fn2 = fn1 + '.tmp' + dir_ign = os.path.join(dir, 'dir-ignore') + os.mkdir(dir_ign) + for dn in [dir, dir_ign]: + for fn in [fn1, fn2]: + output = open(os.path.join(dn, fn), 'w') + output.write(data) + output.close() + output = open(os.path.join(dir_ign, os.path.basename(dir) + + '.ign'), 'w') output.write(data) output.close() @@ -95,10 +106,44 @@ (['file'], ['file2'], []), "Comparing mismatched directories fails") + def test_dircmp_default(self): + # Check attributes for comparison of two identical directories + ignore = ['dir-ignore', 'file.tmp'] + d = filecmp.dircmp(self.dir, self.dir_same, ignore=ignore) + if self.caseinsensitive: + self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']]) + else: + 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']) + self.failUnless(d.diff_files == []) - def test_dircmp(self): + # Check attributes for comparison of two different directories + d = filecmp.dircmp(self.dir, self.dir_diff, ignore=ignore, + match=fnmatch.fnmatch) + self.failUnless(d.left_list == ['file']) + self.failUnless(d.right_list == ['file', 'file2']) + self.failUnless(d.common == ['file']) + self.failUnless(d.left_only == []) + self.failUnless(d.right_only == ['file2']) + self.failUnless(d.same_files == ['file']) + self.failUnless(d.diff_files == []) + + # Add different file2 + output = open(os.path.join(self.dir, 'file2'), 'w') + output.write('Different contents.\n') + output.close() + d = filecmp.dircmp(self.dir, self.dir_diff, ignore=ignore, + match=fnmatch.fnmatch) + self.failUnless(d.same_files == ['file']) + self.failUnless(d.diff_files == ['file2']) + + def test_dircmp_fnmatch(self): # Check attributes for comparison of two identical directories - d = filecmp.dircmp(self.dir, self.dir_same) + ignore = ['*ignore*', '*.tmp'] + d = filecmp.dircmp(self.dir, self.dir_same, ignore=ignore, + match=fnmatch.fnmatch) if self.caseinsensitive: self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']]) else: