Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI/Workflow: Use Hatch for the test suite #63

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ env:
PYTHONUNBUFFERED: "1"
FORCE_COLOR: "1"
PYTHONIOENCODING: "utf8"
PYAWAITABLE_OPTIMIZED: 1

jobs:
changes:
Expand Down Expand Up @@ -45,21 +44,18 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Build PyAwaitable
run: pip install . --verbose

- name: Build PyAwaitable Test Package
run: pip install ./tests --verbose

- name: Install Hatch
uses: pypa/hatch@install

- name: Run tests
run: python -W error -m unittest tests/main.py --verbose
run: hatch test

tests-pass:
runs-on: ubuntu-latest
Expand Down
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ To build PyAwaitable locally, simple run `pip`:
$ pip install .
```

It's highly recommended to do this inside of a [virtual environment](https://docs.python.org/3/library/venv.html).

## Running Tests

PyAwaitable uses [Hatch](https://hatch.pypa.io), so that will handle everything for you:
Expand Down
7 changes: 7 additions & 0 deletions hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ os.environ['PYAWAITABLE_INCLUDE'] = pyawaitable.include(suppress_error=True)
[build.hooks.custom]
enable-by-default = true
dependencies = ["typing_extensions"]

[envs.hatch-test]
dependencies = ["pyawaitable_test @ {root:uri}/tests", "pytest"]
default-args = ["--verbose"]

[[envs.hatch-test.matrix]]
python = ["3.13", "3.12", "3.11", "3.10", "3.9"]
25 changes: 13 additions & 12 deletions tests/main.py → tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any, Callable
from collections.abc import Awaitable, Coroutine
import inspect
from pytest import warns

NOT_FOUND = """
The PyAwaitable test package wasn't built!
Expand All @@ -13,16 +14,15 @@
except ImportError as err:
raise RuntimeError(NOT_FOUND) from err

class PyAwaitableTests(unittest.TestCase):
def test_awaitable_semantics(self):
awaitable = _pyawaitable_test.generic_awaitable(None)
self.assertIsInstance(awaitable, Awaitable)
self.assertIsInstance(awaitable, Coroutine)
# It's not a *native* coroutine
self.assertFalse(inspect.iscoroutine(awaitable))
def test_awaitable_semantics():
awaitable = _pyawaitable_test.generic_awaitable(None)
assert isinstance(awaitable, Awaitable)
assert isinstance(awaitable, Coroutine)
# It's not a *native* coroutine
assert inspect.iscoroutine(awaitable) is False

with self.assertWarns(ResourceWarning):
del awaitable
with warns(ResourceWarning):
del awaitable

def coro_wrap_call(method: Callable[[Awaitable[Any]], Any]) -> Callable[[], None]:
def wrapper(*_: Any):
Expand All @@ -35,11 +35,12 @@ async def dummy():

for method in dir(_pyawaitable_test):
if method.startswith("test_"):
test_case = getattr(_pyawaitable_test, method)
case = getattr(_pyawaitable_test, method)
if method.endswith("needs_coro"):
setattr(PyAwaitableTests, method.rstrip("_needs_coro"), coro_wrap_call(test_case))
globals()[method.rstrip("_needs_coro")] = coro_wrap_call(case)
else:
setattr(PyAwaitableTests, method, test_case)
# Wrap it with a Python function for pytest
globals()[method] = lambda: case()

if __name__ == "__main__":
unittest.main()