Skip to content

Commit

Permalink
update test module ref
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Jul 29, 2024
1 parent 1d379cd commit 85c0fd6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
8 changes: 2 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "earcutx"
version = "1.0.3"
version = "1.0.4"
requires-python = ">=3.8"
authors = [{name = "Samuel Kogler", email = "[email protected]"}]
license = {file = "LICENSE.md"}
Expand Down Expand Up @@ -38,11 +38,7 @@ skip = "pp*"
test-extras = ["test"]

# Run the package tests using `pytest`
# also test against pre-release Numpy
# TODO : when numpy 2.0 releases this can be reduced to just one pytest
test-command = ["pytest {package}/tests",
"pip install --force-reinstall --upgrade --pre numpy",
"pytest {package}/tests"]
test-command = "pytest {package}/tests"

# don't test on PyPy as it will re-build numpy
test-skip = "*_arm64 *_universal2:arm64"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _get_version() -> str:

ext_modules = [
Pybind11Extension(
"mapbox_earcut",
"earcutx",
["src/main.cpp"],
include_dirs=["include"],
define_macros=[("VERSION_INFO", _get_version())],
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ py::array_t<IndexT> triangulate(py::array_t<CoordT> vertices, py::array_t<IndexT
);
}

PYBIND11_MODULE(mapbox_earcut, m)
PYBIND11_MODULE(earcutx, m)
{
m.doc() = R"pbdoc(
Python bindings to mapbox/earcut.hpp
-----------------------
.. currentmodule:: mapbox_earcut
.. currentmodule:: earcutx
.. autosummary::
:toctree: _generate
Expand Down
50 changes: 25 additions & 25 deletions tests/test_earcut.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mapbox_earcut as earcut
import earcutx
import numpy as np
import pytest

Expand All @@ -7,66 +7,66 @@ def test_valid_triangulation_float32():
verts = np.array([[0, 0], [1, 0], [1, 1]], dtype=np.float32).reshape(-1, 2)
rings = np.array([3])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.dtype == np.uint32
assert result.shape == (3, )
assert result.shape == (3,)
assert np.all(result == np.array([1, 2, 0]))


def test_valid_triangulation_float64():
verts = np.array([[0, 0], [1, 0], [1, 1]], dtype=np.float64).reshape(-1, 2)
rings = np.array([3])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.dtype == np.uint32
assert result.shape == (3, )
assert result.shape == (3,)
assert np.all(result == np.array([1, 2, 0]))


def test_valid_triangulation_int32():
verts = np.array([[0, 0], [1, 0], [1, 1]], dtype=np.int32).reshape(-1, 2)
rings = np.array([3])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.dtype == np.uint32
assert result.shape == (3, )
assert result.shape == (3,)
assert np.all(result == np.array([1, 2, 0]))


def test_inverted_vertex_order():
verts = np.array(
list(reversed([[0, 0], [1, 0], [1, 1]])), dtype=np.int32).reshape(
-1, 2)
verts = np.array(list(reversed([[0, 0], [1, 0], [1, 1]])), dtype=np.int32).reshape(
-1, 2
)
rings = np.array([3])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.dtype == np.uint32
assert result.shape == (3, )
assert result.shape == (3,)
assert np.all(result == np.array([1, 0, 2]))


def test_no_triangles():
verts = np.array([[0, 0], [1, 0], [1, 1]], dtype=np.int32).reshape(-1, 2)
rings = np.array([2, 3])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.dtype == np.uint32
assert result.shape == (0, )
assert result.shape == (0,)


def test_valid_triangulation_int64():
verts = np.array([[0, 0], [1, 0], [1, 1]], dtype=np.int64).reshape(-1, 2)
rings = np.array([3])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.dtype == np.uint32
assert result.shape == (3, )
assert result.shape == (3,)
assert np.all(result == np.array([1, 2, 0]))


Expand All @@ -75,61 +75,61 @@ def test_end_index_too_large():
rings = np.array([5])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)


def test_end_index_too_small():
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)
rings = np.array([2])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)


def test_end_index_neg():
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)
rings = np.array([-1])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)


def test_rings_not_increasing():
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)
rings = np.array([3, 0, 3])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)


def test_rings_same():
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)
rings = np.array([3, 3])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)


def test_no_rings():
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)
rings = np.array([])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)


def test_no_rings():
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)
rings = np.array([])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float64(verts, rings)


def test_empty_data():
verts = np.array([]).reshape(-1, 2)
rings = np.array([])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.shape == (0, )
assert result.shape == (0,)

0 comments on commit 85c0fd6

Please sign in to comment.