18 """Write files into a given directory."""
21 if not os.path.exists(self.
_cwd):
22 os.makedirs(self.
_cwd)
24 def mkdir(self, dname, mode=0o755):
25 """Create the given directory with the given mode."""
26 dname = os.path.join(self.
_cwd, dname)
30 def write(self, fname, mode=0o640):
31 """Write the file with the given mode and random contents."""
32 fname = os.path.join(self.
_cwd, fname)
33 with open(fname,
'w')
as f:
34 f.write(str(uuid.uuid4()))
38 """Remove the file."""
39 fname = os.path.join(self.
_cwd, fname)
40 if os.path.isfile(fname):
47 """Compare two directory trees, assert if any differences."""
48 def _cmp(prefix, dcmp):
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)
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:
65 with open(pathB,
'rb')
as f:
67 test.assertEqual(contentsA, contentsB)
70 for prefix, obj
in dcmp.subdirs.items():
73 _cmp(
'', filecmp.dircmp(a, b))
def write(self, fname, mode=0o640)
def mkdir(self, dname, mode=0o755)
def compare_trees(test, a, b)