Files
rsync/testsuite/crtimes_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

39 lines
1.2 KiB
Python

#!/usr/bin/env python3
# Python rewrite of testsuite/crtimes.test.
#
# Test that rsync preserves source create times when the binary was built
# with crtimes support. Touch tricks: setting an older time via touch sets
# the create time to the mtime; setting a newer time affects only mtime.
import datetime
import os
import rsyncfns
from rsyncfns import FROMDIR, TODIR, checkit, run_rsync, test_skipped
vv = run_rsync('-VV', check=True, capture_output=True)
if '"crtimes": true' not in vv.stdout:
test_skipped("Rsync is configured without crtimes support")
FROMDIR.mkdir(parents=True, exist_ok=True)
(FROMDIR / 'foo').write_text("hiho\n")
def _utime(path, when: 'datetime.datetime') -> None:
ts = when.timestamp()
os.utime(path, (ts, ts))
# Touch fromdir to an old time then to a newer time -- in shells with the
# right kernel support this leaves the create time pinned to the older.
_utime(FROMDIR, datetime.datetime(2001, 1, 1, 11, 11, 11))
_utime(FROMDIR, datetime.datetime(2002, 2, 2, 22, 22, 22))
_utime(FROMDIR / 'foo', datetime.datetime(2001, 11, 11, 11, 11, 11))
_utime(FROMDIR / 'foo', datetime.datetime(2002, 12, 12, 22, 22, 22))
rsyncfns.TLS_ARGS = '--crtimes'
checkit(['-rtgvvv', '--crtimes', f'{FROMDIR}/', f'{TODIR}/'], FROMDIR, TODIR)