47 """Compare two directory trees, assert if any differences."""
48 def _cmp(prefix, dcmp):
49
50 test.assertEqual(
len(dcmp.left_only), 0)
51 test.assertEqual(
len(dcmp.right_only), 0)
52 test.assertEqual(
len(dcmp.diff_files), 0)
53 test.assertEqual(
len(dcmp.funny_files), 0)
54
55
56 for f in dcmp.common_files:
57 pathA = os.path.join(a, prefix, f)
58 pathB = os.path.join(b, prefix, f)
59 test.assertTrue(filecmp.cmp(pathA, pathB, shallow=False))
60 statA = os.stat(pathA)
61 statB = os.stat(pathB)
62 test.assertEqual(statA.st_mode, statB.st_mode)
63 with open(pathA, 'rb') as f:
64 contentsA = f.read()
65 with open(pathB, 'rb') as f:
66 contentsB = f.read()
67 test.assertEqual(contentsA, contentsB)
68
69
70 for prefix, obj in dcmp.subdirs.items():
71 _cmp(prefix, obj)
72
73 _cmp('', filecmp.dircmp(a, b))
def compare_trees(test, a, b)