Skip to content

Commit 86b5db4

Browse files
committed
Advise to use spin run python when doing spin run foo.py
1 parent 238680e commit 86b5db4

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

spin/tests/test_build_cmds.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,42 @@
11
import subprocess
2+
import sys
3+
import tempfile
24
from pathlib import Path
35

6+
import pytest
7+
48
import spin as libspin
59
from spin.cmds.util import run
610

11+
skip_on_windows = pytest.mark.skipif(
12+
sys.platform.startswith("win"), reason="Skipped on Windows"
13+
)
14+
715

816
def spin(*args):
9-
return run(["spin"] + list(args), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
17+
return run(
18+
["spin"] + list(args),
19+
stdout=subprocess.PIPE,
20+
stderr=subprocess.PIPE,
21+
sys_exit=False,
22+
)
1023

1124

1225
def stdout(p):
1326
return p.stdout.decode("utf-8").strip()
1427

1528

29+
def stderr(p):
30+
return p.stderr.decode("utf-8").strip()
31+
32+
1633
def test_get_version():
1734
p = spin("--version")
1835
assert stdout(p) == f"spin {libspin.__version__}"
1936

2037

2138
def test_basic_build():
39+
"""Does the package build?"""
2240
spin("build")
2341

2442
assert Path("build").exists(), "`build` folder not created after `spin build`"
@@ -28,20 +46,23 @@ def test_basic_build():
2846

2947

3048
def test_debug_builds():
49+
"""Does spin generate gcov debug output files?"""
3150
spin("build", "--gcov")
3251

3352
debug_files = Path(".").rglob("*.gcno")
3453
assert len(list(debug_files)) != 0, "debug files not generated for gcov build"
3554

3655

3756
def test_expand_pythonpath():
57+
"""Does an $ENV_VAR get expanded in `spin run`?"""
3858
output = spin("run", "echo $PYTHONPATH")
3959
assert any(
4060
p in stdout(output) for p in ("site-packages", "dist-packages")
4161
), f"Expected value of $PYTHONPATH, got {stdout(output)} instead"
4262

4363

4464
def test_run_stdout():
65+
"""Ensure `spin run` only includes command output on stdout."""
4566
p = spin(
4667
"run",
4768
"python",
@@ -54,10 +75,23 @@ def test_run_stdout():
5475

5576

5677
def test_editable_conflict():
78+
"""Do we warn when a conflicting editable install is present?"""
5779
try:
5880
run(["pip", "install", "--quiet", "-e", "."])
5981
assert "Warning! An editable installation" in stdout(
6082
spin("run", "ls")
6183
), "Failed to detect and warn about editable install"
6284
finally:
6385
run(["pip", "uninstall", "--quiet", "-y", "example_pkg"])
86+
87+
88+
# Detecting whether a file is executable is not that easy on Windows,
89+
# as it seems to take into consideration whether that file is associated as an executable.
90+
@skip_on_windows
91+
def test_recommend_run_python():
92+
"""If `spin run file.py` is called, is `spin run python file.py` recommended?"""
93+
with tempfile.NamedTemporaryFile(suffix=".py") as f:
94+
p = spin("run", f.name)
95+
assert "Did you mean to call" in stdout(
96+
p
97+
), "Failed to recommend `python run python file.py`"

0 commit comments

Comments
 (0)