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 00:17:34 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,663 @@ self.assertEqual(d.diff_files, ['file2']) +class BaseReportTestCase(unittest.TestCase): + """Common methods for report test cases.""" + + def setUpDirectories(self): + """ + Set up directories and files for report tests. + """ + + self.tmpdir = tempfile.gettempdir() + self.dir = 'dir' + self.dir_same = 'dir-same' + self.dir_diff = 'dir-diff' + self.dir_path = os.path.join(self.tmpdir, self.dir) + self.dir_same_path = os.path.join(self.tmpdir, self.dir_same) + self.dir_diff_path = os.path.join(self.tmpdir, self.dir_diff) + + # Another dir is created under dir_same, but it has a name from the + # ignored list so it should not affect testing results. + self.dir_ignored_path = os.path.join(self.dir_same_path, '.hg') + + self.caseinsensitive = os.path.normcase('A') == os.path.normcase('a') + self.data = 'Contents of file go here.\n' + self.extra = 'An extra file.\n' + self.different = 'Different contents.\n' + self.dir_file = 'file' + for path in (self.dir_path, + self.dir_same_path, + self.dir_diff_path, + self.dir_ignored_path): + shutil.rmtree(path, True) + os.mkdir(path) + if self.caseinsensitive and path is self.dir_same_path: + # Verify case-insensitive comparison + fn = self.dir_file.swapcase() + else: + fn = self.dir_file + with open(os.path.join(path, fn), 'w') as output: + output.write(self.data) + + self.dir_extra_file = 'file2' + with open(os.path.join(self.dir_diff_path, + self.dir_extra_file), 'w') as output: + output.write(self.extra) + + def setUpSubdirectories(self): + """ + Set up subdirectories and files for partial report tests. + """ + + self.setUpDirectories() + self.subdir = 'subdir' + self.subdir_diff = 'subdir-diff' + self.dir_subdir = os.path.join(self.dir, self.subdir) + self.dir_same_subdir = os.path.join(self.dir_same, self.subdir) + self.dir_diff_subdir = os.path.join(self.dir_diff, self.subdir) + self.dir_diff_subdir_diff = os.path.join(self.dir_diff, + self.subdir_diff) + self.dir_subdir_path = os.path.join(self.tmpdir, self.dir_subdir) + self.dir_same_subdir_path = os.path.join(self.tmpdir, + self.dir_same_subdir) + self.dir_diff_subdir_path = os.path.join(self.tmpdir, + self.dir_diff_subdir) + self.dir_diff_subdir_diff_path = \ + os.path.join(self.tmpdir, self.dir_diff_subdir_diff) + self.subdir_file = 'file3' + for path in [self.dir_subdir_path, + self.dir_same_subdir_path, + self.dir_diff_subdir_path, + self.dir_diff_subdir_diff_path]: + os.mkdir(path) + if self.caseinsensitive and path is self.dir_same_subdir_path: + # Verify case-insensitive comparison + fn = self.subdir_file.swapcase() + else: + fn = self.subdir_file + with open(os.path.join(path, fn), 'w') as output: + output.write(self.data) + + self.subdir_extra_file = 'file4' + with open(os.path.join(self.dir_diff_subdir_path, + self.subdir_extra_file), 'w') as output: + output.write(self.extra) + + def setUpNestedSubdirectories(self): + """ + Set up nested subdirectories and files for full report tests. + """ + + self.setUpSubdirectories() + self.nested = 'nested' + self.nested_diff = 'nested-diff' + self.dir_subdir_nested = os.path.join(self.dir_subdir, self.nested) + self.dir_same_subdir_nested = os.path.join(self.dir_same_subdir, + self.nested) + self.dir_diff_subdir_nested = os.path.join(self.dir_diff_subdir, + self.nested) + self.dir_diff_subdir_nested_diff = os.path.join(self.dir_diff_subdir, + self.nested_diff) + self.dir_subdir_nested_path = os.path.join(self.tmpdir, + self.dir_subdir_nested) + self.dir_same_subdir_nested_path = os.path.join( + self.tmpdir, + self.dir_same_subdir_nested) + self.dir_diff_subdir_nested_path = os.path.join( + self.tmpdir, + self.dir_diff_subdir_nested) + self.dir_diff_subdir_nested_diff_path = \ + os.path.join(self.tmpdir, self.dir_diff_subdir_nested_diff) + self.nested_file = 'file5' + for path in [self.dir_subdir_nested_path, + self.dir_same_subdir_nested_path, + self.dir_diff_subdir_nested_path, + self.dir_diff_subdir_nested_diff_path]: + os.mkdir(path) + if self.caseinsensitive and \ + path is self.dir_same_subdir_nested_path: + # Verify case-insensitive comparison + fn = self.nested_file.swapcase() + else: + fn = self.nested_file + with open(os.path.join(path, fn), 'w') as output: + output.write(self.data) + + self.nested_extra_file = 'file6' + with open(os.path.join(self.dir_diff_subdir_nested_path, + self.nested_extra_file), 'w') as output: + output.write(self.extra) + + def tearDown(self): + for dir in (self.dir_path, self.dir_same_path, self.dir_diff_path): + shutil.rmtree(dir) + + +class ReportTestCase(BaseReportTestCase): + """ + Test reports in directory. + """ + + def setUpReports(self): + """Set up reports expected by tests.""" + + self.report_same = "\n".join(( + "diff {0.dir} {0.dir_same}", + "Identical files : ['{0.dir_file}']", + "",)).format(self) + self.report_diff_dirs = "\n".join(( + "diff {0.dir} {0.dir_diff}", + "Only in {0.dir_diff} : ['{0.dir_extra_file}']", + "Identical files : ['{0.dir_file}']", + "",)).format(self) + self.report_diff_files = "\n".join(( + "diff {0.dir} {0.dir_diff}", + "Identical files : ['{0.dir_file}']", + "Differing files : ['{0.dir_extra_file}']", + "",)).format(self) + + def setUp(self): + self.setUpDirectories() + self.setUpReports() + + def test_report_same(self): + """Test report with two identical directories.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + with open(os.path.join(self.dir, + self.dir_extra_file), 'w') as output: + output.write(self.different) + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + with open(os.path.join(self.dir, + self.dir_extra_file), 'w') as output: + output.write(self.different) + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + with open(os.path.join(self.dir, + self.dir_extra_file), 'w') as output: + output.write(self.different) + d = filecmp.dircmp(self.dir, self.dir_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 setUpPartialReports(self): + """Set up reports expected by tests.""" + + self.report_same = "\n".join(( + "diff {0.dir} {0.dir_same}", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "",)).format(self) + self.report_diff_dirs = "\n".join(( + "diff {0.dir} {0.dir_diff}", + "Only in {0.dir_diff} : ['{0.dir_extra_file}', '{0.subdir_diff}']", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "",)).format(self) + self.report_diff_files = "\n".join(( + "diff {0.dir} {0.dir_diff}", + "Only in {0.dir_diff} : ['{0.dir_extra_file}', '{0.subdir_diff}']", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "",)).format(self) + self.partial_report_same = "\n".join(( + "diff {0.dir} {0.dir_same}", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "", + "diff {0.dir_subdir} {0.dir_same_subdir}", + "Identical files : ['{0.subdir_file}']", + "",)).format(self) + self.partial_report_diff_dirs = "\n".join(( + "diff {0.dir} {0.dir_diff}", + "Only in {0.dir_diff} : ['{0.dir_extra_file}', '{0.subdir_diff}']", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "", + "diff {0.dir_subdir} {0.dir_diff_subdir}", + "Only in {0.dir_diff_subdir} : ['{0.subdir_extra_file}']", + "Identical files : ['{0.subdir_file}']", + "",)).format(self) + self.partial_report_diff_files = "\n".join(( + "diff {0} {1}".format(self.dir, self.dir_diff), + "Only in {0.dir_diff} : ['{0.dir_extra_file}', '{0.subdir_diff}']", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "", + "diff {0.dir_subdir} {0.dir_diff_subdir}", + "Identical files : ['{0.subdir_file}']", + "Differing files : ['{0.subdir_extra_file}']", + "",)).format(self) + + def setUp(self): + self.setUpSubdirectories() + self.setUpPartialReports() + + def test_report_same(self): + """Test report with two identical subdirectories.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + with open(os.path.join(self.dir_subdir, + self.subdir_extra_file), 'w') as output: + output.write(self.different) + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + with open(os.path.join(self.dir_subdir, + self.subdir_extra_file), 'w') as output: + output.write(self.different) + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + with open(os.path.join(self.dir_subdir, + self.subdir_extra_file), 'w') as output: + output.write(self.different) + d = filecmp.dircmp(self.dir, self.dir_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 setUpFullReports(self): + """Set up reports expected by tests.""" + + self.report_same = "\n".join(( + "diff {0.dir} {0.dir_same}", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "",)).format(self) + self.report_diff_dirs = "\n".join(( + "diff {0.dir} {0.dir_diff}", + "Only in {0.dir_diff} : ['{0.dir_extra_file}', '{0.subdir_diff}']", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "",)).format(self) + self.report_diff_files = "\n".join(( + "diff {0.dir} {0.dir_diff}", + "Only in {0.dir_diff} : ['{0.dir_extra_file}', '{0.subdir_diff}']", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "",)).format(self) + self.partial_report_same = "\n".join(( + "diff {0.dir} {0.dir_same}", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "", + "diff {0.dir_subdir} {0.dir_same_subdir}", + "Identical files : ['{0.subdir_file}']", + "Common subdirectories : ['{0.nested}']", + "",)).format(self) + self.partial_report_diff_dirs = "\n".join(( + "diff {0.dir} {0.dir_diff}", + "Only in {0.dir_diff} : ['{0.dir_extra_file}', '{0.subdir_diff}']", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "", + "diff {0.dir_subdir} {0.dir_diff_subdir}", + "Only in {0.dir_diff_subdir} : ['{0.subdir_extra_file}', " + "'{0.nested_diff}']", + "Identical files : ['{0.subdir_file}']", + "Common subdirectories : ['{0.nested}']", + "",)).format(self) + self.partial_report_diff_files = "\n".join(( + "diff {0} {1}".format(self.dir, self.dir_diff), + "Only in {0.dir_diff} : ['{0.dir_extra_file}', '{0.subdir_diff}']", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "", + "diff {0.dir_subdir} {0.dir_diff_subdir}", + "Only in {0.dir_diff_subdir} : ['{0.subdir_extra_file}', " + "'{0.nested_diff}']", + "Identical files : ['{0.subdir_file}']", + "Common subdirectories : ['{0.nested}']", + "",)).format(self) + self.full_report_same = "\n".join(( + "diff {0.dir} {0.dir_same}", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "", + "diff {0.dir_subdir} {0.dir_same_subdir}", + "Identical files : ['{0.subdir_file}']", + "Common subdirectories : ['{0.nested}']", + "", + "diff {0.dir_subdir_nested} {0.dir_same_subdir_nested}", + "Identical files : ['{0.nested_file}']", + "",)).format(self) + self.full_report_diff_dirs = "\n".join(( + "diff {0.dir} {0.dir_diff}", + "Only in {0.dir_diff} : ['{0.dir_extra_file}', '{0.subdir_diff}']", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "", + "diff {0.dir_subdir} {0.dir_diff_subdir}", + "Only in {0.dir_diff_subdir} : ['{0.subdir_extra_file}', " + "'{0.nested_diff}']", + "Identical files : ['{0.subdir_file}']", + "Common subdirectories : ['{0.nested}']", + "", + "diff {0.dir_subdir_nested} {0.dir_diff_subdir_nested}", + "Only in {0.dir_diff_subdir_nested} : ['{0.nested_extra_file}']", + "Identical files : ['{0.nested_file}']", + "",)).format(self) + self.full_report_diff_files = "\n".join(( + "diff {0.dir} {0.dir_diff}", + "Only in {0.dir_diff} : ['{0.dir_extra_file}', '{0.subdir_diff}']", + "Identical files : ['{0.dir_file}']", + "Common subdirectories : ['{0.subdir}']", + "", + "diff {0.dir_subdir} {0.dir_diff_subdir}", + "Only in {0.dir_diff_subdir} : ['{0.subdir_extra_file}', " + "'{0.nested_diff}']", + "Identical files : ['{0.subdir_file}']", + "Common subdirectories : ['{0.nested}']", + "", + "diff {0.dir_subdir_nested} {0.dir_diff_subdir_nested}", + "Identical files : ['{0.nested_file}']", + "Differing files : ['{0.nested_extra_file}']", + "",)).format(self) + + def setUp(self): + self.setUpNestedSubdirectories() + self.setUpFullReports() + + def test_report_same(self): + """Test report with two identical nested subdirectories.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + with open(os.path.join(self.dir_subdir_nested, + self.nested_extra_file), 'w') as output: + output.write(self.different) + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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. + """ + + with support.temp_cwd(path=self.tmpdir) as t: + with open(os.path.join(self.dir_subdir_nested, + self.nested_extra_file), 'w') as output: + output.write(self.different) + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + d = filecmp.dircmp(self.dir, self.dir_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.""" + + with support.temp_cwd(path=self.tmpdir) as t: + with open(os.path.join(self.dir_subdir_nested, + self.nested_extra_file), 'w') as output: + output.write(self.different) + d = filecmp.dircmp(self.dir, self.dir_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()