-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tests for Python package; bump min Python version; run in CI
- Loading branch information
Showing
5 changed files
with
229 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Python tests | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
name: Python tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install uv | ||
uses: astral-sh/setup-uv@v3 | ||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version-file: crates/pyaugurs/pyproject.toml | ||
- name: Build wheel | ||
uses: PyO3/maturin-action@v1 | ||
with: | ||
command: develop | ||
target: x86_64 | ||
args: --uv --manifest-path crates/pyaugurs/Cargo.toml | ||
sccache: 'true' | ||
- name: Install deps | ||
run: uv sync --all-extras --dev | ||
- name: Run tests | ||
run: uv run pytest crates/pyaugurs/tests |
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 +1,2 @@ | ||
.python-version | ||
__pycache__ |
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,48 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from augurs import Dtw | ||
|
||
|
||
class TestDtw: | ||
@pytest.mark.parametrize( | ||
"opts, input, expected", | ||
[ | ||
({}, [[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]], 5.0990195135926845), | ||
({"window": 2}, [[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]], 5.0990195135926845), | ||
({"distance_fn": "euclidean"}, [[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]], 5.0990195135926845), | ||
({"distance_fn": "manhattan"}, [[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]], 9), | ||
], | ||
) | ||
def test_distance(self, opts, input, expected): | ||
d = Dtw(**opts) | ||
arrays = [np.array(x) for x in input] | ||
np.testing.assert_allclose(d.distance(*arrays), expected) | ||
|
||
@pytest.mark.parametrize( | ||
"opts, input, expected", | ||
[ | ||
( | ||
{}, | ||
[[0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0]], | ||
[ | ||
[0.0, 5.0990195135926845, 10.392304845413264], | ||
[5.0990195135926845, 0.0, 5.0990195135926845], | ||
[10.392304845413264, 5.0990195135926845, 0.0], | ||
] | ||
), | ||
( | ||
{"distance_fn": "manhattan"}, | ||
[[0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0]], | ||
[ | ||
[0.0, 9.0, 18.0], | ||
[9.0, 0.0, 9.0], | ||
[18.0, 9.0, 0.0], | ||
] | ||
), | ||
], | ||
) | ||
def test_distance_matrix(self, opts, input, expected): | ||
d = Dtw(**opts) | ||
arrays = [np.array(x) for x in input] | ||
np.testing.assert_allclose(d.distance_matrix(arrays).to_numpy(), expected) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.