Mercurial > hgrepos > Python > apps > py-cutils
comparison tests/test_treesum.py @ 381:ff4424a7a8cf
treesum: unit tests for generating and reading treesum files
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 17 May 2025 13:25:48 +0200 |
| parents | 58552d3d1766 |
| children | e949cab90e86 |
comparison
equal
deleted
inserted
replaced
| 380:58552d3d1766 | 381:ff4424a7a8cf |
|---|---|
| 17 from _test_setup import (DATADIR, TMPDIR) | 17 from _test_setup import (DATADIR, TMPDIR) |
| 18 | 18 |
| 19 import cutils.treesum | 19 import cutils.treesum |
| 20 | 20 |
| 21 | 21 |
| 22 class TreesumTests(unittest.TestCase): | 22 class TaggedTreesumTests(unittest.TestCase): |
| 23 | 23 |
| 24 def setUp(self): | 24 def setUp(self): |
| 25 if not os.path.isdir(TMPDIR): | 25 if not os.path.isdir(TMPDIR): |
| 26 os.mkdir(TMPDIR) | 26 os.mkdir(TMPDIR) |
| 27 | 27 |
| 28 def tearDown(self): | 28 def tearDown(self): |
| 29 if os.path.isdir(TMPDIR): | 29 if os.path.isdir(TMPDIR): |
| 30 shutil.rmtree(TMPDIR) | 30 shutil.rmtree(TMPDIR) |
| 31 | 31 |
| 32 def test_xxx(self): | 32 def test_gen_and_info_P_utf8(self): |
| 33 self.assertTrue(True) | 33 digest_file = os.path.join( |
| 34 TMPDIR, | |
| 35 "%d__test_gen_and_info_P_utf8.info" % (os.getpid(),)) | |
| 36 rel_tmpdir = os.path.relpath(TMPDIR, DATADIR) | |
| 37 gen_opts = cutils.treesum.gen_generate_opts( | |
| 38 directories=[DATADIR], | |
| 39 algorithm="SHA1", | |
| 40 fnmatch_filters=[("exclude", "glob:%s" % (rel_tmpdir,))], | |
| 41 generator="full", | |
| 42 grouping_separator="_", | |
| 43 output=digest_file, | |
| 44 output_style="tagged", | |
| 45 print_size=True, | |
| 46 utf8=True) | |
| 47 info_opts = cutils.treesum.gen_info_opts(digest_files=[digest_file], | |
| 48 last=True) | |
| 49 cutils.treesum.generate_treesum(gen_opts) | |
| 50 cutils.treesum.print_treesum_digestfile_infos(info_opts) | |
| 51 info = cutils.treesum.TreesumInfo.collect_last_from_file(digest_file) | |
| 52 self.assertEqual( | |
| 53 b"\xe1\x76\x18\xfc\x9b\x2f\x1e\x41\xfc\xe0\x04\xfc\x92\x43\x4e\xa7\x49\xbd\x57\x36", # noqa: E501 line too long | |
| 54 info.digest) | |
| 55 self.assertEqual(2808, info.size) | |
| 56 self.assertEqual("SHA1", info.algorithm) | |
| 57 | |
| 58 def test_gen_and_info_P_native(self): | |
| 59 digest_file = os.path.join( | |
| 60 TMPDIR, | |
| 61 "%d__test_gen_and_info_P_native.info" % (os.getpid(),)) | |
| 62 rel_tmpdir = os.path.relpath(TMPDIR, DATADIR) | |
| 63 gen_opts = cutils.treesum.gen_generate_opts( | |
| 64 directories=[DATADIR], | |
| 65 algorithm="SHA1", | |
| 66 fnmatch_filters=[("exclude", "glob:%s" % (rel_tmpdir,))], | |
| 67 generator="full", | |
| 68 grouping_separator="_", | |
| 69 output=digest_file, | |
| 70 output_style="tagged", | |
| 71 print_size=True, | |
| 72 utf8=False) | |
| 73 info_opts = cutils.treesum.gen_info_opts(digest_files=[digest_file], | |
| 74 last=True) | |
| 75 cutils.treesum.generate_treesum(gen_opts) | |
| 76 cutils.treesum.print_treesum_digestfile_infos(info_opts) | |
| 77 info = cutils.treesum.TreesumInfo.collect_last_from_file(digest_file) | |
| 78 self.assertEqual( | |
| 79 b"\xe1\x76\x18\xfc\x9b\x2f\x1e\x41\xfc\xe0\x04\xfc\x92\x43\x4e\xa7\x49\xbd\x57\x36", # noqa: E501 line too long | |
| 80 info.digest) | |
| 81 self.assertEqual(2808, info.size) | |
| 82 self.assertEqual("SHA1", info.algorithm) | |
| 83 | |
| 84 def test_gen_and_info_L_utf8(self): | |
| 85 digest_file = os.path.join( | |
| 86 TMPDIR, | |
| 87 "%d__test_gen_and_info_L_utf8.info" % (os.getpid(),)) | |
| 88 rel_tmpdir = os.path.relpath(TMPDIR, DATADIR) | |
| 89 gen_opts = cutils.treesum.gen_generate_opts( | |
| 90 directories=[DATADIR], | |
| 91 algorithm="SHA1", | |
| 92 fnmatch_filters=[("exclude", "glob:%s" % (rel_tmpdir,))], | |
| 93 follow_symlinks=cutils.treesum.FollowSymlinkConfig( | |
| 94 True, True, True), | |
| 95 generator="full", | |
| 96 grouping_separator="_", | |
| 97 output=digest_file, | |
| 98 output_style="tagged", | |
| 99 print_size=True, | |
| 100 utf8=True) | |
| 101 info_opts = cutils.treesum.gen_info_opts(digest_files=[digest_file], | |
| 102 last=True) | |
| 103 cutils.treesum.generate_treesum(gen_opts) | |
| 104 cutils.treesum.print_treesum_digestfile_infos(info_opts) | |
| 105 info = cutils.treesum.TreesumInfo.collect_last_from_file(digest_file) | |
| 106 self.assertEqual( | |
| 107 b"\xb3\xdd\x1b\x93\xec\x3a\xa5\xf1\xb1\xc6\xbd\x8c\x1e\xe1\xd5\xcf\x72\x65\x27\x1d", # noqa: E501 line too long | |
| 108 info.digest) | |
| 109 self.assertEqual(2863, info.size) | |
| 110 self.assertEqual("SHA1", info.algorithm) | |
| 111 | |
| 112 def test_gen_and_info_L_native(self): | |
| 113 digest_file = os.path.join( | |
| 114 TMPDIR, | |
| 115 "%d__test_gen_and_info_L_native.info" % (os.getpid(),)) | |
| 116 rel_tmpdir = os.path.relpath(TMPDIR, DATADIR) | |
| 117 gen_opts = cutils.treesum.gen_generate_opts( | |
| 118 directories=[DATADIR], | |
| 119 algorithm="SHA1", | |
| 120 fnmatch_filters=[("exclude", "glob:%s" % (rel_tmpdir,))], | |
| 121 follow_symlinks=cutils.treesum.FollowSymlinkConfig( | |
| 122 True, True, True), | |
| 123 generator="full", | |
| 124 grouping_separator="_", | |
| 125 output=digest_file, | |
| 126 output_style="tagged", | |
| 127 print_size=True, | |
| 128 utf8=False) | |
| 129 info_opts = cutils.treesum.gen_info_opts(digest_files=[digest_file], | |
| 130 last=True) | |
| 131 cutils.treesum.generate_treesum(gen_opts) | |
| 132 cutils.treesum.print_treesum_digestfile_infos(info_opts) | |
| 133 info = cutils.treesum.TreesumInfo.collect_last_from_file(digest_file) | |
| 134 self.assertEqual( | |
| 135 b"\xb3\xdd\x1b\x93\xec\x3a\xa5\xf1\xb1\xc6\xbd\x8c\x1e\xe1\xd5\xcf\x72\x65\x27\x1d", # noqa: E501 line too long | |
| 136 info.digest) | |
| 137 self.assertEqual(2863, info.size) | |
| 138 self.assertEqual("SHA1", info.algorithm) | |
| 34 | 139 |
| 35 | 140 |
| 36 if __name__ == "__main__": | 141 if __name__ == "__main__": |
| 37 print(TMPDIR) | 142 sys.exit(unittest.main(buffer=True)) |
| 38 sys.exit(unittest.main()) |
