|
| 1 | +import subprocess |
1 | 2 | from pathlib import Path |
2 | 3 |
|
3 | | -from util import PKG_NAME, assert_cmd |
| 4 | +import spin as libspin |
| 5 | +from spin.cmds.util import run |
4 | 6 |
|
5 | | -import spin |
| 7 | + |
| 8 | +def spin(*args): |
| 9 | + return run(["spin"] + list(args), stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
6 | 10 |
|
7 | 11 |
|
8 | 12 | def stdout(p): |
9 | 13 | return p.stdout.decode("utf-8").strip() |
10 | 14 |
|
11 | 15 |
|
12 | 16 | 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__}" |
15 | 19 |
|
16 | 20 |
|
17 | 21 | def test_basic_build(): |
18 | | - assert_cmd(["spin", "build"]) |
| 22 | + spin("build") |
19 | 23 |
|
| 24 | + assert Path("build").exists(), "`build` folder not created after `spin build`" |
20 | 25 | 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" |
25 | 27 | ).exists(), "`build-install` folder not created after `spin build`" |
26 | 28 |
|
27 | 29 |
|
28 | 30 | def test_debug_builds(): |
29 | | - assert_cmd(["spin", "build", "--gcov"]) |
| 31 | + spin("build", "--gcov") |
30 | 32 |
|
31 | | - debug_files = Path(PKG_NAME).rglob("*.gcno") |
| 33 | + debug_files = Path(".").rglob("*.gcno") |
32 | 34 | assert len(list(debug_files)) != 0, "debug files not generated for gcov build" |
33 | 35 |
|
34 | 36 |
|
35 | 37 | def test_expand_pythonpath(): |
36 | | - output = assert_cmd(["spin", "run", "echo $PYTHONPATH"]) |
| 38 | + output = spin("run", "echo $PYTHONPATH") |
37 | 39 | assert any( |
38 | 40 | p in stdout(output) for p in ("site-packages", "dist-packages") |
39 | 41 | ), f"Expected value of $PYTHONPATH, got {stdout(output)} instead" |
40 | 42 |
|
41 | 43 |
|
42 | 44 | 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__)", |
51 | 50 | ) |
52 | 51 | assert ( |
53 | 52 | stdout(p) == "0.0.0dev0" |
54 | 53 | ), 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