diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..ed7efc7 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,45 @@ +name: Tests + +on: + push: + branches: + - master + pull_request: + branches: + - master + +concurrency: + group: test-${{ github.head_ref }} + cancel-in-progress: true + +env: + PYTHONUNBUFFERED: "1" + FORCE_COLOR: "1" + PYTHONIOENCODING: "utf8" + +jobs: + run: + name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-12] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Ward + run: pip install --upgrade --pre ward + + - name: Install project + run: pip install . + + - name: Run tests + run: ward diff --git a/setup.py b/setup.py index ac33c0b..6d821fd 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,5 @@ from setuptools import Extension, setup -HEADER_FILES: list[str] = ["./include/awaitable.h"] - if __name__ == "__main__": setup( ext_modules=[ @@ -12,5 +10,5 @@ define_macros=[("PYAWAITABLE_IS_COMPILING", None)], ) ], - data_files=[("include", HEADER_FILES)], + data_files=[("include", ["./include/awaitable.h"])], ) diff --git a/src/awaitable.c b/src/awaitable.c index 11d54f4..e952600 100644 --- a/src/awaitable.c +++ b/src/awaitable.c @@ -2,10 +2,9 @@ // This code follows PEP 7 and CPython ABI conventions #include #include "pyerrors.h" -#include #include #include - +#include #ifndef _PyObject_Vectorcall #define PyObject_CallNoArgs(o) PyObject_CallObject( \ @@ -471,7 +470,7 @@ awaitable_throw(PyObject *self, PyObject *args) assert(NULL); } -#if PY_MINOR_VERSION > 8 +#if PY_MINOR_VERSION > 9 static PySendResult awaitable_am_send(PyObject *self, PyObject *arg, PyObject **presult) { PyObject *send_res = awaitable_send_with_arg(self, arg); @@ -505,7 +504,7 @@ static PyMethodDef awaitable_methods[] = { }; static PyAsyncMethods async_methods = { - #if PY_MINOR_VERSION == 8 + #if PY_MINOR_VERSION < 10 .am_await = awaitable_next #else .am_await = awaitable_next, diff --git a/tests/test_awaitable.py b/tests/test_awaitable.py new file mode 100644 index 0000000..f1a7618 --- /dev/null +++ b/tests/test_awaitable.py @@ -0,0 +1,12 @@ +from ward import test +import pyawaitable +import ctypes as ct +from ctypes import pythonapi + +get_pointer = pythonapi.PyCapsule_GetPointer +get_pointer.argtypes = (ct.py_object, ct.c_void_p) +get_pointer.restype = ct.c_void_p + +@test("awaitable creation") +async def _(): + ptr = get_pointer(pyawaitable._api, None)