Debian Codegraph @

testsuite/00-hello_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/00-hello.test.
3 #
4 # Foundational smoke test: --version / --info=help / --debug=help all
5 # work, plus a round-trip transfer of a directory whose name contains
6 # shell-special characters via the lsh.sh remote-shell stand-in.
7
8 import os
9
10 from rsyncfns import (
11 FROMDIR, RSYNC, RSYNC_PEER, SRCDIR, TODIR,
12 checkit, run_rsync, test_fail, rsync_path_arg, rsh_cmd,
13 )
14
15
16 # Set RSYNC_RSH so rsync picks up lsh.sh for the "lh:" hosts below.
17 os.environ['RSYNC_RSH'] = rsh_cmd()
18
19 # Basic help dumps must not crash.
20 if run_rsync('--version', check=False).returncode != 0:
21 test_fail('--version output failed')
22 if run_rsync('--info=help', check=False).returncode != 0:
23 test_fail('--info=help output failed')
24 if run_rsync('--debug=help', check=False).returncode != 0:
25 test_fail('--debug=help output failed')
26
27 weird_name = "A weird)name"
28
29 FROMDIR.mkdir(parents=True, exist_ok=True)
30 weird_dir = FROMDIR / weird_name
31 weird_dir.mkdir()
32
33
34 def append_line(line: str) -> None:
35 print(line)
36 with open(weird_dir / 'file', 'a') as f:
37 f.write(line + '\n')
38
39
40 def copy_weird(args: list, src_host: str, dst_host: str) -> None:
41 checkit(
42 [*args, f'--rsync-path={rsync_path_arg()}',
43 f'{src_host}{weird_dir}/',
44 f'{dst_host}{TODIR / weird_name}'],
45 FROMDIR, TODIR,
46 )
47
48
49 append_line('test1')
50 checkit(['-ai', f'{FROMDIR}/', f'{TODIR}/'], FROMDIR, TODIR)
51
52 append_line('test2')
53 copy_weird(['-ai'], 'lh:', '')
54
55 append_line('test3')
56 copy_weird(['-ai'], '', 'lh:')
57
58 append_line('test4')
59 copy_weird(['-ais'], 'lh:', '')
60
61 append_line('test5')
62 copy_weird(['-ais'], '', 'lh:')
63
64 # test6: --old-args lets two whitespace-separated names go through as a
65 # single "one two" remote argument to be re-split by the remote shell.
66 print('test6')
67 (FROMDIR / 'one').touch()
68 (FROMDIR / 'two').touch()
69
70 saved = os.getcwd()
71 os.chdir(FROMDIR)
72 try:
73 run_rsync('-ai', '--old-args', f'--rsync-path={rsync_path_arg()}',
74 'lh:one two', f'{TODIR}/')
75 finally:
76 os.chdir(saved)
77
78 if not (TODIR / 'one').is_file() or not (TODIR / 'two').is_file():
79 test_fail("old-args copy of 'one two' failed")
80
81 # test7: the RSYNC_OLD_ARGS=1 env var should be equivalent to --old-args.
82 print('test7')
83 (TODIR / 'one').unlink()
84 (TODIR / 'two').unlink()
85
86 env = os.environ.copy()
87 env['RSYNC_OLD_ARGS'] = '1'
88 import subprocess
89 from rsyncfns import rsync_argv
90
91 os.chdir(FROMDIR)
92 try:
93 subprocess.run(
94 rsync_argv('-ai', f'--rsync-path={rsync_path_arg()}',
95 'lh:one two', f'{TODIR}/'),
96 env=env, check=True,
97 )
98 finally:
99 os.chdir(saved)
100
101 # check=True only proves a zero exit; confirm the env-var path actually copied
102 # both files (as the explicit --old-args case above does).
103 if not (TODIR / 'one').is_file() or not (TODIR / 'two').is_file():
104 test_fail("RSYNC_OLD_ARGS=1 copy of 'one two' failed")