Skip to content

Commit

Permalink
Add tests for kwd/flag override
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanv committed Mar 23, 2024
1 parent b5a8ff5 commit 32b9eaf
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 61 deletions.
35 changes: 2 additions & 33 deletions spin/tests/test_build_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?"""
Expand Down Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions spin/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -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)
32 changes: 32 additions & 0 deletions spin/tests/testutil.py
Original file line number Diff line number Diff line change
@@ -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()
28 changes: 0 additions & 28 deletions spin/tests/util.py

This file was deleted.

0 comments on commit 32b9eaf

Please sign in to comment.