Skip to content

Commit

Permalink
test: convert finger partial test case to pytest+pexpect
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed May 4, 2019
1 parent cd9f061 commit f3537dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 41 deletions.
7 changes: 0 additions & 7 deletions test/lib/completions/finger.exp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ setup
sync_after_int


set test "Tab should complete partial username"
assert_complete_partial [exec bash -c "compgen -A user -S @"] "finger" "" $test -nospace


sync_after_int


set test "Tab should complete partial hostname"
# Build string list of hostnames, starting with the character of the first
# host, unless host starts with a COMP_WORDBREAKS character, e.g. a colon (:).
Expand Down
31 changes: 0 additions & 31 deletions test/lib/library.exp
Original file line number Diff line number Diff line change
Expand Up @@ -378,37 +378,6 @@ proc assert_complete_dir {expected cmd dir {test ""} {args {}}} {



# Make sure a partial argument is completed.
# A completion is tried with `$partial', or if this is empty, the first
# character of the first item of `$expected'. Only the items from $expected,
# starting with this character are then expected as completions.
# @param list $expected List of all completions.
# @param string $cmd Command given to generate items
# @param string $partial Word to complete
# @param string $test Test title
# @param list $args See: assert_complete()
proc assert_complete_partial {expected cmd {partial ""} {test ""} {args {}}} {
if {$test == ""} {set test "$cmd should complete partial argument"}
if {[llength $expected] == 0} {
unresolved "$test"
} else {
set pick {}
# Make sure expected items are unique
set expected [lsort -unique $expected]
foreach item $expected {
if {$partial == ""} {set partial [string range $item 0 0]}
# Only append item if starting with $partial
if {[string range $item 0 [expr [string length $partial] - 1]] == "$partial"} {
lappend pick $item
}
}
# NOTE: The `eval' is necessary to flatten the $args list
# See also: http://wiki.tcl.tk/11787 - {expand}
eval assert_complete \$pick \"\$cmd \$partial\" \$test $args; #"
}
}


# If cword contains colon (:), left-trim completions with cword
# @param string $cmd Command to complete
# @param list $items Reference to list of completions to trim
Expand Down
17 changes: 14 additions & 3 deletions test/t/test_finger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@


class TestFinger:
@pytest.mark.complete("finger ")
def test_1(self, bash, completion):
users_at = sorted(
@pytest.fixture(scope="class")
def users_at(self, bash):
return sorted(
assert_bash_exec(
bash, "compgen -A user -S @", want_output=True
).split()
)

@pytest.mark.complete("finger ")
def test_1(self, bash, completion, users_at):
assert completion == users_at

@pytest.mark.complete("finger r")
def test_2(self, bash, completion, users_at):
if not any(x.startswith("r") for x in users_at):
pytest.skip("No users starting with r")
assert completion
assert all(x.startswith("r") for x in completion)
assert not completion.endswith(" ")

0 comments on commit f3537dd

Please sign in to comment.