Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_filecmp.DirCompareTestCase Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_cmpfiles
def test_dircmp

Public Attributes

 dir
 dir_same
 dir_diff
 caseinsensitive

Detailed Description

Definition at line 43 of file test_filecmp.py.


Member Function Documentation

Definition at line 44 of file test_filecmp.py.

00044 
00045     def setUp(self):
00046         tmpdir = tempfile.gettempdir()
00047         self.dir = os.path.join(tmpdir, 'dir')
00048         self.dir_same = os.path.join(tmpdir, 'dir-same')
00049         self.dir_diff = os.path.join(tmpdir, 'dir-diff')
00050         self.caseinsensitive = os.path.normcase('A') == os.path.normcase('a')
00051         data = 'Contents of file go here.\n'
00052         for dir in [self.dir, self.dir_same, self.dir_diff]:
00053             shutil.rmtree(dir, True)
00054             os.mkdir(dir)
00055             if self.caseinsensitive and dir is self.dir_same:
00056                 fn = 'FiLe'     # Verify case-insensitive comparison
00057             else:
00058                 fn = 'file'
00059             output = open(os.path.join(dir, fn), 'w')
00060             output.write(data)
00061             output.close()
00062 
00063         output = open(os.path.join(self.dir_diff, 'file2'), 'w')
00064         output.write('An extra file.\n')
00065         output.close()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 66 of file test_filecmp.py.

00066 
00067     def tearDown(self):
00068         shutil.rmtree(self.dir)
00069         shutil.rmtree(self.dir_same)
00070         shutil.rmtree(self.dir_diff)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 71 of file test_filecmp.py.

00071 
00072     def test_cmpfiles(self):
00073         self.assertTrue(filecmp.cmpfiles(self.dir, self.dir, ['file']) ==
00074                         (['file'], [], []),
00075                         "Comparing directory to itself fails")
00076         self.assertTrue(filecmp.cmpfiles(self.dir, self.dir_same, ['file']) ==
00077                         (['file'], [], []),
00078                         "Comparing directory to same fails")
00079 
00080         # Try it with shallow=False
00081         self.assertTrue(filecmp.cmpfiles(self.dir, self.dir, ['file'],
00082                                          shallow=False) ==
00083                         (['file'], [], []),
00084                         "Comparing directory to itself fails")
00085         self.assertTrue(filecmp.cmpfiles(self.dir, self.dir_same, ['file'],
00086                                          shallow=False),
00087                         "Comparing directory to same fails")
00088 
00089         # Add different file2
00090         output = open(os.path.join(self.dir, 'file2'), 'w')
00091         output.write('Different contents.\n')
00092         output.close()
00093 
00094         self.assertFalse(filecmp.cmpfiles(self.dir, self.dir_same,
00095                                      ['file', 'file2']) ==
00096                     (['file'], ['file2'], []),
00097                     "Comparing mismatched directories fails")
00098 

Here is the call graph for this function:

Definition at line 99 of file test_filecmp.py.

00099 
00100     def test_dircmp(self):
00101         # Check attributes for comparison of two identical directories
00102         d = filecmp.dircmp(self.dir, self.dir_same)
00103         if self.caseinsensitive:
00104             self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']])
00105         else:
00106             self.assertEqual([d.left_list, d.right_list],[['file'], ['file']])
00107         self.assertEqual(d.common, ['file'])
00108         self.assertTrue(d.left_only == d.right_only == [])
00109         self.assertEqual(d.same_files, ['file'])
00110         self.assertEqual(d.diff_files, [])
00111 
00112         # Check attributes for comparison of two different directories
00113         d = filecmp.dircmp(self.dir, self.dir_diff)
00114         self.assertEqual(d.left_list, ['file'])
00115         self.assertTrue(d.right_list == ['file', 'file2'])
00116         self.assertEqual(d.common, ['file'])
00117         self.assertEqual(d.left_only, [])
00118         self.assertEqual(d.right_only, ['file2'])
00119         self.assertEqual(d.same_files, ['file'])
00120         self.assertEqual(d.diff_files, [])
00121 
00122         # Add different file2
00123         output = open(os.path.join(self.dir, 'file2'), 'w')
00124         output.write('Different contents.\n')
00125         output.close()
00126         d = filecmp.dircmp(self.dir, self.dir_diff)
00127         self.assertEqual(d.same_files, ['file'])
00128         self.assertEqual(d.diff_files, ['file2'])
00129 

Here is the call graph for this function:


Member Data Documentation

Definition at line 49 of file test_filecmp.py.

Definition at line 46 of file test_filecmp.py.

Definition at line 48 of file test_filecmp.py.

Definition at line 47 of file test_filecmp.py.


The documentation for this class was generated from the following file: