示例#1
0
 def test_merge_takes_other_names(self):
     old_dir = os.path.join(self.temp_dir, "old")
     touch(os.path.join(self.temp_dir, "entry"))
     with mkfile(os.path.join(old_dir, "MD5SUMS")) as old_md5sums:
         print("checksum *other-entry", file=old_md5sums)
     checksum_file = ChecksumFile(self.config, self.temp_dir, "MD5SUMS",
                                  hashlib.md5)
     checksum_file.merge([old_dir], "entry", ["other-entry"])
     self.assertEqual({"entry": "checksum"}, checksum_file.entries)
示例#2
0
 def test_merge_takes_other_names(self):
     old_dir = os.path.join(self.temp_dir, "old")
     os.mkdir(old_dir)
     touch(os.path.join(self.temp_dir, "entry"))
     with open(os.path.join(old_dir, "MD5SUMS"), "w") as old_md5sums:
         print("checksum *other-entry", file=old_md5sums)
     checksum_file = ChecksumFile(
         self.config, self.temp_dir, "MD5SUMS", hashlib.md5)
     checksum_file.merge([old_dir], "entry", ["other-entry"])
     self.assertEqual({"entry": "checksum"}, checksum_file.entries)
示例#3
0
 def test_merge_ignores_stale_checksums(self):
     old_dir = os.path.join(self.temp_dir, "old")
     with mkfile(os.path.join(old_dir, "MD5SUMS")) as old_md5sums:
         print("checksum *entry", file=old_md5sums)
     entry_path = os.path.join(self.temp_dir, "entry")
     touch(entry_path)
     next_minute = time.time() + 60
     os.utime(entry_path, (next_minute, next_minute))
     checksum_file = ChecksumFile(self.config, self.temp_dir, "MD5SUMS",
                                  hashlib.md5)
     checksum_file.merge([old_dir], "entry", ["entry"])
     self.assertEqual({}, checksum_file.entries)
示例#4
0
 def test_merge_ignores_stale_checksums(self):
     old_dir = os.path.join(self.temp_dir, "old")
     os.mkdir(old_dir)
     with open(os.path.join(old_dir, "MD5SUMS"), "w") as old_md5sums:
         print("checksum *entry", file=old_md5sums)
     entry_path = os.path.join(self.temp_dir, "entry")
     touch(entry_path)
     next_minute = time.time() + 60
     os.utime(entry_path, (next_minute, next_minute))
     checksum_file = ChecksumFile(
         self.config, self.temp_dir, "MD5SUMS", hashlib.md5)
     checksum_file.merge([old_dir], "entry", ["entry"])
     self.assertEqual({}, checksum_file.entries)
示例#5
0
 def test_merge_handles_symlinks(self):
     old_dir = os.path.join(self.temp_dir, "old")
     touch(os.path.join(old_dir, "entry"))
     with mkfile(os.path.join(old_dir, "MD5SUMS")) as old_md5sums:
         print("correct-checksum *entry", file=old_md5sums)
     new_dir = os.path.join(self.temp_dir, "new")
     os.mkdir(new_dir)
     os.symlink(os.path.join(os.pardir, "old", "entry"),
                os.path.join(new_dir, "entry"))
     with mkfile(os.path.join(new_dir, "MD5SUMS")) as new_md5sums:
         print("wrong-checksum *entry", file=new_md5sums)
     checksum_file = ChecksumFile(self.config, new_dir, "MD5SUMS",
                                  hashlib.md5)
     checksum_file.merge([new_dir, old_dir], "entry", ["entry"])
     self.assertEqual({"entry": "correct-checksum"}, checksum_file.entries)