Skip to content

Commit

Permalink
Fix Alpine Linux completion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ghantoos committed Dec 1, 2024
1 parent f87459b commit f2e02a6
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions test/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from getpass import getuser
import pexpect

from test.test_utils import is_alpine_linux

TOPDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
CONFIG = f"{TOPDIR}/test/testfiles/test.conf"
Expand Down Expand Up @@ -57,15 +58,24 @@ def test_14_path_completion_tilda(self):
open(file2, "w").close()

# test dir list
if is_alpine_linux():
command = "ls -a -d ~/*/"
else:
command = "find . -maxdepth 1 -type d -printf '%f/\n'"
p_dir_list = subprocess.Popen(
"find . -maxdepth 1 -type d -printf '%f/\n'",
command,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
)
stdout_p_dir_list = p_dir_list.stdout
expected = stdout_p_dir_list.read().decode("utf8").strip().split()
# Normalize expected to relative paths
if is_alpine_linux():
# Remove the `/home/<user>/` prefix for Alpine Linux
expected = {os.path.basename(path.rstrip("/")) + "/" for path in expected}
else:
expected = set(expected)
expected = set(expected)
expected.discard("./")

Expand Down Expand Up @@ -101,8 +111,12 @@ def test_15_file_completion_tilda(self):
open(file2, "w").close()

# test file list
if is_alpine_linux():
command = "ls -a -p ~/"
else:
command = "find . -maxdepth 1 -printf '%P%y\n' | sed 's|d$|/|;s|f$||'"
p_file_list = subprocess.Popen(
"find . -maxdepth 1 -printf '%P%y\n' | sed 's|d$|/|;s|f$||'",
command,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
Expand All @@ -111,6 +125,10 @@ def test_15_file_completion_tilda(self):
expected = stdout_p_file_list.read().decode("utf8").strip().split()
expected = set(expected)
expected.discard("/")
# alpine specific because of `ls -a -p`
if is_alpine_linux():
expected.discard("./")
expected.discard("../")

self.child.sendline("ls ~/\t\t")
self.child.expect(PROMPT)
Expand Down Expand Up @@ -146,8 +164,12 @@ def test_16_file_completion_with_arg(self):
open(file2, "w").close()

# test file list
if is_alpine_linux():
command = "ls -a -p ~/"
else:
command = "find . -maxdepth 1 -printf '%P%y\n' | sed 's|d$|/|;s|f$||'"
p_file_list = subprocess.Popen(
"find . -maxdepth 1 -printf '%P%y\n' | sed 's|d$|/|;s|f$||'",
command,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
Expand All @@ -156,6 +178,10 @@ def test_16_file_completion_with_arg(self):
expected = stdout_p_file_list.read().decode("utf8").strip().split()
expected = set(expected)
expected.discard("/")
# alpine specific because of `ls -a -p`
if is_alpine_linux():
expected.discard("./")
expected.discard("../")

self.child.sendline("ls -l ~/\t\t")
self.child.expect(PROMPT)
Expand Down

0 comments on commit f2e02a6

Please sign in to comment.