Skip to content

Commit

Permalink
test/_expand: port remaining test cases to pytest+pexpect
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed May 10, 2020
1 parent 4543212 commit db481c6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 42 deletions.
9 changes: 9 additions & 0 deletions test/t/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ def known_hosts(bash: pexpect.spawn) -> List[str]:
return sorted(set(output.split()))


@pytest.fixture(scope="class")
def user_home(bash: pexpect.spawn) -> Tuple[str, str]:
user = assert_bash_exec(
bash, 'id -un 2>/dev/null || echo "$USER"', want_output=True
).strip()
home = assert_bash_exec(bash, 'echo "$HOME"', want_output=True).strip()
return (user, home)


def partialize(
bash: pexpect.spawn, items: Iterable[str]
) -> Tuple[str, List[str]]:
Expand Down
20 changes: 19 additions & 1 deletion test/t/unit/test_unit_expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,29 @@
from conftest import assert_bash_exec


@pytest.mark.bashcomp(cmd=None)
@pytest.mark.bashcomp(cmd=None, ignore_env=r"^[+-](cur|COMPREPLY)=")
class TestUnitExpand:
def test_1(self, bash):
assert_bash_exec(bash, "_expand >/dev/null")

def test_2(self, bash):
"""Test environment non-pollution, detected at teardown."""
assert_bash_exec(bash, "foo() { _expand; }; foo; unset foo")

def test_user_home_compreply(self, bash, user_home):
user, home = user_home
output = assert_bash_exec(
bash,
r'cur="~%s"; _expand; printf "%%s\n" "$COMPREPLY"' % user,
want_output=True,
)
assert output.strip() == home

def test_user_home_cur(self, bash, user_home):
user, home = user_home
output = assert_bash_exec(
bash,
r'cur="~%s/a"; _expand; printf "%%s\n" "$cur"' % user,
want_output=True,
)
assert output.strip() == "%s/a" % home
8 changes: 0 additions & 8 deletions test/t/unit/test_unit_expand_tilde_by_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@

@pytest.mark.bashcomp(cmd=None, ignore_env=r"^[+-]var=")
class TestUnitExpandTildeByRef:
@pytest.fixture(scope="class")
def user_home(self, bash):
user = assert_bash_exec(
bash, 'id -un 2>/dev/null || echo "$USER"', want_output=True
).strip()
home = assert_bash_exec(bash, 'echo "$HOME"', want_output=True).strip()
return (user, home)

def test_1(self, bash):
assert_bash_exec(bash, "__expand_tilde_by_ref >/dev/null")

Expand Down
33 changes: 0 additions & 33 deletions test/unit/_expand.exp

This file was deleted.

0 comments on commit db481c6

Please sign in to comment.