Skip to content

Commit

Permalink
test: port most umount test cases to pytest+pexpect
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed May 3, 2020
1 parent 663ac51 commit b621591
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 65 deletions.
66 changes: 1 addition & 65 deletions test/lib/completions/umount.exp
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
# umount completion from fstab can't be tested directly because it
# (correctly) uses absolute paths. So we create a custom completion which
# reads from a file in our text fixture instead.
proc setup_dummy_mnt {} {
assert_bash_exec {unset COMPREPLY cur}
assert_bash_exec {unset -f _mnt}

assert_bash_exec { \
_mnt() { \
local cur=$(_get_cword); \
_linux_fstab $(_get_pword) < "$SRCDIRABS/fixtures/mount/test-fstab"; \
}; \
complete -F _mnt mnt \
}
}


proc teardown_dummy_mnt {} {
assert_bash_exec {unset COMPREPLY cur}
assert_bash_exec {unset -f _mnt}
assert_bash_exec {complete -r mnt}
}


proc setup {} {
save_env
setup_dummy_mnt
}


proc teardown {} {
teardown_dummy_mnt
assert_env_unmodified {/OLDPWD/d}
assert_env_unmodified
}


Expand All @@ -54,42 +28,4 @@ assert_bash_exec {unset var}
sync_after_int


# Begin testing through mnt (see setup_dummy_mnt).
assert_complete {/mnt/nice-test-path} {mnt /mnt/nice-test-p}
sync_after_int

assert_complete {/mnt/nice\ test-path} {mnt /mnt/nice\ test-p}
sync_after_int

assert_complete {/mnt/nice\$test-path} {mnt /mnt/nice\$test-p}
sync_after_int

assert_complete {/mnt/nice\ test\\path} {mnt /mnt/nice\ test\\p}
sync_after_int

assert_complete {{/mnt/nice\ test\\path} {/mnt/nice\ test-path}} \
{mnt /mnt/nice\ } "" -expect-cmd-minus {/mnt/nice\ }
sync_after_int

assert_complete {/mnt/nice\$test-path} {mnt /mnt/nice\$}
sync_after_int

assert_complete {/mnt/nice\'test-path} {mnt /mnt/nice\'}
sync_after_int

assert_complete {/mnt/other\'test\ path} {mnt /mnt/other}
sync_after_int

assert_complete {Ubuntu\ Karmic} {mnt -L Ubu}
sync_after_int

assert_complete {Debian-it\'s\ awesome} {mnt -L Deb}
sync_after_int

# This does not work. Proper support for this requires smarter parsing of
# $COMP_LINE and it's not worth doing just for umount.
#assert_complete {$'/mnt/nice\ntest-path'} {mnt $'/mnt/nice\n}
#sync_after_int


teardown
67 changes: 67 additions & 0 deletions test/t/test_umount.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,74 @@
import pytest

from conftest import assert_bash_exec


class TestUmount:
@pytest.fixture(scope="class")
def dummy_mnt(self, request, bash):
"""
umount completion from fstab can't be tested directly because it
(correctly) uses absolute paths. So we create a custom completion which
reads from a file in our text fixture instead.
"""
assert_bash_exec(bash, "unset COMPREPLY cur; unset -f _mnt")
assert_bash_exec(
bash,
"_mnt() { "
"local cur=$(_get_cword); "
"_linux_fstab $(_get_pword) < mount/test-fstab; "
"} && complete -F _mnt mnt",
)
request.addfinalizer(
lambda: assert_bash_exec(bash, "complete -r mnt; unset -f _mnt")
)

@pytest.mark.complete("umount ")
def test_1(self, completion):
assert completion

@pytest.mark.complete("mnt /mnt/nice-test-p")
def test_mnt_basic(self, completion, dummy_mnt):
assert completion == "/mnt/nice-test-path"

# Note in tests below that return only one result, that the result
# is shell unescaped due to how assert_complete handles the
# "one result on same line case".

@pytest.mark.complete(r"mnt /mnt/nice\ test-p")
def test_mnt_space(self, completion, dummy_mnt):
assert completion == r"/mnt/nice test-path"

@pytest.mark.complete(r"mnt /mnt/nice\$test-p")
def test_mnt_dollar(self, completion, dummy_mnt):
assert completion == "/mnt/nice$test-path"

@pytest.mark.complete(r"mnt /mnt/nice\ test\\p")
def test_mnt_backslash(self, completion, dummy_mnt):
assert completion == r"/mnt/nice test\path"

@pytest.mark.complete(r"mnt /mnt/nice\ ")
def test_mnt_after_space(self, completion, dummy_mnt):
assert completion == sorted(
(r"/mnt/nice\ test\\path", r"/mnt/nice\ test-path")
)

@pytest.mark.complete(r"mnt /mnt/nice\$")
def test_mnt_at_dollar(self, completion, dummy_mnt):
assert completion == "/mnt/nice$test-path"

@pytest.mark.complete(r"mnt /mnt/nice\'")
def test_mnt_at_quote(self, completion, dummy_mnt):
assert completion == "/mnt/nice'test-path"

@pytest.mark.complete("mnt /mnt/other")
def test_mnt_other(self, completion, dummy_mnt):
assert completion == "/mnt/other'test path"

@pytest.mark.complete("mnt -L Ubu")
def test_mnt_label_space(self, completion, dummy_mnt):
assert completion == "Ubuntu Karmic"

@pytest.mark.complete("mnt -L Deb")
def test_mnt_label_quote(self, completion, dummy_mnt):
assert completion == "Debian-it's awesome"

0 comments on commit b621591

Please sign in to comment.