Debian Codegraph @

testsuite/stop-time_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 """Coverage of --stop-at (options.c parse_time) and --stop-after.
3
4 --stop-at parses an absolute y-m-dTh:m time (parse_time): a future time is
5 accepted and the transfer proceeds; a past time is rejected at parse. --stop-after
6 takes a minute count. These exercise the OPT_STOP_AT/OPT_STOP_AFTER option
7 handling that no other test reaches.
8 """
9
10 from datetime import datetime, timedelta
11
12 from rsyncfns import (
13 FROMDIR, TODIR,
14 assert_same, make_tree, rmtree, run_rsync, test_fail, walk_files,
15 )
16
17 src = FROMDIR
18 rmtree(src)
19 make_tree(src, depth=2)
20 rels = [p.relative_to(src) for p in walk_files(src)]
21
22 # --- --stop-at in the future: parses, transfer completes normally -----------
23 # Generated relative to now (a day ahead) rather than a fixed far-future date:
24 # rsync rejects a --stop-at that isn't strictly in the future, and a hard-coded
25 # year would date-rot and can overflow a 32-bit time_t.
26 future = (datetime.now() + timedelta(days=1)).strftime('%Y-%m-%dT%H:%M')
27 rmtree(TODIR)
28 run_rsync('-a', f'--stop-at={future}', f'{src}/', f'{TODIR}/')
29 for rel in rels:
30 assert_same(TODIR / rel, src / rel, label=f'--stop-at future {rel}')
31
32 # --- --stop-at in the past: rejected at parse -------------------------------
33 rmtree(TODIR)
34 proc = run_rsync('-a', '--stop-at=2000-01-01T00:00', f'{src}/', f'{TODIR}/',
35 check=False)
36 if proc.returncode == 0:
37 test_fail("--stop-at with a past time was not rejected")
38
39 # --- --stop-after (minutes): parses, transfer completes ---------------------
40 rmtree(TODIR)
41 run_rsync('-a', '--stop-after=60', f'{src}/', f'{TODIR}/')
42 for rel in rels:
43 assert_same(TODIR / rel, src / rel, label=f'--stop-after {rel}')
44
45 print("stop-time: --stop-at future/past and --stop-after verified")