Skip to content

Commit a186fab

Browse files
authored
Merge pull request #1428 from yedayak/use-live-more
test(scp): use live_pwd to test xfunc_remote_files
2 parents 136dd33 + 3a6e9e7 commit a186fab

File tree

3 files changed

+33
-43
lines changed

3 files changed

+33
-43
lines changed

test/fixtures/scp/bin/ssh

Lines changed: 0 additions & 19 deletions
This file was deleted.

test/t/conftest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ def partialize(
184184
return first_char, partial_items
185185

186186

187+
def get_testdir():
188+
return os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
189+
190+
187191
@pytest.fixture(scope="class")
188192
def bash(request) -> pexpect.spawn:
189193
logfile: Optional[TextIO] = None
@@ -196,9 +200,7 @@ def bash(request) -> pexpect.spawn:
196200
elif os.environ.get("CI"):
197201
logfile = sys.stdout
198202

199-
testdir = os.path.abspath(
200-
os.path.join(os.path.dirname(__file__), os.pardir)
201-
)
203+
testdir = get_testdir()
202204

203205
# Create an empty temporary file for HISTFILE.
204206
#

test/t/test_scp.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
assert_bash_exec,
99
assert_complete,
1010
bash_env_saved,
11+
get_testdir,
1112
prepare_fixture_dir,
1213
)
1314

@@ -32,7 +33,7 @@ def test_basic(self, hosts, completion):
3233
)
3334
),
3435
# Local filenames
35-
["bin/", "config", "known_hosts", r"spaced\ \ conf"],
36+
["config", "known_hosts", r"spaced\ \ conf"],
3637
)
3738
)
3839
assert completion == expected
@@ -52,7 +53,7 @@ def test_basic_spaced_conf(self, hosts, completion):
5253
)
5354
),
5455
# Local filenames
55-
["bin/", "config", "known_hosts", r"spaced\ \ conf"],
56+
["config", "known_hosts", r"spaced\ \ conf"],
5657
)
5758
)
5859
assert completion == expected
@@ -68,9 +69,9 @@ def test_capital_f_without_space(self, completion):
6869
def test_capital_f_without_space_2(self, completion):
6970
assert completion == "ig"
7071

71-
@pytest.mark.complete("scp -Fbi", cwd="scp")
72+
@pytest.mark.complete("scp -Fempty", cwd="shared")
7273
def test_capital_f_without_space_3(self, completion):
73-
assert completion == "n/"
74+
assert completion == "_dir/"
7475

7576
@pytest.fixture(scope="class")
7677
def live_pwd(self, bash):
@@ -119,15 +120,15 @@ def test_remote_path_with_spaces(self, bash):
119120
assert_bash_exec(bash, "unset -f ssh")
120121
assert completion == r"\\\ in\\\ filename.txt"
121122

122-
def test_xfunc_remote_files(self, bash):
123+
def test_xfunc_remote_files(self, live_pwd, bash):
124+
def prefix_paths(prefix, paths):
125+
return [f"{prefix}{path}" for path in paths]
126+
123127
with bash_env_saved(bash) as bash_env:
124128
bash_env.save_variable("COMPREPLY")
125129
bash_env.write_variable(
126-
"PATH",
127-
"$PWD/scp/bin:$PATH",
128-
quote=False,
130+
"cur", f"{LIVE_HOST}:{get_testdir()}/fixtures/shared/default/"
129131
)
130-
bash_env.write_variable("cur", "local:shared/default/")
131132
completions_regular_escape = (
132133
assert_bash_exec(
133134
bash,
@@ -146,18 +147,24 @@ def test_xfunc_remote_files(self, bash):
146147
.strip()
147148
.splitlines()
148149
)
149-
assert completions_regular_escape == [
150-
"shared/default/bar ",
151-
r"shared/default/bar\\\ bar.d/",
152-
"shared/default/foo ",
153-
"shared/default/foo.d/",
154-
]
155-
assert completions_less_escape == [
156-
"shared/default/bar ",
157-
r"shared/default/bar\ bar.d/",
158-
"shared/default/foo ",
159-
"shared/default/foo.d/",
160-
]
150+
assert completions_regular_escape == prefix_paths(
151+
f"{get_testdir()}/fixtures/shared/default/",
152+
[
153+
"bar ",
154+
r"bar\\\ bar.d/",
155+
"foo ",
156+
"foo.d/",
157+
],
158+
)
159+
assert completions_less_escape == prefix_paths(
160+
f"{get_testdir()}/fixtures/shared/default/",
161+
[
162+
"bar ",
163+
r"bar\ bar.d/",
164+
"foo ",
165+
"foo.d/",
166+
],
167+
)
161168

162169
@pytest.fixture
163170
def tmpdir_backslash(self, request, bash):

0 commit comments

Comments
 (0)