mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Merge #15269: document dircmp.left and right, and add tests for them.
Patch by Chris Jerdonek.
This commit is contained in:
commit
7f84833726
2 changed files with 33 additions and 2 deletions
|
@ -91,6 +91,16 @@ The :class:`dircmp` class
|
||||||
to compute are used.
|
to compute are used.
|
||||||
|
|
||||||
|
|
||||||
|
.. attribute:: left
|
||||||
|
|
||||||
|
The directory *a*.
|
||||||
|
|
||||||
|
|
||||||
|
.. attribute:: right
|
||||||
|
|
||||||
|
The directory *b*.
|
||||||
|
|
||||||
|
|
||||||
.. attribute:: left_list
|
.. attribute:: left_list
|
||||||
|
|
||||||
Files and subdirectories in *a*, filtered by *hide* and *ignore*.
|
Files and subdirectories in *a*, filtered by *hide* and *ignore*.
|
||||||
|
@ -154,3 +164,18 @@ The :class:`dircmp` class
|
||||||
A dictionary mapping names in :attr:`common_dirs` to :class:`dircmp`
|
A dictionary mapping names in :attr:`common_dirs` to :class:`dircmp`
|
||||||
objects.
|
objects.
|
||||||
|
|
||||||
|
|
||||||
|
Here is a simplified example of using the ``subdirs`` attribute to search
|
||||||
|
recursively through two directories to show common different files::
|
||||||
|
|
||||||
|
>>> from filecmp import dircmp
|
||||||
|
>>> def print_diff_files(dcmp):
|
||||||
|
... for name in dcmp.diff_files:
|
||||||
|
... print("diff_file %s found in %s and %s" % (name, dcmp.left,
|
||||||
|
... dcmp.right))
|
||||||
|
... for sub_dcmp in dcmp.subdirs.values():
|
||||||
|
... print_diff_files(sub_dcmp)
|
||||||
|
...
|
||||||
|
>>> dcmp = dircmp('dir1', 'dir2')
|
||||||
|
>>> print_diff_files(dcmp)
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,10 @@ class DirCompareTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_dircmp(self):
|
def test_dircmp(self):
|
||||||
# Check attributes for comparison of two identical directories
|
# Check attributes for comparison of two identical directories
|
||||||
d = filecmp.dircmp(self.dir, self.dir_same)
|
left_dir, right_dir = self.dir, self.dir_same
|
||||||
|
d = filecmp.dircmp(left_dir, right_dir)
|
||||||
|
self.assertEqual(d.left, left_dir)
|
||||||
|
self.assertEqual(d.right, right_dir)
|
||||||
if self.caseinsensitive:
|
if self.caseinsensitive:
|
||||||
self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']])
|
self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']])
|
||||||
else:
|
else:
|
||||||
|
@ -109,7 +112,10 @@ class DirCompareTestCase(unittest.TestCase):
|
||||||
self.assertEqual(d.diff_files, [])
|
self.assertEqual(d.diff_files, [])
|
||||||
|
|
||||||
# Check attributes for comparison of two different directories
|
# Check attributes for comparison of two different directories
|
||||||
d = filecmp.dircmp(self.dir, self.dir_diff)
|
left_dir, right_dir = self.dir, self.dir_diff
|
||||||
|
d = filecmp.dircmp(left_dir, right_dir)
|
||||||
|
self.assertEqual(d.left, left_dir)
|
||||||
|
self.assertEqual(d.right, right_dir)
|
||||||
self.assertEqual(d.left_list, ['file'])
|
self.assertEqual(d.left_list, ['file'])
|
||||||
self.assertTrue(d.right_list == ['file', 'file2'])
|
self.assertTrue(d.right_list == ['file', 'file2'])
|
||||||
self.assertEqual(d.common, ['file'])
|
self.assertEqual(d.common, ['file'])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue