diff -r 9328e2b8a397 Lib/test/filecmpdata/fulldirs/dir-diff/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fulldirs/dir-diff/file Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fulldirs/dir-diff/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fulldirs/dir-diff/file2 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r 9328e2b8a397 Lib/test/filecmpdata/fulldirs/dir-diff/subdir-diff/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fulldirs/dir-diff/subdir-diff/file3 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fulldirs/dir-diff/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fulldirs/dir-diff/subdir/file3 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fulldirs/dir-diff/subdir/file4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fulldirs/dir-diff/subdir/file4 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r 9328e2b8a397 Lib/test/filecmpdata/fulldirs/dir-diff/subdir/nested-diff/file5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fulldirs/dir-diff/subdir/nested-diff/file5 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fulldirs/dir-diff/subdir/nested/file5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fulldirs/dir-diff/subdir/nested/file5 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fulldirs/dir-diff/subdir/nested/file6 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fulldirs/dir-diff/subdir/nested/file6 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r 9328e2b8a397 Lib/test/filecmpdata/fulldirs/dir/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fulldirs/dir/file Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fulldirs/dir/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fulldirs/dir/subdir/file3 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fulldirs/dir/subdir/nested/file5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fulldirs/dir/subdir/nested/file5 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fullfiles/dir-diff/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fullfiles/dir-diff/file Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fullfiles/dir-diff/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fullfiles/dir-diff/file2 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r 9328e2b8a397 Lib/test/filecmpdata/fullfiles/dir-diff/subdir-diff/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fullfiles/dir-diff/subdir-diff/file3 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fullfiles/dir-diff/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fullfiles/dir-diff/subdir/file3 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fullfiles/dir-diff/subdir/file4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fullfiles/dir-diff/subdir/file4 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r 9328e2b8a397 Lib/test/filecmpdata/fullfiles/dir-diff/subdir/nested-diff/file5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fullfiles/dir-diff/subdir/nested-diff/file5 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fullfiles/dir-diff/subdir/nested/file5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fullfiles/dir-diff/subdir/nested/file5 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fullfiles/dir-diff/subdir/nested/file6 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fullfiles/dir-diff/subdir/nested/file6 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r 9328e2b8a397 Lib/test/filecmpdata/fullfiles/dir/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fullfiles/dir/file Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fullfiles/dir/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fullfiles/dir/subdir/file3 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fullfiles/dir/subdir/nested/file5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fullfiles/dir/subdir/nested/file5 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/fullfiles/dir/subdir/nested/file6 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/fullfiles/dir/subdir/nested/file6 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Different contents. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialdirs/dir-diff/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialdirs/dir-diff/file Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialdirs/dir-diff/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialdirs/dir-diff/file2 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialdirs/dir-diff/subdir-diff/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialdirs/dir-diff/subdir-diff/file3 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialdirs/dir-diff/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialdirs/dir-diff/subdir/file3 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialdirs/dir-diff/subdir/file4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialdirs/dir-diff/subdir/file4 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialdirs/dir/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialdirs/dir/file Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialdirs/dir/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialdirs/dir/subdir/file3 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialfiles/dir-diff/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialfiles/dir-diff/file Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialfiles/dir-diff/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialfiles/dir-diff/file2 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialfiles/dir-diff/subdir-diff/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialfiles/dir-diff/subdir-diff/file3 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialfiles/dir-diff/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialfiles/dir-diff/subdir/file3 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialfiles/dir-diff/subdir/file4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialfiles/dir-diff/subdir/file4 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialfiles/dir/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialfiles/dir/file Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialfiles/dir/subdir/file3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialfiles/dir/subdir/file3 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/partialfiles/dir/subdir/file4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/partialfiles/dir/subdir/file4 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Different contents. diff -r 9328e2b8a397 Lib/test/filecmpdata/reportdirs/dir-diff/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/reportdirs/dir-diff/file Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/reportdirs/dir-diff/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/reportdirs/dir-diff/file2 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r 9328e2b8a397 Lib/test/filecmpdata/reportdirs/dir/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/reportdirs/dir/file Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/reportfiles/dir-diff/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/reportfiles/dir-diff/file Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/reportfiles/dir-diff/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/reportfiles/dir-diff/file2 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +An extra file. diff -r 9328e2b8a397 Lib/test/filecmpdata/reportfiles/dir/file --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/reportfiles/dir/file Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Contents of file go here. diff -r 9328e2b8a397 Lib/test/filecmpdata/reportfiles/dir/file2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/filecmpdata/reportfiles/dir/file2 Tue Apr 09 18:37:18 2013 -0400 @@ -0,0 +1,1 @@ +Different contents. diff -r 9328e2b8a397 Lib/test/test_filecmp.py --- a/Lib/test/test_filecmp.py Tue Apr 02 22:13:49 2013 +0200 +++ b/Lib/test/test_filecmp.py Tue Apr 09 18:37:18 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,539 @@ self.assertEqual(d.diff_files, ['file2']) +class BaseReportTestCase(unittest.TestCase): + """Common attributes for report test cases.""" + + TESTDATADIR = 'filecmpdata' + + REPORTDIRS = 'reportdirs' + REPORTFILES = 'reportfiles' + PARTIALDIRS = 'partialdirs' + PARTIALFILES = 'partialfiles' + FULLDIRS = 'fulldirs' + FULLFILES = 'fullfiles' + + DIR = 'dir' + DIRSAME = 'dir-same' + DIRDIFF = 'dir-diff' + SUBDIR = 'subdir' + SUBDIRDIFF = 'subdir-diff' + NESTED = 'nested' + NESTEDDIFF = 'nested-diff' + + DIRFILE = 'file' + DIREXTRAFILE = 'file2' + SUBDIRFILE = 'file3' + SUBDIREXTRAFILE = 'file4' + NESTEDFILE = 'file5' + NESTEDEXTRAFILE = 'file6' + + test_data_path = os.path.join(os.path.dirname(support.__file__), + TESTDATADIR) + + report_dirs_path = os.path.join(test_data_path, REPORTDIRS) + report_files_path = os.path.join(test_data_path, REPORTFILES) + partial_dirs_path = os.path.join(test_data_path, PARTIALDIRS) + partial_files_path = os.path.join(test_data_path, PARTIALFILES) + full_dirs_path = os.path.join(test_data_path, FULLDIRS) + full_files_path = os.path.join(test_data_path, FULLFILES) + + dir_subdir = os.path.join(DIR, SUBDIR) + dir_same_subdir = os.path.join(DIRSAME, SUBDIR) + dir_diff_subdir = os.path.join(DIRDIFF, SUBDIR) + dir_diff_subdir_diff = os.path.join(DIRDIFF, SUBDIRDIFF) + + dir_subdir_nested = os.path.join(dir_subdir, NESTED) + dir_same_subdir_nested = os.path.join(dir_same_subdir, NESTED) + dir_diff_subdir_nested = os.path.join(dir_diff_subdir, NESTED) + dir_diff_subdir_nested_diff = os.path.join(dir_diff_subdir, NESTEDDIFF) + + +class ReportTestCase(BaseReportTestCase): + """ + Test reports in directory. + """ + + def setUp(self): + """Set up reports expected by tests.""" + + self.report_same = "\n".join(( + "diff {0.DIR} {0.DIRSAME}", + "Identical files : ['{0.DIRFILE}']", + "",)).format(self) + self.report_diff_dirs = "\n".join(( + "diff {0.DIR} {0.DIRDIFF}", + "Only in {0.DIRDIFF} : ['{0.DIREXTRAFILE}']", + "Identical files : ['{0.DIRFILE}']", + "",)).format(self) + self.report_diff_files = "\n".join(( + "diff {0.DIR} {0.DIRDIFF}", + "Identical files : ['{0.DIRFILE}']", + "Differing files : ['{0.DIREXTRAFILE}']", + "",)).format(self) + + def test_report_same(self): + """Test report with two identical directories.""" + + with support.temp_cwd(path=self.report_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRSAME) + 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.""" + + with support.temp_cwd(path=self.report_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.report_files_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.report_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRSAME) + 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.""" + + with support.temp_cwd(path=self.report_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.report_files_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.report_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRSAME) + 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.""" + + with support.temp_cwd(path=self.report_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.report_files_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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 setUp(self): + """Set up reports expected by tests.""" + + self.report_same = "\n".join(( + "diff {0.DIR} {0.DIRSAME}", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "",)).format(self) + self.report_diff_dirs = "\n".join(( + "diff {0.DIR} {0.DIRDIFF}", + "Only in {0.DIRDIFF} : ['{0.DIREXTRAFILE}', '{0.SUBDIRDIFF}']", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "",)).format(self) + self.report_diff_files = "\n".join(( + "diff {0.DIR} {0.DIRDIFF}", + "Only in {0.DIRDIFF} : ['{0.DIREXTRAFILE}', '{0.SUBDIRDIFF}']", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "",)).format(self) + self.partial_report_same = "\n".join(( + "diff {0.DIR} {0.DIRSAME}", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dir_subdir} {0.dir_same_subdir}", + "Identical files : ['{0.SUBDIRFILE}']", + "",)).format(self) + self.partial_report_diff_dirs = "\n".join(( + "diff {0.DIR} {0.DIRDIFF}", + "Only in {0.DIRDIFF} : ['{0.DIREXTRAFILE}', '{0.SUBDIRDIFF}']", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dir_subdir} {0.dir_diff_subdir}", + "Only in {0.dir_diff_subdir} : ['{0.SUBDIREXTRAFILE}']", + "Identical files : ['{0.SUBDIRFILE}']", + "",)).format(self) + self.partial_report_diff_files = "\n".join(( + "diff {0} {1}".format(self.DIR, self.DIRDIFF), + "Only in {0.DIRDIFF} : ['{0.DIREXTRAFILE}', '{0.SUBDIRDIFF}']", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dir_subdir} {0.dir_diff_subdir}", + "Identical files : ['{0.SUBDIRFILE}']", + "Differing files : ['{0.SUBDIREXTRAFILE}']", + "",)).format(self) + + def test_report_same(self): + """Test report with two identical subdirectories.""" + + with support.temp_cwd(path=self.partial_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRSAME) + 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.""" + + with support.temp_cwd(path=self.partial_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.partial_files_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.partial_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRSAME) + 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.""" + + with support.temp_cwd(path=self.partial_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.partial_files_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.partial_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRSAME) + 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.""" + + with support.temp_cwd(path=self.partial_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.partial_files_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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 setUp(self): + """Set up reports expected by tests.""" + + self.report_same = "\n".join(( + "diff {0.DIR} {0.DIRSAME}", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "",)).format(self) + self.report_diff_dirs = "\n".join(( + "diff {0.DIR} {0.DIRDIFF}", + "Only in {0.DIRDIFF} : ['{0.DIREXTRAFILE}', '{0.SUBDIRDIFF}']", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "",)).format(self) + self.report_diff_files = "\n".join(( + "diff {0.DIR} {0.DIRDIFF}", + "Only in {0.DIRDIFF} : ['{0.DIREXTRAFILE}', '{0.SUBDIRDIFF}']", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "",)).format(self) + self.partial_report_same = "\n".join(( + "diff {0.DIR} {0.DIRSAME}", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dir_subdir} {0.dir_same_subdir}", + "Identical files : ['{0.SUBDIRFILE}']", + "Common subdirectories : ['{0.NESTED}']", + "",)).format(self) + self.partial_report_diff_dirs = "\n".join(( + "diff {0.DIR} {0.DIRDIFF}", + "Only in {0.DIRDIFF} : ['{0.DIREXTRAFILE}', '{0.SUBDIRDIFF}']", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dir_subdir} {0.dir_diff_subdir}", + "Only in {0.dir_diff_subdir} : ['{0.SUBDIREXTRAFILE}', " + "'{0.NESTEDDIFF}']", + "Identical files : ['{0.SUBDIRFILE}']", + "Common subdirectories : ['{0.NESTED}']", + "",)).format(self) + self.partial_report_diff_files = "\n".join(( + "diff {0} {1}".format(self.DIR, self.DIRDIFF), + "Only in {0.DIRDIFF} : ['{0.DIREXTRAFILE}', '{0.SUBDIRDIFF}']", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dir_subdir} {0.dir_diff_subdir}", + "Only in {0.dir_diff_subdir} : ['{0.SUBDIREXTRAFILE}', " + "'{0.NESTEDDIFF}']", + "Identical files : ['{0.SUBDIRFILE}']", + "Common subdirectories : ['{0.NESTED}']", + "",)).format(self) + self.full_report_same = "\n".join(( + "diff {0.DIR} {0.DIRSAME}", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dir_subdir} {0.dir_same_subdir}", + "Identical files : ['{0.SUBDIRFILE}']", + "Common subdirectories : ['{0.NESTED}']", + "", + "diff {0.dir_subdir_nested} {0.dir_same_subdir_nested}", + "Identical files : ['{0.NESTEDFILE}']", + "",)).format(self) + self.full_report_diff_dirs = "\n".join(( + "diff {0.DIR} {0.DIRDIFF}", + "Only in {0.DIRDIFF} : ['{0.DIREXTRAFILE}', '{0.SUBDIRDIFF}']", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dir_subdir} {0.dir_diff_subdir}", + "Only in {0.dir_diff_subdir} : ['{0.SUBDIREXTRAFILE}', " + "'{0.NESTEDDIFF}']", + "Identical files : ['{0.SUBDIRFILE}']", + "Common subdirectories : ['{0.NESTED}']", + "", + "diff {0.dir_subdir_nested} {0.dir_diff_subdir_nested}", + "Only in {0.dir_diff_subdir_nested} : ['{0.NESTEDEXTRAFILE}']", + "Identical files : ['{0.NESTEDFILE}']", + "",)).format(self) + self.full_report_diff_files = "\n".join(( + "diff {0.DIR} {0.DIRDIFF}", + "Only in {0.DIRDIFF} : ['{0.DIREXTRAFILE}', '{0.SUBDIRDIFF}']", + "Identical files : ['{0.DIRFILE}']", + "Common subdirectories : ['{0.SUBDIR}']", + "", + "diff {0.dir_subdir} {0.dir_diff_subdir}", + "Only in {0.dir_diff_subdir} : ['{0.SUBDIREXTRAFILE}', " + "'{0.NESTEDDIFF}']", + "Identical files : ['{0.SUBDIRFILE}']", + "Common subdirectories : ['{0.NESTED}']", + "", + "diff {0.dir_subdir_nested} {0.dir_diff_subdir_nested}", + "Identical files : ['{0.NESTEDFILE}']", + "Differing files : ['{0.NESTEDEXTRAFILE}']", + "",)).format(self) + + def test_report_same(self): + """Test report with two identical nested subdirectories.""" + + with support.temp_cwd(path=self.full_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRSAME) + 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.""" + + with support.temp_cwd(path=self.full_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.full_files_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.full_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRSAME) + 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.""" + + with support.temp_cwd(path=self.full_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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. + """ + + with support.temp_cwd(path=self.full_files_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.full_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRSAME) + 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.""" + + with support.temp_cwd(path=self.full_dirs_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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.""" + + with support.temp_cwd(path=self.full_files_path) as t: + d = filecmp.dircmp(self.DIR, self.DIRDIFF) + 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()