Mercurial > hgrepos > Python > apps > py-cutils
diff tests/test_treesum.py @ 386:f045d46e9f3d
treesum: also collect the CRC checksum when reading .treesum files and test for them
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 17 May 2025 22:41:22 +0200 |
| parents | ea73723be05e |
| children |
line wrap: on
line diff
--- a/tests/test_treesum.py Sat May 17 16:53:16 2025 +0200 +++ b/tests/test_treesum.py Sat May 17 22:41:22 2025 +0200 @@ -196,6 +196,45 @@ # accepts uses the digest algorithm from the .treesum file self.assertEqual("SHA256", info.algorithm) + def test_comments_in_treesum_file(self): + src_digest_file = os.path.join(DATADIR, "_data.treesum") + dst_digest_file = os.path.join(TMPDIR, "_data.treesum") + + with open(src_digest_file, "rb") as src: + with open(dst_digest_file, "wb") as dst: + first = True + lineno = 0 + while True: + line = src.readline(4096) + if not line: + # write a trailing comment + dst.write("; this is a trailing comment\r\n") + break + if first: + # write a leading comment + dst.write("# this is a leading comment\r\n") + first = False + lineno += 1 + dst.write(line) + if lineno == 1: + dst.write(" ;this is a comment after VERSION\n") + elif lineno == 9: + dst.write("#this is a comment after a digest line\r\n") + info_opts = cutils.treesum.gen_info_opts( + digest_files=[dst_digest_file], + last=True) + cutils.treesum.print_treesum_digestfile_infos(info_opts) + info = cutils.treesum.TreesumInfo.collect_last_from_file( + dst_digest_file) + self.assertEqual( + b"\x69\x6f\xe2\x51\xbe\x94\xbe\xcc\x76\xa5\x91\x24\x1d\x46\x83\xbb\x44\x36\xc7\x9b\x5b\x7b\x62\xb3\xe0\x4a\x0e\xdc\x7e\xc4\x07\xcb", # noqa: E501 line too long + info.digest) + # accepts the size within the .treesum file + self.assertEqual(67, info.size) + # accepts uses the digest algorithm from the .treesum file + self.assertEqual("SHA256", info.algorithm) + self.assertEqual("4C53C26D", info.crc_checksum) + if __name__ == "__main__": sys.exit(unittest.main(buffer=True))
