Skip to content

Commit

Permalink
test: Fixture reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Jul 8, 2018
1 parent 2c32433 commit c677b8e
Show file tree
Hide file tree
Showing 32 changed files with 124 additions and 67 deletions.
2 changes: 1 addition & 1 deletion test/generate
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ marker=

if [[ $cmd == *.* ]]; then
file=${cmd//./-}
marker=$'\n'"@pytest.mark.command(\"$cmd\")"
marker=$'\n'"@pytest.mark.bashcomp("$'\n'" cmd=\"$cmd\","$'\n'")"
fi

name=$(python -c "import re,sys;print(re.sub('(^|[_-]+)(.)',lambda m:m.group(2).upper(),sys.argv[1]))" $file)
Expand Down
15 changes: 6 additions & 9 deletions test/t/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ def bash(request) -> pexpect.spawn:

# Use command name from marker if set, or grab from test filename
cmd = None
marker = request.node.get_marker("command")
marker = request.node.get_marker("bashcomp")
if marker:
if marker.args:
cmd = marker.args[0]
cmd = marker.kwargs.get("cmd")
# Run pre-test commands, early so they're usable in skipif
for pre_cmd in marker.kwargs.get("pre_cmds", []):
assert_bash_exec(bash, pre_cmd)
# Process skip conditions
skipif = marker.kwargs.get("skipif")
if skipif:
try:
Expand All @@ -69,12 +72,6 @@ def bash(request) -> pexpect.spawn:
if match:
cmd = match.group(1)

# Run pre-test commands
marker = request.node.get_marker("pre_commands")
if marker:
for pre_cmd in marker.args:
assert_bash_exec(bash, pre_cmd)

if is_testable(bash, cmd):
before_env = get_env(bash)
yield bash
Expand Down
6 changes: 4 additions & 2 deletions test/t/test_arch.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
'PATH=$PATH:/usr/lib/mailman/bin',
@pytest.mark.bashcomp(
pre_cmds=(
"PATH=/usr/lib/mailman/bin:$PATH",
),
)
class TestArch(object):

Expand Down
4 changes: 3 additions & 1 deletion test/t/test_btdownloadcurses-py.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest


@pytest.mark.command("btdownloadcurses.py")
@pytest.mark.bashcomp(
cmd="btdownloadcurses.py",
)
class TestBtdownloadcursesPy(object):

@pytest.mark.complete("btdownloadcurses.py ")
Expand Down
4 changes: 3 additions & 1 deletion test/t/test_btdownloadgui-py.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest


@pytest.mark.command("btdownloadgui.py")
@pytest.mark.bashcomp(
cmd="btdownloadgui.py",
)
class TestBtdownloadguiPy(object):

@pytest.mark.complete("btdownloadgui.py ")
Expand Down
4 changes: 3 additions & 1 deletion test/t/test_btdownloadheadless-py.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest


@pytest.mark.command("btdownloadheadless.py")
@pytest.mark.bashcomp(
cmd="btdownloadheadless.py",
)
class TestBtdownloadheadlessPy(object):

@pytest.mark.complete("btdownloadheadless.py ")
Expand Down
6 changes: 4 additions & 2 deletions test/t/test_change_pw.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
'PATH=$PATH:/usr/lib/mailman/bin',
@pytest.mark.bashcomp(
pre_cmds=(
"PATH=/usr/lib/mailman/bin:$PATH",
),
)
class TestChangePw(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_cleanarch.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
'PATH=$PATH:/usr/lib/mailman/bin',
@pytest.mark.bashcomp(
pre_cmds=(
"PATH=/usr/lib/mailman/bin:$PATH",
),
)
class TestCleanarch(object):

Expand Down
8 changes: 5 additions & 3 deletions test/t/test_configure.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import pytest


@pytest.mark.pre_commands(
# Make sure our own ./configure is in PATH
"PATH+=:$PWD/../..",
@pytest.mark.bashcomp(
pre_cmds=(
# Make sure our own ./configure is in PATH
"PATH=$PWD/../..:$PATH",
),
)
class TestConfigure(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_cvs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
"HOME=$PWD/cvs",
@pytest.mark.bashcomp(
pre_cmds=(
"HOME=$PWD/cvs",
),
)
class TestCvs(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_cvsps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
"HOME=$PWD/cvs",
@pytest.mark.bashcomp(
pre_cmds=(
"HOME=$PWD/cvs",
),
)
class TestCvsps(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_dumpdb.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
'PATH=$PATH:/usr/lib/mailman/bin',
@pytest.mark.bashcomp(
pre_cmds=(
"PATH=/usr/lib/mailman/bin:$PATH",
),
)
class TestDumpdb(object):

Expand Down
4 changes: 3 additions & 1 deletion test/t/test_flake8.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest


@pytest.mark.command(skipif="! flake8 --help &>/dev/null")
@pytest.mark.bashcomp(
skipif="! flake8 --help &>/dev/null",
)
class TestFlake8(object):

@pytest.mark.complete("flake8 ")
Expand Down
6 changes: 4 additions & 2 deletions test/t/test_genaliases.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
'PATH=$PATH:/usr/lib/mailman/bin',
@pytest.mark.bashcomp(
pre_cmds=(
"PATH=/usr/lib/mailman/bin:$PATH",
),
)
class TestGenaliases(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_hid2hci.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
'PATH=$PATH:/lib/udev',
@pytest.mark.bashcomp(
pre_cmds=(
"PATH=/lib/udev:$PATH",
),
)
class TestHid2hci(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_info.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
"INFOPATH+=:info:",
@pytest.mark.bashcomp(
pre_cmds=(
"INFOPATH+=:$PWD/info:",
),
)
class TestInfo(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_inject.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
'PATH=$PATH:/usr/lib/mailman/bin',
@pytest.mark.bashcomp(
pre_cmds=(
"PATH=/usr/lib/mailman/bin:$PATH",
),
)
class TestInject(object):

Expand Down
4 changes: 3 additions & 1 deletion test/t/test_invoke-rc-d.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest


@pytest.mark.command("invoke-rc.d")
@pytest.mark.bashcomp(
cmd="invoke-rc.d",
)
class TestInvokeRcD(object):

@pytest.mark.complete("invoke-rc.d ")
Expand Down
6 changes: 4 additions & 2 deletions test/t/test_isql.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
"ODBCINI=isql/odbc.ini",
@pytest.mark.bashcomp(
pre_cmds=(
"ODBCINI=isql/odbc.ini",
),
)
class TestIsql(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_java.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
'CLASSPATH=$PWD/java/a:$PWD/java/bashcomp.jar',
@pytest.mark.bashcomp(
pre_cmds=(
"CLASSPATH=$PWD/java/a:$PWD/java/bashcomp.jar",
),
)
class TestJava(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_list_owners.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
'PATH=$PATH:/usr/lib/mailman/bin',
@pytest.mark.bashcomp(
pre_cmds=(
"PATH=/usr/lib/mailman/bin:$PATH",
),
)
class TestListOwners(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_mailmanctl.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
'PATH=$PATH:/usr/lib/mailman/bin',
@pytest.mark.bashcomp(
pre_cmds=(
"PATH=/usr/lib/mailman/bin:$PATH",
),
)
class TestMailmanctl(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_mencoder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
"HOME=$PWD/mplayer",
@pytest.mark.bashcomp(
pre_cmds=(
"HOME=$PWD/mplayer",
),
)
class TestMencoder(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_mplayer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
"HOME=$PWD/mplayer",
@pytest.mark.bashcomp(
pre_cmds=(
"HOME=$PWD/mplayer",
),
)
class TestMplayer(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_perldoc.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
"export PERL5LIB=$PWD/perldoc",
@pytest.mark.bashcomp(
pre_cmds=(
"export PERL5LIB=$PWD/perldoc",
),
)
class TestPerldoc(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_pinfo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
"INFOPATH+=:info:",
@pytest.mark.bashcomp(
pre_cmds=(
"INFOPATH+=:$PWD/info:",
),
)
class TestPinfo(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_pkg_deinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import pytest


@pytest.mark.pre_commands(
"PKG_DBDIR=pkgtools/db",
@pytest.mark.bashcomp(
pre_cmds=(
"PKG_DBDIR=$PWD/pkgtools/db",
),
)
class TestPkgDeinstall(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_portupgrade.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
"PKG_DBDIR=$PWD/dbtools/db",
@pytest.mark.bashcomp(
pre_cmds=(
"PKG_DBDIR=$PWD/dbtools/db",
),
)
class TestPortupgrade(object):

Expand Down
6 changes: 4 additions & 2 deletions test/t/test_ri.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest


@pytest.mark.pre_commands(
'export RI="-d ri"',
@pytest.mark.bashcomp(
pre_cmds=(
"export RI='-d ri'",
),
)
class TestRi(object):

Expand Down
10 changes: 6 additions & 4 deletions test/t/test_ssh-copy-id.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import pytest


# Some old versions of ssh-copy-id won't output even usage if no
# identities are found. Try to make sure there is at least one.
@pytest.mark.pre_commands(
"HOME=$PWD/ssh-copy-id",
@pytest.mark.bashcomp(
pre_cmds=(
# Some old versions of ssh-copy-id won't output even usage if no
# identities are found. Try to make sure there is at least one.
"HOME=$PWD/ssh-copy-id",
),
)
class TestSshCopyId(object):

Expand Down
Loading

0 comments on commit c677b8e

Please sign in to comment.