|
| 1 | +import os |
1 | 2 | import subprocess |
2 | 3 | import sys |
3 | 4 | import tempfile |
|
9 | 10 | from spin.cmds.util import run |
10 | 11 |
|
11 | 12 | skip_on_windows = pytest.mark.skipif( |
12 | | - sys.platform.startswith("win"), reason="Skipped on Windows" |
| 13 | + sys.platform.startswith("win"), reason="Skipped; platform is Windows" |
13 | 14 | ) |
14 | 15 |
|
| 16 | +on_linux = pytest.mark.skipif( |
| 17 | + not sys.platform.startswith("linux"), reason="Skipped; platform not Linux" |
| 18 | +) |
15 | 19 |
|
16 | | -def spin(*args): |
17 | | - return run( |
18 | | - ["spin"] + list(args), |
19 | | - stdout=subprocess.PIPE, |
20 | | - stderr=subprocess.PIPE, |
21 | | - sys_exit=False, |
22 | | - ) |
| 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}) |
23 | 28 |
|
24 | 29 |
|
25 | 30 | def stdout(p): |
@@ -91,7 +96,60 @@ def test_editable_conflict(): |
91 | 96 | def test_recommend_run_python(): |
92 | 97 | """If `spin run file.py` is called, is `spin run python file.py` recommended?""" |
93 | 98 | with tempfile.NamedTemporaryFile(suffix=".py") as f: |
94 | | - p = spin("run", f.name) |
| 99 | + p = spin("run", f.name, sys_exit=False) |
95 | 100 | assert "Did you mean to call" in stdout( |
96 | 101 | p |
97 | 102 | ), "Failed to recommend `python run python file.py`" |
| 103 | + |
| 104 | + |
| 105 | +def test_test(): |
| 106 | + """Does the test command run?""" |
| 107 | + spin("test") |
| 108 | + |
| 109 | + |
| 110 | +def test_test_with_pythonpath(): |
| 111 | + """Does `spin test` work when PYTHONPATH is set?""" |
| 112 | + spin("test", env={**os.environ, "PYTHONPATH": "/tmp"}) |
| 113 | + |
| 114 | + |
| 115 | +def test_sdist(): |
| 116 | + spin("sdist") |
| 117 | + |
| 118 | + |
| 119 | +def test_example(): |
| 120 | + spin("example") |
| 121 | + |
| 122 | + |
| 123 | +def test_docs(): |
| 124 | + run(["pip", "install", "--quiet", "sphinx"]) |
| 125 | + spin("docs") |
| 126 | + |
| 127 | + |
| 128 | +def test_spin_install(): |
| 129 | + cwd = os.getcwd() |
| 130 | + spin("install") |
| 131 | + try: |
| 132 | + with tempfile.TemporaryDirectory() as d: |
| 133 | + os.chdir(d) |
| 134 | + p = run( |
| 135 | + ["python", "-c", "import example_pkg; print(example_pkg.__version__)"], |
| 136 | + stdout=subprocess.PIPE, |
| 137 | + ) |
| 138 | + assert stdout(p) == "0.0.0dev0" |
| 139 | + finally: |
| 140 | + os.chdir(cwd) |
| 141 | + run(["pip", "uninstall", "-y", "--quiet", "example_pkg"]) |
| 142 | + |
| 143 | + |
| 144 | +@on_linux |
| 145 | +def test_gdb(): |
| 146 | + p = spin( |
| 147 | + "gdb", |
| 148 | + "-c", |
| 149 | + 'import example_pkg; example_pkg.echo("hi")', |
| 150 | + "--", |
| 151 | + "--eval", |
| 152 | + "run", |
| 153 | + "--batch", |
| 154 | + ) |
| 155 | + assert "hi" in stdout(p) |
0 commit comments