mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-05-30 17:58:10 -04:00
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>
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
# Python rewrite of testsuite/ssh-basic.test.
|
|
#
|
|
# Basic two-step "remote shell" transfer via lsh.sh (or real ssh if
|
|
# rsync_enable_ssh_tests=yes is set in shconfig). Confirms that an -e
|
|
# RSH transfer reproduces the source tree on the destination, and that
|
|
# a follow-up --delete pass cleans up after a destination-side rename.
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
|
|
from rsyncfns import (
|
|
FROMDIR, SRCDIR, TODIR,
|
|
checkit, hands_setup, runtest, test_skipped,
|
|
)
|
|
|
|
|
|
SSH = str(SRCDIR / 'support' / 'lsh.sh')
|
|
|
|
# Allow opting into real ssh via the shconfig variable, like the shell test.
|
|
if os.environ.get('rsync_enable_ssh_tests') == 'yes':
|
|
real_ssh = shutil.which('ssh')
|
|
if real_ssh:
|
|
SSH = real_ssh
|
|
|
|
probe = subprocess.run(
|
|
[SSH, '-oBatchMode yes', 'localhost', 'echo', 'yes'],
|
|
capture_output=True, text=True,
|
|
)
|
|
if probe.stdout.strip() != 'yes':
|
|
test_skipped(
|
|
"Skipping SSH tests because ssh connection to localhost not authorised"
|
|
)
|
|
|
|
print(f"Using remote shell: {SSH}")
|
|
|
|
hands_setup()
|
|
|
|
# RSYNC may be a multi-word command line; pass it through --rsync-path.
|
|
from rsyncfns import RSYNC
|
|
|
|
|
|
def _basic():
|
|
checkit(['-avH', '-e', SSH, f'--rsync-path={RSYNC}',
|
|
f'{FROMDIR}/', f'localhost:{TODIR}'], FROMDIR, TODIR)
|
|
|
|
|
|
def _delete_after_rename():
|
|
shutil.move(str(TODIR / 'text'), str(TODIR / 'ThisShouldGo'))
|
|
checkit(['--delete', '-avH', '-e', SSH, f'--rsync-path={RSYNC}',
|
|
f'{FROMDIR}/', f'localhost:{TODIR}'], FROMDIR, TODIR)
|
|
|
|
|
|
runtest("ssh: basic test", _basic)
|
|
runtest("ssh: renamed file", _delete_after_rename)
|