comparison 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
comparison
equal deleted inserted replaced
385:ea73723be05e 386:f045d46e9f3d
194 # accepts the size within the .treesum file 194 # accepts the size within the .treesum file
195 self.assertEqual(67, info.size) 195 self.assertEqual(67, info.size)
196 # accepts uses the digest algorithm from the .treesum file 196 # accepts uses the digest algorithm from the .treesum file
197 self.assertEqual("SHA256", info.algorithm) 197 self.assertEqual("SHA256", info.algorithm)
198 198
199 def test_comments_in_treesum_file(self):
200 src_digest_file = os.path.join(DATADIR, "_data.treesum")
201 dst_digest_file = os.path.join(TMPDIR, "_data.treesum")
202
203 with open(src_digest_file, "rb") as src:
204 with open(dst_digest_file, "wb") as dst:
205 first = True
206 lineno = 0
207 while True:
208 line = src.readline(4096)
209 if not line:
210 # write a trailing comment
211 dst.write("; this is a trailing comment\r\n")
212 break
213 if first:
214 # write a leading comment
215 dst.write("# this is a leading comment\r\n")
216 first = False
217 lineno += 1
218 dst.write(line)
219 if lineno == 1:
220 dst.write(" ;this is a comment after VERSION\n")
221 elif lineno == 9:
222 dst.write("#this is a comment after a digest line\r\n")
223 info_opts = cutils.treesum.gen_info_opts(
224 digest_files=[dst_digest_file],
225 last=True)
226 cutils.treesum.print_treesum_digestfile_infos(info_opts)
227 info = cutils.treesum.TreesumInfo.collect_last_from_file(
228 dst_digest_file)
229 self.assertEqual(
230 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
231 info.digest)
232 # accepts the size within the .treesum file
233 self.assertEqual(67, info.size)
234 # accepts uses the digest algorithm from the .treesum file
235 self.assertEqual("SHA256", info.algorithm)
236 self.assertEqual("4C53C26D", info.crc_checksum)
237
199 238
200 if __name__ == "__main__": 239 if __name__ == "__main__":
201 sys.exit(unittest.main(buffer=True)) 240 sys.exit(unittest.main(buffer=True))