Skip to content

Commit 238680e

Browse files
committed
Simplify test framework; add test_editable_conflict
1 parent 4fb7418 commit 238680e

4 files changed

Lines changed: 35 additions & 41 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ jobs:
2929
run: |
3030
sudo apt-get update
3131
sudo apt-get install -y gdb
32-
# - name: Tests Old
33-
# run: |
34-
# pipx run nox --forcecolor -s tests_old_sh
3532
- name: Tests PyTest
3633
run: |
37-
pipx run nox --forcecolor -s tests_pytest
34+
pipx run nox --forcecolor -s test

noxfile.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22

33

44
@nox.session
5-
def tests_old_sh(session: nox.Session) -> None:
6-
"""
7-
[TBD DEPCRECATED]Run the unit and regular tests.
8-
"""
9-
session.install(".", "pytest", "build")
10-
session.run("bash", ".github/workflows/test.sh", external=True)
11-
12-
13-
@nox.session
14-
def tests_pytest(session: nox.Session) -> None:
15-
"""
16-
[TBD DEPCRECATED]Run the unit and regular tests.
17-
"""
5+
def test(session: nox.Session) -> None:
186
session.install(".", "pytest", "build", "meson-python", "ninja")
197
session.run("pytest", "spin", *session.posargs)

spin/tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22

33
import pytest
4-
from util import PKG_NAME
54

65
from spin import util
76

@@ -10,11 +9,12 @@
109
def pre_post_test():
1110
# Pre-test code
1211
cwd = os.getcwd()
12+
os.chdir("example_pkg")
1313

1414
try:
1515
yield
16-
17-
# Post test code
18-
util.run(["git", "clean", "-xdf"], cwd=PKG_NAME)
1916
finally:
17+
# Post test code
18+
os.chdir(cwd)
19+
util.run(["git", "clean", "-xdf"], cwd="example_pkg")
2020
os.chdir(cwd)

spin/tests/test_build_cmds.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,63 @@
1+
import subprocess
12
from pathlib import Path
23

3-
from util import PKG_NAME, assert_cmd
4+
import spin as libspin
5+
from spin.cmds.util import run
46

5-
import spin
7+
8+
def spin(*args):
9+
return run(["spin"] + list(args), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
610

711

812
def stdout(p):
913
return p.stdout.decode("utf-8").strip()
1014

1115

1216
def test_get_version():
13-
p = assert_cmd(["spin", "--version"])
14-
assert stdout(p) == f"spin {spin.__version__}"
17+
p = spin("--version")
18+
assert stdout(p) == f"spin {libspin.__version__}"
1519

1620

1721
def test_basic_build():
18-
assert_cmd(["spin", "build"])
22+
spin("build")
1923

24+
assert Path("build").exists(), "`build` folder not created after `spin build`"
2025
assert Path(
21-
PKG_NAME, "build"
22-
).exists(), "`build` folder not created after `spin build`"
23-
assert Path(
24-
PKG_NAME, "build-install"
26+
"build-install"
2527
).exists(), "`build-install` folder not created after `spin build`"
2628

2729

2830
def test_debug_builds():
29-
assert_cmd(["spin", "build", "--gcov"])
31+
spin("build", "--gcov")
3032

31-
debug_files = Path(PKG_NAME).rglob("*.gcno")
33+
debug_files = Path(".").rglob("*.gcno")
3234
assert len(list(debug_files)) != 0, "debug files not generated for gcov build"
3335

3436

3537
def test_expand_pythonpath():
36-
output = assert_cmd(["spin", "run", "echo $PYTHONPATH"])
38+
output = spin("run", "echo $PYTHONPATH")
3739
assert any(
3840
p in stdout(output) for p in ("site-packages", "dist-packages")
3941
), f"Expected value of $PYTHONPATH, got {stdout(output)} instead"
4042

4143

4244
def test_run_stdout():
43-
p = assert_cmd(
44-
[
45-
"spin",
46-
"run",
47-
"python",
48-
"-c",
49-
"import sys; del sys.path[0]; import example_pkg; print(example_pkg.__version__)",
50-
]
45+
p = spin(
46+
"run",
47+
"python",
48+
"-c",
49+
"import sys; del sys.path[0]; import example_pkg; print(example_pkg.__version__)",
5150
)
5251
assert (
5352
stdout(p) == "0.0.0dev0"
5453
), f"`spin run` stdout did not yield version, but {stdout(p)}"
54+
55+
56+
def test_editable_conflict():
57+
try:
58+
run(["pip", "install", "--quiet", "-e", "."])
59+
assert "Warning! An editable installation" in stdout(
60+
spin("run", "ls")
61+
), "Failed to detect and warn about editable install"
62+
finally:
63+
run(["pip", "uninstall", "--quiet", "-y", "example_pkg"])

0 commit comments

Comments
 (0)