mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-06-08 06:05:57 -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>
66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
# Python rewrite of testsuite/chmod-temp-dir.test.
|
|
#
|
|
# Like chmod_test.py, but uses --temp-dir pointing at a different
|
|
# filesystem so rsync must rename(2) across filesystems (i.e. fall back
|
|
# to copy+unlink) instead of the in-place rename it does when temp and
|
|
# destination are on the same fs. We probe candidate tmp paths to find
|
|
# one whose filesystem differs from the scratch dir.
|
|
|
|
import os
|
|
import subprocess
|
|
|
|
from rsyncfns import FROMDIR, SCRATCHDIR, TODIR, TOOLDIR, checkit, hands_setup, test_skipped
|
|
|
|
|
|
def _fsdev(path: str) -> str:
|
|
return subprocess.check_output(
|
|
[str(TOOLDIR / 'getfsdev'), path], text=True,
|
|
).strip()
|
|
|
|
|
|
hands_setup()
|
|
|
|
scratch_dev = _fsdev(str(SCRATCHDIR))
|
|
tmpdir2 = None
|
|
candidates = [
|
|
os.environ.get('RSYNC_TEST_TMP', '/override-tmp-not-specified'),
|
|
'/run/shm', '/var/tmp', '/tmp',
|
|
]
|
|
for cand in candidates:
|
|
if not (os.path.isdir(cand) and os.access(cand, os.W_OK)):
|
|
continue
|
|
if _fsdev(cand) != scratch_dev:
|
|
tmpdir2 = cand
|
|
break
|
|
|
|
if tmpdir2 is None:
|
|
test_skipped("Can't find a tmp dir on a different file system")
|
|
|
|
|
|
# Mirror chmod_test.py: set up a varied permission tree on the source.
|
|
def _try_chmods(path, modes):
|
|
for m in modes:
|
|
try:
|
|
os.chmod(path, m)
|
|
return
|
|
except PermissionError:
|
|
continue
|
|
os.chmod(path, modes[-1])
|
|
|
|
|
|
os.chmod(FROMDIR / 'text', 0o440)
|
|
os.chmod(FROMDIR / 'dir' / 'text', 0o500)
|
|
_try_chmods(FROMDIR / 'dir' / 'subdir' / 'foobar.baz',
|
|
[0o6450, 0o2450, 0o1450, 0o450])
|
|
_try_chmods(FROMDIR / 'dir' / 'subdir' / 'subsubdir' / 'etc-ltr-list',
|
|
[0o2670, 0o1670, 0o670])
|
|
|
|
# First a normal copy (whole-file) but through a cross-fs --temp-dir.
|
|
checkit(['-avv', f'--temp-dir={tmpdir2}', f'{FROMDIR}/', str(TODIR)],
|
|
FROMDIR, TODIR)
|
|
|
|
# Then an update through delta, still routing partial transfers across fs.
|
|
checkit(['-avvI', '--no-whole-file', f'--temp-dir={tmpdir2}',
|
|
f'{FROMDIR}/', str(TODIR)], FROMDIR, TODIR)
|