1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
import pytest
from conftest import assert_bash_exec, assert_complete
@pytest.mark.bashcomp(ignore_env=r"^[+-]_comp_cmd_scp__path_esc=")
class TestRsync:
@pytest.mark.complete("rsync ")
def test_1(self, completion):
assert completion
@pytest.mark.complete("rsync --rsh ")
def test_2(self, completion):
assert completion == "rsh ssh".split()
@pytest.mark.complete("rsync --rsh=")
def test_3(self, completion):
assert completion == "rsh ssh".split()
@pytest.mark.complete("rsync --", require_cmd=True)
def test_4(self, completion):
assert "--help" in completion
@pytest.mark.parametrize(
"ver1,ver2,result",
[
("1", "1", "="),
("1", "2", "<"),
("2", "1", ">"),
("1.1", "1.2", "<"),
("1.2", "1.1", ">"),
("1.1", "1.1.1", "<"),
("1.1.1", "1.1", ">"),
("1.1.1", "1.1.1", "="),
("2.1", "2.2", "<"),
("3.0.4.10", "3.0.4.2", ">"),
("4.08", "4.08.01", "<"),
("3.2.1.9.8144", "3.2", ">"),
("3.2", "3.2.1.9.8144", "<"),
("1.2", "2.1", "<"),
("2.1", "1.2", ">"),
("5.6.7", "5.6.7", "="),
("1.01.1", "1.1.1", "="),
("1.1.1", "1.01.1", "="),
("1", "1.0", "="),
("1.0", "1", "="),
("1.0.2.0", "1.0.2", "="),
("1..0", "1.0", "="),
("1.0", "1..0", "="),
],
)
def test_vercomp(self, bash, ver1, ver2, result):
output = assert_bash_exec(
bash,
f"_comp_cmd_rsync__vercomp {ver1} {ver2}; echo $?",
want_output=True,
).strip()
if result == "=":
assert output == "0"
elif result == ">":
assert output == "1"
elif result == "<":
assert output == "2"
else:
raise Exception(f"Unsupported comparison result: {result}")
def test_remote_path_with_spaces(self, bash):
assert_bash_exec(bash, "ssh() { echo 'spaces in filename.txt'; }")
completion = assert_complete(bash, "rsync remote_host:spaces")
assert_bash_exec(bash, "unset -f ssh")
assert (
completion == r"\ in\ filename.txt"
or completion == r"\\\ in\\\ filename.txt"
)
|