Reinstate the actual python autopkgtests, accidentally removed in the previous upload.
Closes: #944072
Signed-off-by: Mattia Rizzolo <mattia@debian.org>
Mattia Rizzolo
4 years ago
0 | 0 | #!/usr/bin/python3 |
1 | 1 | |
2 | import runpy | |
2 | import tlsh | |
3 | ||
4 | ||
5 | def compute_hash(path): | |
6 | h = tlsh.Tlsh() | |
7 | with open(path, 'rb') as f: | |
8 | for buf in iter(lambda: f.read(512), b''): | |
9 | h.update(buf) | |
10 | h.final() | |
11 | return h | |
12 | ||
13 | ||
14 | def compare_files(left_path, right_path): | |
15 | left_hash = compute_hash(left_path) | |
16 | right_hash = compute_hash(right_path) | |
17 | return left_hash.diff(right_hash) | |
18 | ||
19 | ||
20 | def main(): | |
21 | score = compare_files('debian/tests/data/file1', 'debian/tests/data/file1') | |
22 | print('Identical:', score) | |
23 | if score != 0: | |
24 | raise Exception('Should be identical') | |
25 | score = compare_files('debian/tests/data/file1', 'debian/tests/data/file2') | |
26 | print('Similar:', score) | |
27 | if score >= 40: | |
28 | raise Exception('Should be similar') | |
29 | score = compare_files('debian/tests/data/file1', 'debian/tests/data/quick') | |
30 | print('Different:', score) | |
31 | if score <= 300: | |
32 | raise Exception('Should be different') | |
33 | ||
3 | 34 | |
4 | 35 | if __name__ == '__main__': |
5 | globals = runpy.run_path('debian/tests/use-python-tlsh') | |
6 | globals['main']() | |
36 | main() |