-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve source layout test discovery (#247)
- When `./tests` is present, try to test that instead of packagename - If src layout is used, there's no need to switch away from the source directory when testing - No longer use import-mode=importlib, which meant that packages could not do relative imports in tests
- Loading branch information
Showing
21 changed files
with
211 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
def echo(str) -> None: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.* export-ignore | ||
.spin -export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build | ||
build-install | ||
.mesonpy-native-file.ini | ||
dist/ | ||
doc/_build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
project( | ||
'spin-example-pkg', | ||
'c', | ||
version: '0.0.dev0', | ||
license: 'BSD-3', | ||
meson_version: '>= 0.64', | ||
default_options: [ | ||
'buildtype=debugoptimized', | ||
'c_std=c99', | ||
'cpp_std=c++14', | ||
], | ||
) | ||
|
||
cc = meson.get_compiler('c') | ||
|
||
py_mod = import('python') | ||
py = py_mod.find_installation(pure: false) | ||
py_dep = py.dependency() | ||
|
||
subdir('src') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[project] | ||
name = "example_pkg" | ||
version = "0.0dev0" | ||
requires-python = ">=3.7" | ||
description = "spin Example Package" | ||
|
||
[build-system] | ||
build-backend = "mesonpy" | ||
requires = [ | ||
"meson-python>=0.13.0rc0", | ||
] | ||
|
||
[tool.spin] | ||
package = 'example_pkg' | ||
|
||
[tool.spin.commands] | ||
"Build" = [ | ||
"spin.cmds.meson.build", | ||
"spin.cmds.meson.test" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from ._core import echo | ||
|
||
__all__ = ["echo"] | ||
__version__ = "0.0.0dev0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
def echo(str) -> None: ... |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#define PY_SSIZE_T_CLEAN | ||
#include <Python.h> | ||
|
||
static PyObject * | ||
core_echo(PyObject *self, PyObject *args) | ||
{ | ||
const char *str; | ||
PyObject *ret; | ||
|
||
if (!PyArg_ParseTuple(args, "s", &str)) | ||
return NULL; | ||
|
||
printf("%s\n", str); | ||
|
||
ret = PyLong_FromLong(42); | ||
Py_INCREF(ret); | ||
return ret; | ||
} | ||
|
||
static PyMethodDef CoreMethods[] = { | ||
{"echo", core_echo, METH_VARARGS, "Echo a string and return 42"}, | ||
{NULL, NULL, 0, NULL} /* Sentinel */ | ||
}; | ||
|
||
static struct PyModuleDef coremodule = { | ||
PyModuleDef_HEAD_INIT, | ||
"core", /* name of module */ | ||
NULL, /* module documentation, may be NULL */ | ||
-1, /* size of per-interpreter state of the module, | ||
or -1 if the module keeps state in global variables. */ | ||
CoreMethods | ||
}; | ||
|
||
PyMODINIT_FUNC | ||
PyInit__core(void) | ||
{ | ||
PyObject *m; | ||
|
||
m = PyModule_Create(&coremodule); | ||
if (m == NULL) | ||
return NULL; | ||
|
||
return m; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
py.extension_module( | ||
'_core', | ||
'coremodule.c', | ||
install: true, | ||
subdir: 'example_pkg' | ||
) | ||
|
||
python_sources = [ | ||
'__init__.py', | ||
'conftest.py' | ||
] | ||
|
||
py.install_sources( | ||
python_sources, | ||
subdir: 'example_pkg' | ||
) | ||
|
||
install_subdir('submodule', install_dir: py.get_install_dir() / 'example_pkg') |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def test_something(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from example_pkg import echo # type: ignore[attr-defined] | ||
|
||
|
||
def test_core(): | ||
ans = echo("hello world") | ||
assert ans == 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
from testutil import spin, stdout | ||
from .testutil import spin, stdout | ||
|
||
|
||
def test_detect_editable(editable_install): | ||
def test_detect_editable(example_pkg, editable_install): | ||
assert "Editable install of same source detected" in stdout( | ||
spin("build") | ||
), "Failed to detect and warn about editable install" | ||
|
||
|
||
def test_editable_tests(editable_install): | ||
def test_editable_tests(example_pkg, editable_install): | ||
spin("test") |
Oops, something went wrong.