Debian Codegraph @

testsuite/missing_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/missing.test.
3 #
4 # Three regressions guarded by the missing_below logic rewrite:
5 # 1. Dry-run with --ignore-non-existing must NOT emit "not creating new"
6 # for files whose containing directory already exists at the dest.
7 # 2. Dry-run -R -y --no-implied-dirs must not crash trying to build a
8 # fuzzy dirlist for a directory it never created.
9 # 3. --delete-after dry-run still emits "*deleting" lines even when the
10 # last source dir is dry-missing on the destination.
11
12 import os
13 import subprocess
14
15 from rsyncfns import FROMDIR, RSYNC, TMPDIR, TODIR, makepath, rsync_argv, test_fail
16
17
18 makepath(FROMDIR / 'subdir', TODIR)
19 (FROMDIR / 'subdir' / 'file').write_text("data\n")
20 (TODIR / 'other').write_text("data\n")
21
22
23 def run_capture(*args):
24 proc = subprocess.run(rsync_argv(*args), capture_output=True, text=True)
25 print(proc.stdout, end='')
26 print(proc.stderr, end='')
27 return proc
28
29
30 # Test 1: too much "not creating new..." output on a dry-run.
31 out_path = TMPDIR / 'out1'
32 proc = run_capture('-n', '-r', '--ignore-non-existing', '-vv',
33 f'{FROMDIR}/', f'{TODIR}/')
34 if proc.returncode != 0:
35 test_fail(f"test 1 failed: dry-run errored (rc={proc.returncode})")
36 out_path.write_text(proc.stdout)
37 for line in proc.stdout.splitlines():
38 if 'not creating new' in line and 'subdir/file' in line:
39 test_fail("test 1 failed: dry-run announced creating subdir/file")
40
41 # Test 2: fuzzy dirlist crash on dry-run. Skipped on protocol 29 just like
42 # the shell version did, since the new flist sanity check rejects this.
43 if 'protocol=29' not in RSYNC:
44 proc = run_capture('-n', '-r', '-R', '--no-implied-dirs', '-y',
45 f'{FROMDIR}/./subdir/file', f'{TODIR}/')
46 if proc.returncode != 0:
47 test_fail("test 2 failed: --no-implied-dirs dry-run errored")
48 else:
49 print("Skipped test 2 for protocol 29.")
50
51 # Test 3: --delete-after pass skipped when last dir is dry-missing.
52 proc = run_capture('-n', '-r', '--delete-after', '-i',
53 f'{FROMDIR}/', f'{TODIR}/')
54 saw_delete = any(line.lstrip().startswith('*deleting')
55 and 'other' in line
56 for line in proc.stdout.splitlines())
57 if not saw_delete:
58 test_fail("test 3 failed: no '*deleting other' line in dry-run output")