From 2e15fdddfd9e44c07d573d18a7e12e914036dbde Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Mon, 18 May 2020 10:42:13 +0200 Subject: [PATCH] change to new test engine --- test/14_before_all/setup.py | 19 -------- test/14_before_all/spam.c | 48 ------------------- ...ibuildwheel_test.py => test_before_all.py} | 21 ++++++-- 3 files changed, 18 insertions(+), 70 deletions(-) delete mode 100644 test/14_before_all/setup.py delete mode 100644 test/14_before_all/spam.c rename test/{14_before_all/cibuildwheel_test.py => test_before_all.py} (54%) diff --git a/test/14_before_all/setup.py b/test/14_before_all/setup.py deleted file mode 100644 index bdcadcaa..00000000 --- a/test/14_before_all/setup.py +++ /dev/null @@ -1,19 +0,0 @@ -from setuptools import ( - Extension, - setup, -) - -# assert that the Python version as written to text_info.txt in the CIBW_BEFORE_ALL step -# is the same one as is currently running. -with open("text_info.txt") as f: - stored_text = f.read() - -print("## stored text: " + stored_text) -assert stored_text == "sample text 123" - - -setup( - name="spam", - ext_modules=[Extension('spam', sources=['spam.c'])], - version="0.1.0", -) diff --git a/test/14_before_all/spam.c b/test/14_before_all/spam.c deleted file mode 100644 index d1ab0f22..00000000 --- a/test/14_before_all/spam.c +++ /dev/null @@ -1,48 +0,0 @@ -#include - -static PyObject * -spam_system(PyObject *self, PyObject *args) -{ - const char *command; - int sts; - - if (!PyArg_ParseTuple(args, "s", &command)) - return NULL; - sts = system(command); - return PyLong_FromLong(sts); -} - -/* Module initialization */ - -#if PY_MAJOR_VERSION >= 3 - #define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) - #define MOD_DEF(m, name, doc, methods, module_state_size) \ - static struct PyModuleDef moduledef = { \ - PyModuleDef_HEAD_INIT, name, doc, module_state_size, methods, }; \ - m = PyModule_Create(&moduledef); - #define MOD_RETURN(m) return m; -#else - #define MOD_INIT(name) PyMODINIT_FUNC init##name(void) - #define MOD_DEF(m, name, doc, methods, module_state_size) \ - m = Py_InitModule3(name, methods, doc); - #define MOD_RETURN(m) return; -#endif - -static PyMethodDef module_methods[] = { - {"system", (PyCFunction)spam_system, METH_VARARGS, - "Execute a shell command."}, - {NULL} /* Sentinel */ -}; - -MOD_INIT(spam) -{ - PyObject* m; - - MOD_DEF(m, - "spam", - "Example module", - module_methods, - -1) - - MOD_RETURN(m) -} diff --git a/test/14_before_all/cibuildwheel_test.py b/test/test_before_all.py similarity index 54% rename from test/14_before_all/cibuildwheel_test.py rename to test/test_before_all.py index 1b7c8d03..177ec555 100644 --- a/test/14_before_all/cibuildwheel_test.py +++ b/test/test_before_all.py @@ -1,10 +1,25 @@ import os +import textwrap -import utils +from . import utils +from . import test_projects + +project_with_before_build_asserts = test_projects.new_c_project( + setup_py_add=textwrap.dedent(r''' + # assert that the Python version as written to text_info.txt in the CIBW_BEFORE_ALL step + # is the same one as is currently running. + with open("text_info.txt") as f: + stored_text = f.read() + + print("## stored text: " + stored_text) + assert stored_text == "sample text 123" + ''') +) -def test(): - project_dir = os.path.dirname(__file__) +def test(tmp_path): + project_dir = tmp_path / 'project' + project_with_before_build_asserts.generate(project_dir) with open(os.path.join(project_dir, "text_info.txt"), mode='w') as ff: print("dummy text", file=ff)