Debian Codegraph @

testsuite/hands_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/hands.test.
3 #
4 # The canonical end-to-end transfer test: build a richly-populated source
5 # tree via hands_setup() then run a series of rsync invocations covering
6 # basic operation, hard links, single-file copies, --no-whole-file delta
7 # updates and --delete cleanup. After each run the source and destination
8 # tree listings must match exactly.
9
10 import os
11 import shutil
12
13 from rsyncfns import FROMDIR, TMPDIR, TODIR, checkit, hands_setup, run_rsync
14
15
16 hands_setup()
17
18 DEBUG_OPTS = "--debug=all0,deltasum0"
19
20
21 # 1. basic operation
22 print("Test basic operation:")
23 checkit(['-av', f'{FROMDIR}/', str(TODIR)], FROMDIR, TODIR)
24
25 # 2. hard links — link filelist into dir/ then transfer with -H so the
26 # receiver should recreate the link relationship.
27 os.link(FROMDIR / 'filelist', FROMDIR / 'dir' / 'filelist')
28 print("Test hard links:")
29 checkit(['-avH', '--bwlimit=0', DEBUG_OPTS, f'{FROMDIR}/', str(TODIR)], FROMDIR, TODIR)
30
31 # 3. one file — delete the destination 'text' and re-sync; only it should
32 # transfer, everything else stays uptodate.
33 (TODIR / 'text').unlink()
34 print("Test one file:")
35 checkit(['-avH', DEBUG_OPTS, f'{FROMDIR}/', str(TODIR)], FROMDIR, TODIR)
36
37 # 4. extra data — append to destination then re-sync with --no-whole-file so
38 # the rsync delta algorithm has to repair it.
39 with open(TODIR / 'text', 'a') as f:
40 f.write("extra line\n")
41 print("Test extra data:")
42 checkit(['-avH', DEBUG_OPTS, '--no-whole-file', f'{FROMDIR}/', str(TODIR)], FROMDIR, TODIR)
43
44 # 5. --delete — add a stray file on the destination and confirm --delete
45 # removes it.
46 shutil.copy(FROMDIR / 'text', TODIR / 'ThisShouldGo')
47 print("Test --delete:")
48 checkit(['--delete', '-avH', DEBUG_OPTS, f'{FROMDIR}/', str(TODIR)], FROMDIR, TODIR)
49
50 # 6. globbed copy without recursion — wipe and re-sync top-level entries by
51 # glob, then a final empty pass to compare listings.
52 os.chdir(TMPDIR)
53 shutil.rmtree('to', ignore_errors=True)
54 for entry in TMPDIR.glob('from/*dir'):
55 if entry.is_dir():
56 shutil.rmtree(entry, ignore_errors=True)
57 else:
58 entry.unlink()
59
60 # Replicate `rsync -av from/* to/` — list the from/ children explicitly.
61 sources = sorted(str(p) for p in (TMPDIR / 'from').iterdir())
62 run_rsync('-av', *sources, 'to/')
63 checkit(['-av', '--exclude=*', 'from/', 'to/'], FROMDIR, TODIR)