diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir-diff/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir-diff/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir-diff/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir-diff/file2 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir-diff/subdir-diff/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir-diff/subdir-diff/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir-diff/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir-diff/subdir/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir-diff/subdir/file4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir-diff/subdir/file4 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir-diff/subdir/nested-diff/file5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir-diff/subdir/nested-diff/file5 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir-diff/subdir/nested/file5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir-diff/subdir/nested/file5 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir-diff/subdir/nested/file6 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir-diff/subdir/nested/file6 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir-same/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir-same/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir-same/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir-same/subdir/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir-same/subdir/nested/file5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir-same/subdir/nested/file5 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir/subdir/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-dirs/dir/subdir/nested/file5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-dirs/dir/subdir/nested/file5 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-files/dir-diff/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-files/dir-diff/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-files/dir-diff/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-files/dir-diff/file2 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-files/dir-diff/subdir-diff/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-files/dir-diff/subdir-diff/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-files/dir-diff/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-files/dir-diff/subdir/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-files/dir-diff/subdir/file4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-files/dir-diff/subdir/file4 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-files/dir-diff/subdir/nested-diff/file5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-files/dir-diff/subdir/nested-diff/file5 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-files/dir-diff/subdir/nested/file5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-files/dir-diff/subdir/nested/file5 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-files/dir-diff/subdir/nested/file6 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-files/dir-diff/subdir/nested/file6 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-files/dir/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-files/dir/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-files/dir/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-files/dir/subdir/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-files/dir/subdir/nested/file5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-files/dir/subdir/nested/file5 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/full-files/dir/subdir/nested/file6 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/full-files/dir/subdir/nested/file6 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Different contents. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-dirs/dir-diff/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-dirs/dir-diff/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-dirs/dir-diff/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-dirs/dir-diff/file2 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-dirs/dir-diff/subdir-diff/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-dirs/dir-diff/subdir-diff/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-dirs/dir-diff/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-dirs/dir-diff/subdir/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-dirs/dir-diff/subdir/file4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-dirs/dir-diff/subdir/file4 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-dirs/dir-same/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-dirs/dir-same/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-dirs/dir-same/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-dirs/dir-same/subdir/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-dirs/dir/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-dirs/dir/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-dirs/dir/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-dirs/dir/subdir/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-files/dir-diff/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-files/dir-diff/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-files/dir-diff/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-files/dir-diff/file2 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-files/dir-diff/subdir-diff/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-files/dir-diff/subdir-diff/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-files/dir-diff/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-files/dir-diff/subdir/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-files/dir-diff/subdir/file4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-files/dir-diff/subdir/file4 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-files/dir/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-files/dir/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-files/dir/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-files/dir/subdir/file3 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/partial-files/dir/subdir/file4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partial-files/dir/subdir/file4 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Different contents. diff -r e0c0bcd60033 Lib/test/filecmpdata/report-dirs/dir-diff/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/report-dirs/dir-diff/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/report-dirs/dir-diff/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/report-dirs/dir-diff/file2 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r e0c0bcd60033 Lib/test/filecmpdata/report-dirs/dir-same/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/report-dirs/dir-same/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/report-dirs/dir/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/report-dirs/dir/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/report-files/dir-diff/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/report-files/dir-diff/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/report-files/dir-diff/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/report-files/dir-diff/file2 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r e0c0bcd60033 Lib/test/filecmpdata/report-files/dir/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/report-files/dir/file Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r e0c0bcd60033 Lib/test/filecmpdata/report-files/dir/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/report-files/dir/file2 Sat Apr 27 21:39:41 2013 -0400 @@ -0,0 +1,1 @@ +Different contents. diff -r e0c0bcd60033 Lib/test/test_filecmp.py --- a/Lib/test/test_filecmp.py Tue Apr 23 13:48:29 2013 +0200 +++ b/Lib/test/test_filecmp.py Sat Apr 27 21:39:41 2013 -0400 @@ -1,7 +1,11 @@ -import os, filecmp, shutil, tempfile +import os +import filecmp +import shutil +import tempfile import unittest from test import support + class FileCompareTestCase(unittest.TestCase): def setUp(self): self.name = support.TESTFN @@ -35,9 +39,10 @@ def test_different(self): self.assertFalse(filecmp.cmp(self.name, self.name_diff), - "Mismatched files compare as equal") + "Mismatched files compare as equal") self.assertFalse(filecmp.cmp(self.name, self.dir), - "File and directory compare as equal") + "File and directory compare as equal") + class DirCompareTestCase(unittest.TestCase): def setUp(self): @@ -97,10 +102,9 @@ output.close() self.assertFalse(filecmp.cmpfiles(self.dir, self.dir_same, - ['file', 'file2']) == - (['file'], ['file2'], []), - "Comparing mismatched directories fails") - + ['file', 'file2']) == + (['file'], ['file2'], []), + "Comparing mismatched directories fails") def test_dircmp(self): # Check attributes for comparison of two identical directories @@ -109,9 +113,9 @@ self.assertEqual(d.left, left_dir) self.assertEqual(d.right, right_dir) if self.caseinsensitive: - self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']]) + self.assertEqual([d.left_list, d.right_list], [['file'], ['FiLe']]) else: - self.assertEqual([d.left_list, d.right_list],[['file'], ['file']]) + self.assertEqual([d.left_list, d.right_list], [['file'], ['file']]) self.assertEqual(d.common, ['file']) self.assertTrue(d.left_only == d.right_only == []) self.assertEqual(d.same_files, ['file']) @@ -139,8 +143,567 @@ self.assertEqual(d.diff_files, ['file2']) +class BaseReportTestCase(unittest.TestCase): + """Common attributes for report test cases.""" + + TEST_DATA = 'filecmpdata' + + REPORT_DIRS = 'report-dirs' + REPORT_FILES = 'report-files' + PARTIAL_DIRS = 'partial-dirs' + PARTIAL_FILES = 'partial-files' + FULL_DIRS = 'full-dirs' + FULL_FILES = 'full-files' + + DIR = 'dir' + SAME = 'dir-same' + DIFF = 'dir-diff' + SUBDIR = 'subdir' + SDIFF = 'subdir-diff' + NESTED = 'nested' + NDIFF = 'nested-diff' + + FILE = 'file' + EXTRA = 'file2' + SFILE = 'file3' + SEXTRA = 'file4' + NFILE = 'file5' + NEXTRA = 'file6' + + test_data = support.findfile(TEST_DATA) + + report_dir = os.path.join(test_data, REPORT_DIRS) + report_files = os.path.join(test_data, REPORT_FILES) + partial_dir = os.path.join(test_data, PARTIAL_DIRS) + partial_files = os.path.join(test_data, PARTIAL_FILES) + full_dir = os.path.join(test_data, FULL_DIRS) + full_files = os.path.join(test_data, FULL_FILES) + + dir_subdir = os.path.join(DIR, SUBDIR) + same_subdir = os.path.join(SAME, SUBDIR) + diff_subdir = os.path.join(DIFF, SUBDIR) + + dir_nested = os.path.join(dir_subdir, NESTED) + same_nested = os.path.join(same_subdir, NESTED) + diff_nested = os.path.join(diff_subdir, NESTED) + + def setUpPaths(self): + """ + Set up paths required for complete test coverage. + + Implemented in subclasses. + """ + + pass + + def setUpReports(self): + """ + Set up reports expected by tests. + + Implemented in subclasses. + """ + + pass + + def setUp(self): + self.setUpPaths() + self.setUpReports() + + +class ReportTestCase(BaseReportTestCase): + """ + Test reports in directory. + """ + + def setUpPaths(self): + """Set up paths required for complete test coverage.""" + + self.dirs_dir = os.path.join(self.report_dir, self.DIR) + self.dirs_same = os.path.join(self.report_dir, self.SAME) + self.dirs_diff = os.path.join(self.report_dir, self.DIFF) + self.files_dir = os.path.join(self.report_files, self.DIR) + self.files_diff = os.path.join(self.report_files, self.DIFF) + + def setUpReports(self): + """Set up reports expected by tests.""" + + self.report_same = "\n".join(( + "diff {0.dirs_dir} {0.dirs_same}", + "Identical files : ['{0.FILE}']", + "",)).format(self) + self.report_diff_dirs = "\n".join(( + "diff {0.dirs_dir} {0.dirs_diff}", + "Only in {0.dirs_diff} : ['{0.EXTRA}']", + "Identical files : ['{0.FILE}']", + "",)).format(self) + self.report_diff_files = "\n".join(( + "diff {0.files_dir} {0.files_diff}", + "Identical files : ['{0.FILE}']", + "Differing files : ['{0.EXTRA}']", + "",)).format(self) + + def test_report_same(self): + """Test report with two identical directories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_same) + with support.captured_stdout() as r: + d.report() + self.assertEqual(r.getvalue(), self.report_same, + "Comparing identical directories fails.") + + def test_report_different_dirs(self): + """Test report with different directories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_diff) + with support.captured_stdout() as r: + d.report() + self.assertEqual(r.getvalue(), self.report_diff_dirs, + "Comparing different directories fails.") + + def test_report_different_files(self): + """Test report with different files in directories.""" + + d = filecmp.dircmp(self.files_dir, self.files_diff) + with support.captured_stdout() as r: + d.report() + self.assertEqual(r.getvalue(), self.report_diff_files, + "Comparing different files in directories fails.") + + def test_partial_report_same(self): + """Test partial report with two identical directories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_same) + with support.captured_stdout() as r: + d.report_partial_closure() + self.assertEqual(r.getvalue(), self.report_same, + "Partially comparing identical directories fails.") + + def test_partial_report_different_dirs(self): + """Test partial report with different directories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_diff) + with support.captured_stdout() as r: + d.report_partial_closure() + self.assertEqual(r.getvalue(), self.report_diff_dirs, + "Partially comparing different directories fails.") + + def test_partial_report_different_files(self): + """Test partial report with different files in directories.""" + + d = filecmp.dircmp(self.files_dir, self.files_diff) + with support.captured_stdout() as r: + d.report_partial_closure() + self.assertEqual( + r.getvalue(), self.report_diff_files, + "Partially comparing different files in directories fails.") + + def test_full_report_same(self): + """Test full report with two identical directories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_same) + with support.captured_stdout() as r: + d.report_full_closure() + self.assertEqual(r.getvalue(), self.report_same, + "Fully comparing identical directories fails.") + + def test_full_report_different_dirs(self): + """Test full report with different directories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_diff) + with support.captured_stdout() as r: + d.report_full_closure() + self.assertEqual(r.getvalue(), self.report_diff_dirs, + "Fully comparing different directories fails.") + + def test_full_report_different_files(self): + """Test full report with different files in directories.""" + + d = filecmp.dircmp(self.files_dir, self.files_diff) + with support.captured_stdout() as r: + d.report_full_closure() + self.assertEqual( + r.getvalue(), self.report_diff_files, + "Fully comparing different files in directories fails.") + + +class PartialReportTestCase(BaseReportTestCase): + """ + Test reports in subdirectory. + """ + + def setUpPaths(self): + """Set up paths required for complete test coverage.""" + + self.dirs_dir = os.path.join(self.partial_dir, self.DIR) + self.dirs_same = os.path.join(self.partial_dir, self.SAME) + self.dirs_diff = os.path.join(self.partial_dir, self.DIFF) + self.files_dir = os.path.join(self.partial_files, self.DIR) + self.files_diff = os.path.join(self.partial_files, self.DIFF) + + self.dirs_dir_subdir = os.path.join(self.partial_dir, self.dir_subdir) + self.dirs_same_subdir = os.path.join(self.partial_dir, + self.same_subdir) + self.dirs_diff_subdir = os.path.join(self.partial_dir, + self.diff_subdir) + self.files_dir_subdir = os.path.join(self.partial_files, + self.dir_subdir) + self.files_diff_subdir = os.path.join(self.partial_files, + self.diff_subdir) + + def setUpReports(self): + """Set up reports expected by tests.""" + + self.report_same = "\n".join(( + "diff {0.dirs_dir} {0.dirs_same}", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "",)).format(self) + self.report_diff_dirs = "\n".join(( + "diff {0.dirs_dir} {0.dirs_diff}", + "Only in {0.dirs_diff} : ['{0.EXTRA}', '{0.SDIFF}']", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "",)).format(self) + self.report_diff_files = "\n".join(( + "diff {0.files_dir} {0.files_diff}", + "Only in {0.files_diff} : ['{0.EXTRA}', '{0.SDIFF}']", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "",)).format(self) + self.partial_report_same = "\n".join(( + "diff {0.dirs_dir} {0.dirs_same}", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dirs_dir_subdir} {0.dirs_same_subdir}", + "Identical files : ['{0.SFILE}']", + "",)).format(self) + self.partial_report_diff_dirs = "\n".join(( + "diff {0.dirs_dir} {0.dirs_diff}", + "Only in {0.dirs_diff} : ['{0.EXTRA}', '{0.SDIFF}']", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dirs_dir_subdir} {0.dirs_diff_subdir}", + "Only in {0.dirs_diff_subdir} : ['{0.SEXTRA}']", + "Identical files : ['{0.SFILE}']", + "",)).format(self) + self.partial_report_diff_files = "\n".join(( + "diff {0.files_dir} {0.files_diff}", + "Only in {0.files_diff} : ['{0.EXTRA}', '{0.SDIFF}']", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.files_dir_subdir} {0.files_diff_subdir}", + "Identical files : ['{0.SFILE}']", + "Differing files : ['{0.SEXTRA}']", + "",)).format(self) + + def test_report_same(self): + """Test report with two identical subdirectories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_same) + with support.captured_stdout() as r: + d.report() + self.assertEqual(r.getvalue(), self.report_same, + "Comparing identical subdirectories fails.") + + def test_report_different_dirs(self): + """Test report with different subdirectories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_diff) + with support.captured_stdout() as r: + d.report() + self.assertEqual(r.getvalue(), self.report_diff_dirs, + "Comparing different subdirectories fails.") + + def test_report_different_files(self): + """Test report with different files in subdirectories.""" + + d = filecmp.dircmp(self.files_dir, self.files_diff) + with support.captured_stdout() as r: + d.report() + self.assertEqual(r.getvalue(), self.report_diff_files, + "Comparing different files in subdirectories fails.") + + def test_partial_report_same(self): + """Test partial report with two identical subdirectories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_same) + with support.captured_stdout() as r: + d.report_partial_closure() + self.assertEqual(r.getvalue(), self.partial_report_same, + "Partially comparing identical subdirectories fails.") + + def test_partial_report_different_dirs(self): + """Test partial report with different subdirectories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_diff) + with support.captured_stdout() as r: + d.report_partial_closure() + self.assertEqual(r.getvalue(), self.partial_report_diff_dirs, + "Partially comparing different subdirectories fails.") + + def test_partial_report_different_files(self): + """Test partial report with different files in subdirectories.""" + + d = filecmp.dircmp(self.files_dir, self.files_diff) + with support.captured_stdout() as r: + d.report_partial_closure() + self.assertEqual( + r.getvalue(), self.partial_report_diff_files, + "Partially comparing different files in subdirectories fails.") + + def test_full_report_same(self): + """Test full report with two identical subdirectories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_same) + with support.captured_stdout() as r: + d.report_full_closure() + self.assertEqual(r.getvalue(), self.partial_report_same, + "Fully comparing identical subdirectories fails.") + + def test_full_report_different_dirs(self): + """Test full report with different subdirectories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_diff) + with support.captured_stdout() as r: + d.report_full_closure() + self.assertEqual(r.getvalue(), self.partial_report_diff_dirs, + "Fully comparing different subdirectories fails.") + + def test_full_report_different_files(self): + """Test full report with different files in subdirectories.""" + + d = filecmp.dircmp(self.files_dir, self.files_diff) + with support.captured_stdout() as r: + d.report_full_closure() + self.assertEqual( + r.getvalue(), self.partial_report_diff_files, + "Fully comparing different files in subdirectories fails.") + + +class FullReportTestCase(BaseReportTestCase): + """ + Test reports in nested subdirectory. + """ + + def setUpPaths(self): + """Set up paths required for complete test coverage.""" + + self.dirs_dir = os.path.join(self.full_dir, self.DIR) + self.dirs_same = os.path.join(self.full_dir, self.SAME) + self.dirs_diff = os.path.join(self.full_dir, self.DIFF) + self.files_dir = os.path.join(self.full_files, self.DIR) + self.files_diff = os.path.join(self.full_files, self.DIFF) + + self.dirs_dir_subdir = os.path.join(self.full_dir, self.dir_subdir) + self.dirs_same_subdir = os.path.join(self.full_dir, self.same_subdir) + self.dirs_diff_subdir = os.path.join(self.full_dir, self.diff_subdir) + self.files_dir_subdir = os.path.join(self.full_files, self.dir_subdir) + self.files_diff_subdir = os.path.join(self.full_files, + self.diff_subdir) + + self.dirs_dir_nested = os.path.join(self.full_dir, self.dir_nested) + self.dirs_same_nested = os.path.join(self.full_dir, self.same_nested) + self.dirs_diff_nested = os.path.join(self.full_dir, self.diff_nested) + self.files_dir_nested = os.path.join(self.full_files, self.dir_nested) + self.files_diff_nested = os.path.join(self.full_files, + self.diff_nested) + + def setUpReports(self): + """Set up reports expected by tests.""" + + self.report_same = "\n".join(( + "diff {0.dirs_dir} {0.dirs_same}", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "",)).format(self) + self.report_diff_dirs = "\n".join(( + "diff {0.dirs_dir} {0.dirs_diff}", + "Only in {0.dirs_diff} : ['{0.EXTRA}', '{0.SDIFF}']", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "",)).format(self) + self.report_diff_files = "\n".join(( + "diff {0.files_dir} {0.files_diff}", + "Only in {0.files_diff} : ['{0.EXTRA}', '{0.SDIFF}']", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "",)).format(self) + self.partial_report_same = "\n".join(( + "diff {0.dirs_dir} {0.dirs_same}", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dirs_dir_subdir} {0.dirs_same_subdir}", + "Identical files : ['{0.SFILE}']", + "Common subdirectories : ['{0.NESTED}']", + "",)).format(self) + self.partial_report_diff_dirs = "\n".join(( + "diff {0.dirs_dir} {0.dirs_diff}", + "Only in {0.dirs_diff} : ['{0.EXTRA}', '{0.SDIFF}']", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dirs_dir_subdir} {0.dirs_diff_subdir}", + "Only in {0.dirs_diff_subdir} : ['{0.SEXTRA}', '{0.NDIFF}']", + "Identical files : ['{0.SFILE}']", + "Common subdirectories : ['{0.NESTED}']", + "",)).format(self) + self.partial_report_diff_files = "\n".join(( + "diff {0.files_dir} {0.files_diff}", + "Only in {0.files_diff} : ['{0.EXTRA}', '{0.SDIFF}']", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.files_dir_subdir} {0.files_diff_subdir}", + "Only in {0.files_diff_subdir} : ['{0.SEXTRA}', '{0.NDIFF}']", + "Identical files : ['{0.SFILE}']", + "Common subdirectories : ['{0.NESTED}']", + "",)).format(self) + self.full_report_same = "\n".join(( + "diff {0.dirs_dir} {0.dirs_same}", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dirs_dir_subdir} {0.dirs_same_subdir}", + "Identical files : ['{0.SFILE}']", + "Common subdirectories : ['{0.NESTED}']", + "", + "diff {0.dirs_dir_nested} {0.dirs_same_nested}", + "Identical files : ['{0.NFILE}']", + "",)).format(self) + self.full_report_diff_dirs = "\n".join(( + "diff {0.dirs_dir} {0.dirs_diff}", + "Only in {0.dirs_diff} : ['{0.EXTRA}', '{0.SDIFF}']", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dirs_dir_subdir} {0.dirs_diff_subdir}", + "Only in {0.dirs_diff_subdir} : ['{0.SEXTRA}', '{0.NDIFF}']", + "Identical files : ['{0.SFILE}']", + "Common subdirectories : ['{0.NESTED}']", + "", + "diff {0.dirs_dir_nested} {0.dirs_diff_nested}", + "Only in {0.dirs_diff_nested} : ['{0.NEXTRA}']", + "Identical files : ['{0.NFILE}']", + "",)).format(self) + self.full_report_diff_files = "\n".join(( + "diff {0.files_dir} {0.files_diff}", + "Only in {0.files_diff} : ['{0.EXTRA}', '{0.SDIFF}']", + "Identical files : ['{0.FILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.files_dir_subdir} {0.files_diff_subdir}", + "Only in {0.files_diff_subdir} : ['{0.SEXTRA}', '{0.NDIFF}']", + "Identical files : ['{0.SFILE}']", + "Common subdirectories : ['{0.NESTED}']", + "", + "diff {0.files_dir_nested} {0.files_diff_nested}", + "Identical files : ['{0.NFILE}']", + "Differing files : ['{0.NEXTRA}']", + "",)).format(self) + + def test_report_same(self): + """Test report with two identical nested subdirectories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_same) + with support.captured_stdout() as r: + d.report() + self.assertEqual(r.getvalue(), self.report_same, + "Comparing identical nested subdirectories fails.") + + def test_report_different_dirs(self): + """Test report with different nested subdirectories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_diff) + with support.captured_stdout() as r: + d.report() + self.assertEqual(r.getvalue(), self.report_diff_dirs, + "Comparing different nested subdirectories fails.") + + def test_report_different_files(self): + """Test report with different files in nested subdirectories.""" + + d = filecmp.dircmp(self.files_dir, self.files_diff) + with support.captured_stdout() as r: + d.report() + self.assertEqual( + r.getvalue(), self.report_diff_files, + "Comparing different files in nested subdirectories fails.") + + def test_partial_report_same(self): + """Test partial report with two identical nested subdirectories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_same) + with support.captured_stdout() as r: + d.report_partial_closure() + self.assertEqual( + r.getvalue(), self.partial_report_same, + "Partially comparing identical nested subdirectories fails.") + + def test_partial_report_different_dirs(self): + """Test partial report with different nested subdirectories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_diff) + with support.captured_stdout() as r: + d.report_partial_closure() + self.assertEqual( + r.getvalue(), self.partial_report_diff_dirs, + "Partially comparing different nested subdirectories fails.") + + def test_partial_report_different_files(self): + """ + Test partial report with different files in nested subdirectories. + """ + + d = filecmp.dircmp(self.files_dir, self.files_diff) + with support.captured_stdout() as r: + d.report_partial_closure() + self.assertEqual( + r.getvalue(), self.partial_report_diff_files, + "Partially comparing different files in " + "nested subdirectories fails.") + + def test_full_report_same(self): + """Test full report with two identical nested subdirectories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_same) + with support.captured_stdout() as r: + d.report_full_closure() + self.assertEqual( + r.getvalue(), self.full_report_same, + "Fully comparing identical nested subdirectories fails.") + + def test_full_report_different_dirs(self): + """Test full report with different nested subdirectories.""" + + d = filecmp.dircmp(self.dirs_dir, self.dirs_diff) + with support.captured_stdout() as r: + d.report_full_closure() + self.assertEqual( + r.getvalue(), self.full_report_diff_dirs, + "Fully comparing different nested subdirectories fails.") + + def test_full_report_different_files(self): + """Test full report with different files in nested subdirectories.""" + + d = filecmp.dircmp(self.files_dir, self.files_diff) + with support.captured_stdout() as r: + d.report_full_closure() + self.assertEqual( + r.getvalue(), self.full_report_diff_files, + "Fully comparing different files in " + "nested subdirectories fails.") + + def test_main(): - support.run_unittest(FileCompareTestCase, DirCompareTestCase) + support.run_unittest(FileCompareTestCase, + DirCompareTestCase, + ReportTestCase, + PartialReportTestCase, + FullReportTestCase) if __name__ == "__main__": test_main()