diff --git a/spin/tests/test_build_cmds.py b/spin/tests/test_build_cmds.py index f802618..dae17e5 100644 --- a/spin/tests/test_build_cmds.py +++ b/spin/tests/test_build_cmds.py @@ -4,41 +4,10 @@ import tempfile from pathlib import Path -import pytest +from testutil import skip_on_windows, skip_unless_linux, spin, stdout -import spin as libspin from spin.cmds.util import run -skip_on_windows = pytest.mark.skipif( - sys.platform.startswith("win"), reason="Skipped; platform is Windows" -) - -on_linux = pytest.mark.skipif( - not sys.platform.startswith("linux"), reason="Skipped; platform not Linux" -) - - -def spin(*args, **user_kwargs): - default_kwargs = { - "stdout": subprocess.PIPE, - "stderr": subprocess.PIPE, - "sys_exit": True, - } - return run(["spin"] + list(args), **{**default_kwargs, **user_kwargs}) - - -def stdout(p): - return p.stdout.decode("utf-8").strip() - - -def stderr(p): - return p.stderr.decode("utf-8").strip() - - -def test_get_version(): - p = spin("--version") - assert stdout(p) == f"spin {libspin.__version__}" - def test_basic_build(): """Does the package build?""" @@ -145,7 +114,7 @@ def test_spin_install(): run(["pip", "uninstall", "-y", "--quiet", "example_pkg"]) -@on_linux +@skip_unless_linux def test_gdb(): p = spin( "gdb", diff --git a/spin/tests/test_cli.py b/spin/tests/test_cli.py new file mode 100644 index 0000000..21f5c65 --- /dev/null +++ b/spin/tests/test_cli.py @@ -0,0 +1,17 @@ +from testutil import spin, stdout + +import spin as libspin + + +def test_get_version(): + p = spin("--version") + assert stdout(p) == f"spin {libspin.__version__}" + + +def test_arg_override(): + p = spin("example") + assert "--test is: default override" in stdout(p) + assert "Default kwd is: 3" in stdout(p) + + p = spin("example", "-t", 6) + assert "--test is: 6" in stdout(p) diff --git a/spin/tests/testutil.py b/spin/tests/testutil.py new file mode 100644 index 0000000..5595e2d --- /dev/null +++ b/spin/tests/testutil.py @@ -0,0 +1,32 @@ +import subprocess +import sys + +import pytest + +from spin.cmds.util import run + +skip_on_windows = pytest.mark.skipif( + sys.platform.startswith("win"), reason="Skipped; platform is Windows" +) + +skip_unless_linux = pytest.mark.skipif( + not sys.platform.startswith("linux"), reason="Skipped; platform not Linux" +) + + +def spin(*args, **user_kwargs): + args = (str(el) for el in args) + default_kwargs = { + "stdout": subprocess.PIPE, + "stderr": subprocess.PIPE, + "sys_exit": True, + } + return run(["spin"] + list(args), **{**default_kwargs, **user_kwargs}) + + +def stdout(p): + return p.stdout.decode("utf-8").strip() + + +def stderr(p): + return p.stderr.decode("utf-8").strip() diff --git a/spin/tests/util.py b/spin/tests/util.py deleted file mode 100644 index 09a3d63..0000000 --- a/spin/tests/util.py +++ /dev/null @@ -1,28 +0,0 @@ -import os -import subprocess - -from spin.cmds import util - -PKG_NAME = "example_pkg" - - -def assert_cmd(cmd, *args, **kwargs) -> str: - cwd = os.getcwd() - p = util.run( - cmd, - *args, - cwd=PKG_NAME, - replace=False, - sys_exit=False, - output=False, - echo=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - **kwargs, - ) - os.chdir(cwd) - stdout = p.stdout.decode("utf-8").strip() - if not p.returncode == 0: - print(stdout) - raise AssertionError(f"[{cmd}] failed with exit code {p.returncode}") - return p