Mercurial > hgrepos > Python > apps > py-cutils
comparison tests/test_treesum.py @ 385:ea73723be05e
treesum: unit tests with an existing .treesum file:
- ignore them
- FIX: checksums where existing .treesum files were not ignored properly
- accept them with (implicitly) changing the algorithm
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 17 May 2025 16:53:16 +0200 |
| parents | e949cab90e86 |
| children | f045d46e9f3d |
comparison
equal
deleted
inserted
replaced
| 384:f66afecac253 | 385:ea73723be05e |
|---|---|
| 139 b"\xfe\x21\x4c\xfa\xdc\xc5\x1f\xad\x63\x19\x74\x95\xf5\xb3\x6d\x32\x45\xec\x73\x3e", # noqa: E501 line too long | 139 b"\xfe\x21\x4c\xfa\xdc\xc5\x1f\xad\x63\x19\x74\x95\xf5\xb3\x6d\x32\x45\xec\x73\x3e", # noqa: E501 line too long |
| 140 info.digest) | 140 info.digest) |
| 141 self.assertEqual(110, info.size) | 141 self.assertEqual(110, info.size) |
| 142 self.assertEqual("SHA1", info.algorithm) | 142 self.assertEqual("SHA1", info.algorithm) |
| 143 | 143 |
| 144 def test_gen_and_info_P_utf8_with_treesum(self): | |
| 145 digest_file = os.path.join( | |
| 146 TMPDIR, | |
| 147 "%d__test_gen_and_info_P_native.info" % (os.getpid(),)) | |
| 148 rel_tmpdir = os.path.relpath(TMPDIR, DATADIR) | |
| 149 gen_opts = cutils.treesum.gen_generate_opts( | |
| 150 directories=[DATADIR], | |
| 151 algorithm="SHA1", | |
| 152 fnmatch_filters=[("exclude", "path:%s" % (rel_tmpdir,))], | |
| 153 generator="full", | |
| 154 grouping_separator="_", | |
| 155 output=digest_file, | |
| 156 output_style="tagged", | |
| 157 print_size=True, | |
| 158 utf8=True) | |
| 159 info_opts = cutils.treesum.gen_info_opts(digest_files=[digest_file], | |
| 160 last=True) | |
| 161 cutils.treesum.generate_treesum(gen_opts) | |
| 162 cutils.treesum.print_treesum_digestfile_infos(info_opts) | |
| 163 info = cutils.treesum.TreesumInfo.collect_last_from_file(digest_file) | |
| 164 self.assertEqual( | |
| 165 b"\x78\xdd\xcd\xd2\xbe\xa5\x2c\x8c\xc9\x1e\x3a\xd4\x26\xda\x35\x2e\xa6\xc2\x0a\x06", # noqa: E501 line too long | |
| 166 info.digest) | |
| 167 self.assertEqual(2620, info.size) | |
| 168 self.assertEqual("SHA1", info.algorithm) | |
| 169 | |
| 170 def test_gen_and_info_P_utf8_accept_treesum(self): | |
| 171 digest_file = os.path.join( | |
| 172 TMPDIR, | |
| 173 "%d__test_gen_and_info_P_native.info" % (os.getpid(),)) | |
| 174 rel_tmpdir = os.path.relpath(TMPDIR, DATADIR) | |
| 175 gen_opts = cutils.treesum.gen_generate_opts( | |
| 176 directories=[DATADIR], | |
| 177 algorithm="SHA1", | |
| 178 fnmatch_filters=[("exclude", "path:%s" % (rel_tmpdir,)), | |
| 179 ("accept-treesum", "glob:*.treesum")], | |
| 180 generator="full", | |
| 181 grouping_separator="_", | |
| 182 output=digest_file, | |
| 183 output_style="tagged", | |
| 184 print_size=True, | |
| 185 utf8=True) | |
| 186 info_opts = cutils.treesum.gen_info_opts(digest_files=[digest_file], | |
| 187 last=True) | |
| 188 cutils.treesum.generate_treesum(gen_opts) | |
| 189 cutils.treesum.print_treesum_digestfile_infos(info_opts) | |
| 190 info = cutils.treesum.TreesumInfo.collect_last_from_file(digest_file) | |
| 191 self.assertEqual( | |
| 192 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 | |
| 193 info.digest) | |
| 194 # accepts the size within the .treesum file | |
| 195 self.assertEqual(67, info.size) | |
| 196 # accepts uses the digest algorithm from the .treesum file | |
| 197 self.assertEqual("SHA256", info.algorithm) | |
| 198 | |
| 144 | 199 |
| 145 if __name__ == "__main__": | 200 if __name__ == "__main__": |
| 146 sys.exit(unittest.main(buffer=True)) | 201 sys.exit(unittest.main(buffer=True)) |
