Skip to content

Commit

Permalink
test: always run tests which don't require tested command
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Jul 4, 2019
1 parent f40a1ca commit 674dd80
Show file tree
Hide file tree
Showing 345 changed files with 534 additions and 391 deletions.
13 changes: 9 additions & 4 deletions test/t/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def bash(request) -> pexpect.spawn:
if match:
cmd = match.group(1)

setattr(request.cls, "cmd", cmd)

if (cmd_found and cmd is None) or is_testable(bash, cmd):
before_env = get_env(bash)
yield bash
Expand Down Expand Up @@ -184,15 +186,14 @@ def is_testable(bash: pexpect.spawn, cmd: str) -> bool:
if not cmd:
pytest.fail("Could not resolve name of command to test")
return False
if not is_bash_type(bash, cmd):
pytest.skip("Command %s not found" % cmd)
return False
if not load_completion_for(bash, cmd):
pytest.skip("No completion for command %s" % cmd)
return True


def is_bash_type(bash: pexpect.spawn, cmd: str) -> bool:
def is_bash_type(bash: pexpect.spawn, cmd: Optional[str]) -> bool:
if not cmd:
return False
typecmd = "type %s &>/dev/null && echo -n 0 || echo -n 1" % cmd
bash.sendline(typecmd)
bash.expect_exact(typecmd + "\r\n")
Expand Down Expand Up @@ -453,6 +454,10 @@ def completion(request, bash: pexpect.spawn) -> CompletionResult:
return CompletionResult("", [])
for pre_cmd in marker.kwargs.get("pre_cmds", []):
assert_bash_exec(bash, pre_cmd)
if marker.kwargs.get("require_cmd") and not is_bash_type(
bash, getattr(request.module, "cmd", None)
):
pytest.skip("Command not found")
return assert_complete(bash, marker.args[0], **marker.kwargs)


Expand Down
2 changes: 1 addition & 1 deletion test/t/test_2to3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class Test2to3:
def test_1(self, completion):
assert completion

@pytest.mark.complete("2to3 -")
@pytest.mark.complete("2to3 -", require_cmd=True)
def test_2(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_7z.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_3(self, completion):
def test_4(self, completion):
assert completion == "a.7z"

@pytest.mark.complete("7z d a.7z ", cwd="7z")
@pytest.mark.complete("7z d a.7z ", cwd="7z", require_cmd=True)
def test_5(self, completion):
assert completion == "abc"

Expand Down
2 changes: 1 addition & 1 deletion test/t/test_a2x.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestA2x:
def test_1(self, completion):
assert completion

@pytest.mark.complete("a2x -")
@pytest.mark.complete("a2x -", require_cmd=True)
def test_2(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_abook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TestAbook:
@pytest.mark.complete("abook -")
@pytest.mark.complete("abook -", require_cmd=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_aclocal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestAclocal:
def test_1(self, completion):
assert completion

@pytest.mark.complete("aclocal -")
@pytest.mark.complete("aclocal -", require_cmd=True)
def test_2(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_acpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TestAcpi:
@pytest.mark.complete("acpi -")
@pytest.mark.complete("acpi -", require_cmd=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestAdb:
def test_1(self, completion):
assert completion

@pytest.mark.complete("adb -")
@pytest.mark.complete("adb -", require_cmd=True)
def test_2(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_alpine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TestAlpine:
@pytest.mark.complete("alpine -")
@pytest.mark.complete("alpine -", require_cmd=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_ant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@pytest.mark.bashcomp(ignore_env=r"^\+ANT_ARGS=")
class TestAnt:
@pytest.mark.complete("ant -")
@pytest.mark.complete("ant -", require_cmd=True)
def test_1(self, completion):
assert completion

Expand Down
2 changes: 1 addition & 1 deletion test/t/test_appdata_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class TestAppdataValidate:
def test_1(self, completion):
assert completion

@pytest.mark.complete("appdata-validate -")
@pytest.mark.complete("appdata-validate -", require_cmd=True)
def test_2(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_apt_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TestAptCache:
def test_1(self, completion):
assert completion

@pytest.mark.complete("apt-cache showsrc [")
@pytest.mark.complete("apt-cache showsrc [", require_cmd=True)
def test_2(self, completion):
# Doesn't actually fail on grep errors, but takes a long time.
assert not completion
2 changes: 1 addition & 1 deletion test/t/test_arpspoof.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TestArpspoof:
@pytest.mark.complete("arpspoof -")
@pytest.mark.complete("arpspoof -", require_cmd=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_asciidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestAsciidoc:
def test_1(self, completion):
assert completion

@pytest.mark.complete("asciidoc -")
@pytest.mark.complete("asciidoc -", require_cmd=True)
def test_2(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_automake.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestAutomake:
def test_1(self, completion):
assert completion

@pytest.mark.complete("automake -")
@pytest.mark.complete("automake -", require_cmd=True)
def test_2(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_autoscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestAutoscan:
def test_1(self, completion):
assert completion

@pytest.mark.complete("autoscan -")
@pytest.mark.complete("autoscan -", require_cmd=True)
def test_2(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_autossh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TestAutossh:
@pytest.mark.complete("autossh -")
@pytest.mark.complete("autossh -", require_cmd=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_badblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TestBadblocks:
def test_1(self, completion):
assert completion

@pytest.mark.complete("badblocks -")
@pytest.mark.complete("badblocks -", require_cmd=True)
def test_2(self, completion):
assert completion
assert all(x not in completion for x in "-w -X".split())
2 changes: 1 addition & 1 deletion test/t/test_bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TestBash:
@pytest.mark.complete("bash --")
@pytest.mark.complete("bash --", require_cmd=True)
def test_1(self, completion):
assert completion
1 change: 1 addition & 0 deletions test/t/test_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class TestBc:
@pytest.mark.complete(
"bc --",
require_cmd=True,
xfail=(
"! bc --help &>/dev/null || "
"! bc --help 2>&1 | command grep -qF -- --help"
Expand Down
2 changes: 1 addition & 1 deletion test/t/test_bison.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TestBison:
@pytest.mark.complete("bison --")
@pytest.mark.complete("bison --", require_cmd=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestCal:
def test_1(self, completion):
assert completion

@pytest.mark.complete("cal -")
@pytest.mark.complete("cal -", require_cmd=True)
def test_2(self, completion):
assert completion
6 changes: 3 additions & 3 deletions test/t/test_ccache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@


class TestCcache:
@pytest.mark.complete("ccache -")
@pytest.mark.complete("ccache -", require_cmd=True)
def test_1(self, completion):
assert completion

@pytest.mark.complete("ccache --clea")
@pytest.mark.complete("ccache --clea", require_cmd=True)
def test_2(self, completion):
assert all(x in completion for x in "--cleanup --clear".split())

Expand All @@ -18,7 +18,7 @@ def test_3(self, completion):
def test_4(self, completion):
assert "stty" in completion

@pytest.mark.complete("ccache --hel")
@pytest.mark.complete("ccache --hel", require_cmd=True)
def test_5(self, completion):
assert "--help" in completion

Expand Down
4 changes: 2 additions & 2 deletions test/t/test_ccze.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class TestCcze:
@pytest.mark.complete("ccze ")
@pytest.mark.complete("ccze ", require_cmd=True)
def test_1(self, completion):
assert completion

Expand All @@ -14,6 +14,6 @@ def test_2(self, completion):
def test_3(self, completion):
assert completion

@pytest.mark.complete("ccze --plugin=")
@pytest.mark.complete("ccze --plugin=", require_cmd=True)
def test_4(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_cfagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TestCfagent:
@pytest.mark.complete("cfagent -")
@pytest.mark.complete("cfagent -", require_cmd=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_chage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestChage:
def test_1(self, completion):
assert completion

@pytest.mark.complete("chage -")
@pytest.mark.complete("chage -", require_cmd=True)
def test_2(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_checksec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TestChecksec:
@pytest.mark.complete("checksec -")
@pytest.mark.complete("checksec -", require_cmd=True)
def test_1(self, completion):
assert completion
4 changes: 2 additions & 2 deletions test/t/test_chronyc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@


class TestChronyc:
@pytest.mark.complete("chronyc ")
@pytest.mark.complete("chronyc ", require_cmd=True)
def test_1(self, completion):
assert completion

@pytest.mark.complete("chronyc -")
@pytest.mark.complete("chronyc -", require_cmd=True)
def test_2(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_chrpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestChrpath:
def test_1(self, completion):
assert completion

@pytest.mark.complete("chrpath -")
@pytest.mark.complete("chrpath -", require_cmd=True)
def test_2(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_chsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def test_1(self, completion):
def test_2(self, completion):
assert completion

@pytest.mark.complete("chsh -")
@pytest.mark.complete("chsh -", require_cmd=True)
def test_3(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_civclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TestCivclient:
@pytest.mark.complete("civclient -")
@pytest.mark.complete("civclient -", require_cmd=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_civserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TestCivserver:
@pytest.mark.complete("civserver -")
@pytest.mark.complete("civserver -", require_cmd=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_cksfv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TestCksfv:
@pytest.mark.complete("cksfv -")
@pytest.mark.complete("cksfv -", require_cmd=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def test_1(self, completion):
def test_2(self, completion):
assert completion

@pytest.mark.complete("convert -")
@pytest.mark.complete("convert -", require_cmd=True)
def test_3(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_cpan2dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class TestCpan2dist:
@pytest.mark.complete("cpan2dist -")
@pytest.mark.complete("cpan2dist -", require_cmd=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_cppcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TestCppcheck:
def test_1(self, completion):
assert completion

@pytest.mark.complete("cppcheck -")
@pytest.mark.complete("cppcheck -", require_cmd=True)
def test_2(self, completion):
assert completion

Expand Down
2 changes: 1 addition & 1 deletion test/t/test_cryptsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestCryptsetup:
def test_1(self, completion):
assert completion

@pytest.mark.complete("cryptsetup -")
@pytest.mark.complete("cryptsetup -", require_cmd=True)
def test_2(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_curl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class TestCurl:
@pytest.mark.complete("curl --h")
@pytest.mark.complete("curl --h", require_cmd=True)
def test_1(self, completion):
assert completion

Expand Down
2 changes: 1 addition & 1 deletion test/t/test_cvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ def test_2(self, completion):
def test_3(self, completion):
assert completion == "foo/bar"

@pytest.mark.complete("cvs -")
@pytest.mark.complete("cvs -", require_cmd=True)
def test_4(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_cvsps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@pytest.mark.bashcomp(pre_cmds=("HOME=$PWD/cvs",))
class TestCvsps:
@pytest.mark.complete("cvsps -")
@pytest.mark.complete("cvsps -", require_cmd=True)
def test_1(self, completion):
assert completion

Expand Down
2 changes: 1 addition & 1 deletion test/t/test_deja_dup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@pytest.mark.bashcomp(cmd="deja-dup")
class TestDejaDup:
@pytest.mark.complete("deja-dup -")
@pytest.mark.complete("deja-dup -", require_cmd=True)
def test_1(self, completion):
assert completion

Expand Down
Loading

0 comments on commit 674dd80

Please sign in to comment.