def _hash_all_files(path: Path) -> Dict[Path, Tuple[str, int]]: if path.is_dir(): files = [p for p in path.rglob("*") if p.is_file()] else: files = [path] hashes = {} for f in files: original_crc32 = verify.calculate_file_crc32(f) original_inode = f.stat().st_ino hashes[f.relative_to(path)] = (original_crc32, original_inode) return hashes
def test_checksum(self): d = write_files({"test1.txt": "test"}) test_file = d.joinpath("test1.txt") sha1_hash = verify.calculate_file_hash(test_file) self.assertEqual(sha1_hash, "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3") md5_hash = verify.calculate_file_hash(test_file, hash_fn=hashlib.md5) self.assertEqual(md5_hash, "098f6bcd4621d373cade4e832627b4f6") crc32_checksum = verify.calculate_file_crc32(test_file) self.assertEqual(crc32_checksum, "d87f7e0c")
def test_checksum(self): # noqa: T003 d = write_files({"test1.txt": "test"}) test_file = d.joinpath("test1.txt") sha1_hash = verify.calculate_file_hash(test_file) assert sha1_hash == "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3" md5_hash = verify.calculate_file_hash(test_file, hash_fn=hashlib.md5) assert md5_hash == "098f6bcd4621d373cade4e832627b4f6" crc32_checksum = verify.calculate_file_crc32(test_file) assert crc32_checksum == "d87f7e0c"