-
Notifications
You must be signed in to change notification settings - Fork 5
✅ test: add tests & CI #18
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,96 @@ | ||
name: CI | ||
permissions: read-all | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
# Many color libraries just need this to be set to any value, but at least | ||
# one distinguishes color depth, where "3" -> "256-bit color". | ||
FORCE_COLOR: 3 | ||
jorenham marked this conversation as resolved.
Show resolved
Hide resolved
jorenham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
jobs: | ||
format: | ||
name: Format | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | ||
|
||
- name: Install uv | ||
uses: astral-sh/setup-uv@f0ec1fc3b38f5e7cd731bb6ce540c5af426746bb | ||
|
||
- name: Install the project | ||
run: uv sync --locked --group test | ||
|
||
- name: Run lefthook hooks | ||
run: uv run --frozen lefthook run pre-commit | ||
|
||
checks: | ||
name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }} | ||
runs-on: ${{ matrix.runs-on }} | ||
needs: [format] | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.11", "3.12", "3.13"] | ||
runs-on: [ubuntu-latest, macos-latest, windows-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | ||
|
||
- name: Install uv | ||
uses: astral-sh/setup-uv@f0ec1fc3b38f5e7cd731bb6ce540c5af426746bb | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install the project | ||
run: uv sync --locked --group test | ||
|
||
- name: Test package | ||
run: >- | ||
uv run --frozen pytest | ||
--cov --cov-report=xml --cov-report=term --durations=20 | ||
src docs tests | ||
|
||
- name: Upload coverage report | ||
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
check_oldest: | ||
name: Check Oldest Dependencies | ||
runs-on: ${{ matrix.runs-on }} | ||
needs: [format] | ||
jorenham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.11"] | ||
runs-on: [ubuntu-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | ||
|
||
- name: Install uv | ||
uses: astral-sh/setup-uv@f0ec1fc3b38f5e7cd731bb6ce540c5af426746bb | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install the project | ||
run: uv sync --locked --group test --resolution lowest-direct | ||
|
||
- name: Test package | ||
run: >- | ||
uv run --frozen pytest | ||
--cov --cov-report=xml --cov-report=term --durations=20 | ||
src docs tests | ||
|
||
- name: Upload coverage report | ||
uses: codecov/codecov-action@v18283e04ce6e62d37312384ff67231eb8fd56d24 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains hidden or 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,16 +1,18 @@ | ||
"""Pytest configuration file.""" | ||
|
||
from typing import Final | ||
|
||
from sybil import Sybil | ||
from sybil.parsers.doctest import DocTestParser | ||
|
||
readme_tester = Sybil( | ||
readme_tester: Final = Sybil( | ||
parsers=[DocTestParser()], | ||
pattern="README.md", | ||
) | ||
|
||
python_file_tester = Sybil( | ||
python_file_tester: Final = Sybil( | ||
parsers=[DocTestParser()], | ||
pattern="src/**/*.py", | ||
) | ||
|
||
pytest_collect_file = (readme_tester + python_file_tester).pytest() | ||
pytest_collect_file: Final = (readme_tester + python_file_tester).pytest() |
This file contains hidden or 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 hidden or 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 hidden or 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,6 +1,10 @@ | ||
"""Static typing support for the array API standard.""" | ||
|
||
__all__ = ["HasArrayNamespace", "__version__", "__version_tuple__"] | ||
__all__ = ( | ||
"HasArrayNamespace", | ||
"__version__", | ||
"__version_tuple__", | ||
) | ||
|
||
from ._namespace import HasArrayNamespace | ||
from ._version import version as __version__, version_tuple as __version_tuple__ |
This file contains hidden or 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 hidden or 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,42 @@ | ||
from types import SimpleNamespace | ||
from typing import Protocol, runtime_checkable | ||
|
||
import array_api_typing as xpt | ||
|
||
|
||
@runtime_checkable | ||
class CheckableHasArrayNamespace(xpt.HasArrayNamespace, Protocol): # type: ignore[misc] | ||
"""Runtime checkable version of HasArrayNamespace.""" | ||
|
||
|
||
class GoodArray: | ||
"""Example class that implements the HasArrayNamespace protocol.""" | ||
|
||
def __array_namespace__(self) -> object: # noqa: PLW3201 | ||
return SimpleNamespace() | ||
|
||
|
||
class BadArray: | ||
"""Example class that does not implement the HasArrayNamespace protocol.""" | ||
|
||
|
||
def test_has_namespace_class(): | ||
"""Test that GoodArray is a subclass of HasArrayNamespace.""" | ||
assert issubclass(GoodArray, CheckableHasArrayNamespace) | ||
|
||
|
||
def test_has_namespace_instance(): | ||
"""Test that an instance of GoodArray is recognized as HasArrayNamespace.""" | ||
x = GoodArray() | ||
assert isinstance(x, CheckableHasArrayNamespace) | ||
|
||
|
||
def test_not_has_namespace_class(): | ||
"""Test that BadArray is not a subclass of HasArrayNamespace.""" | ||
assert not issubclass(BadArray, CheckableHasArrayNamespace) | ||
|
||
|
||
def test_not_has_namespace_instance(): | ||
"""Test that an instance of BadArray is not recognized as HasArrayNamespace.""" | ||
y = BadArray() | ||
assert not isinstance(y, CheckableHasArrayNamespace) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.