Debian Codegraph @

testsuite/fuzzy-basis_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 """Coverage of --fuzzy basis selection scoring (util1.c fuzzy_distance).
3
4 When the destination has no exact match for a source file, --fuzzy makes the
5 generator score the same-directory candidates by name similarity (fuzzy_distance)
6 and use the closest as the delta basis. Set this up at depth with several
7 similar-named candidates so the scorer actually runs.
8 """
9
10 import os
11
12 from rsyncfns import (
13 FROMDIR, TODIR,
14 assert_same, make_data_file, makepath, rmtree, run_rsync, test_fail,
15 )
16
17 src = FROMDIR
18 deepdir = os.path.join('d1', 'd2')
19 newfile = os.path.join(deepdir, 'archive-v2.tar')
20
21 rmtree(src)
22 rmtree(TODIR)
23 makepath(src / deepdir, TODIR / deepdir)
24
25 make_data_file(src / newfile, 300_000)
26 base = (src / newfile).read_bytes()
27
28 # Destination has NO 'archive-v2.tar', but several similar-named candidates that
29 # are mostly identical to it -- so fuzzy must score them by name distance.
30 (TODIR / deepdir / 'archive-v1.tar').write_bytes(base[:280_000] + b'older tail data')
31 (TODIR / deepdir / 'archive-old.tar').write_bytes(base[:200_000])
32 (TODIR / deepdir / 'unrelated.dat').write_bytes(b'nothing alike' * 1000)
33
34 # Capture --debug=FUZZY: a correct final file alone would also result from a
35 # full transfer that ignored --fuzzy, so assert the scorer actually chose the
36 # closest-named candidate (archive-v1.tar) as the basis, not just that bytes match.
37 proc = run_rsync('-a', '--fuzzy', '--no-whole-file', '--debug=FUZZY',
38 f'{src}/', f'{TODIR}/', capture_output=True)
39 want = f'fuzzy basis selected for {newfile}: {os.path.join(deepdir, "archive-v1.tar")}'
40 if want not in proc.stdout:
41 test_fail(f"--fuzzy did not score archive-v1.tar as the closest basis; "
42 f"expected {want!r}, --debug=FUZZY output was:\n{proc.stdout}")
43 assert_same(TODIR / newfile, src / newfile, label='fuzzy result')
44
45 print("fuzzy-basis: --fuzzy candidate scoring (fuzzy_distance) verified at depth")