Skip to content

Commit b1f93a1

Browse files
committed
Add tests for kwd/flag override
1 parent f8207b2 commit b1f93a1

File tree

4 files changed

+51
-61
lines changed

4 files changed

+51
-61
lines changed

spin/tests/test_build_cmds.py

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,10 @@
44
import tempfile
55
from pathlib import Path
66

7-
import pytest
7+
from testutil import skip_on_windows, skip_unless_linux, spin, stdout
88

9-
import spin as libspin
109
from spin.cmds.util import run
1110

12-
skip_on_windows = pytest.mark.skipif(
13-
sys.platform.startswith("win"), reason="Skipped; platform is Windows"
14-
)
15-
16-
on_linux = pytest.mark.skipif(
17-
not sys.platform.startswith("linux"), reason="Skipped; platform not Linux"
18-
)
19-
20-
21-
def spin(*args, **user_kwargs):
22-
default_kwargs = {
23-
"stdout": subprocess.PIPE,
24-
"stderr": subprocess.PIPE,
25-
"sys_exit": True,
26-
}
27-
return run(["spin"] + list(args), **{**default_kwargs, **user_kwargs})
28-
29-
30-
def stdout(p):
31-
return p.stdout.decode("utf-8").strip()
32-
33-
34-
def stderr(p):
35-
return p.stderr.decode("utf-8").strip()
36-
37-
38-
def test_get_version():
39-
p = spin("--version")
40-
assert stdout(p) == f"spin {libspin.__version__}"
41-
4211

4312
def test_basic_build():
4413
"""Does the package build?"""
@@ -145,7 +114,7 @@ def test_spin_install():
145114
run(["pip", "uninstall", "-y", "--quiet", "example_pkg"])
146115

147116

148-
@on_linux
117+
@skip_unless_linux
149118
def test_gdb():
150119
p = spin(
151120
"gdb",

spin/tests/test_cli.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from testutil import spin, stdout
2+
3+
import spin as libspin
4+
5+
6+
def test_get_version():
7+
p = spin("--version")
8+
assert stdout(p) == f"spin {libspin.__version__}"
9+
10+
11+
def test_arg_override():
12+
p = spin("example")
13+
assert "--test is: default override" in stdout(p)
14+
assert "Default kwd is: 3" in stdout(p)
15+
16+
p = spin("example", "-t", 6)
17+
assert "--test is: 6" in stdout(p)

spin/tests/testutil.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import subprocess
2+
import sys
3+
4+
import pytest
5+
6+
from spin.cmds.util import run
7+
8+
skip_on_windows = pytest.mark.skipif(
9+
sys.platform.startswith("win"), reason="Skipped; platform is Windows"
10+
)
11+
12+
skip_unless_linux = pytest.mark.skipif(
13+
not sys.platform.startswith("linux"), reason="Skipped; platform not Linux"
14+
)
15+
16+
17+
def spin(*args, **user_kwargs):
18+
args = (str(el) for el in args)
19+
default_kwargs = {
20+
"stdout": subprocess.PIPE,
21+
"stderr": subprocess.PIPE,
22+
"sys_exit": True,
23+
}
24+
return run(["spin"] + list(args), **{**default_kwargs, **user_kwargs})
25+
26+
27+
def stdout(p):
28+
return p.stdout.decode("utf-8").strip()
29+
30+
31+
def stderr(p):
32+
return p.stderr.decode("utf-8").strip()

spin/tests/util.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)