Files
rsync/testsuite/duplicates_test.py
Andrew Tridgell 1f689ec0c2 testsuite: rewrite the shell testsuite in Python
Replace the entire shell-based testsuite with Python. runtests.py
already drove the suite (it had replaced runtests.sh earlier); this
converts all 60 test scripts from *.test shell to *_test.py and adds
testsuite/rsyncfns.py as the shared helper module -- the Python
counterpart of the now-removed rsync.fns.

runtests.py:
  * Discovers and runs both *.test and *_test.py; dispatches the
    Python tests via the same python3 that runs the harness.
  * Extends PYTHONPATH so tests can `import rsyncfns`.

testsuite/rsyncfns.py provides everything the ports need:
  * environment wiring (scratchdir / srcdir / TOOLDIR / RSYNC /
    TLS_ARGS, and HOME pointed at the per-test scratch dir);
  * result reporting -- test_fail / test_skipped / test_xfail mapping
    to the 0 / 1 / 77 / 78 exit-code convention;
  * the transfer-and-verify helpers checkit, checkdiff, verify_dirs,
    rsync_ls_lR, check_perms and the v_filt output filter;
  * fixture builders hands_setup, build_symlinks, build_rsyncd_conf,
    make_data_file, cp_p / cp_touch, makepath / rmtree.

All 60 tests are converted, including the four split-variant tests
that share one source via a Makefile-built symlink (chown/chown-fake,
devices/devices-fake, xattrs/xattrs-hlink, exclude/exclude-lsh);
Makefile.in's CHECK_SYMLINKS now points at the *_test.py names.

The dead rsync.fns shell library is removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 14:34:52 +10:00

50 lines
1.6 KiB
Python

#!/usr/bin/env python3
# Python rewrite of testsuite/duplicates.test.
#
# The same source directory can be listed many times on the command line
# (e.g. through shell globbing). clean_flist() is supposed to dedupe so
# each file/link is copied exactly once even with ten identical sources.
import os
import subprocess
from rsyncfns import (
FROMDIR, TODIR,
rsync_argv, rsync_ls_lR, test_fail,
)
# Build a single regular file plus a symlink to it.
FROMDIR.mkdir(parents=True, exist_ok=True)
name1 = FROMDIR / 'name1'
name2 = FROMDIR / 'name2'
name1.write_text("This is the file\n")
try:
os.symlink(str(name1), name2)
except OSError as e:
test_fail(f"can't create symlink: {e}")
# Drive rsync with the same source ten times. Capture the verbose output to
# inspect for duplicate-copy behaviour AND for the dir-listing comparison
# that the shell test's checkit was doing alongside.
sources = [f'{FROMDIR}/'] * 10
proc = subprocess.run(
rsync_argv('-avv', *sources, f'{TODIR}/'),
capture_output=True, text=True,
)
print(proc.stdout)
if proc.returncode != 0:
test_fail(f"rsync exited {proc.returncode}\n{proc.stderr}")
name1_count = sum(1 for ln in proc.stdout.splitlines() if ln == 'name1')
if name1_count != 1:
test_fail(f"name1 was not copied exactly once (got {name1_count})")
name2_count = sum(1 for ln in proc.stdout.splitlines() if ln.startswith('name2 -> '))
if name2_count != 1:
test_fail(f"name2 was not copied exactly once (got {name2_count})")
# Cross-check that the destination matches the source.
if rsync_ls_lR(FROMDIR) != rsync_ls_lR(TODIR):
test_fail("destination listing differs from source after deduplication")