Skip to content
Draft
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
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,23 @@ select = [
"I", # isort
"UP", # pyupgrade
]

[tool.coverage.run]
branch = true
source = [
"src/clump_tracker",
"tests",
"src"
]

[tool.coverage.report]
show_missing = true
skip_covered = false

# use exclude_also to *extend* the default exclude_lines,
# and allow purely defensive code patterns
exclude_also = [
"^\\s*raise NotImplementedError\\b",
"^\\s*raise RuntimeError\\b",
"^\\s*case _ as unreachable:",
]
26 changes: 14 additions & 12 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@
from clump_tracker import gradient


def test_tests():
assert True
@pytest.fixture(params=[np.float32, np.float64, float])
def dtype(request):
return request.param


def _dtype():
return "dtype", [float, np.float32, np.float64]
@pytest.fixture(params=[0, 1, 2])
def axis(request):
return request.param


@pytest.mark.xfail
def test_gradient_unsupported_type():
field = np.arange(10, dtype=int) + 5
x = np.arange(10, dtype=int)
axis = 0
gradient(field, x, axis)


@pytest.mark.parametrize(*_dtype())
def test_gradient_1D_uniform(dtype):
field = np.arange(10, dtype=dtype) + 5
x = np.arange(10, dtype=dtype)
axis = 0
assert_array_equal(gradient(field, x, axis), np.gradient(field, x, axis=axis))


@pytest.mark.parametrize(*_dtype())
def test_gradient_1D_non_uniform(dtype):
field = np.arange(10, dtype=float) + 5
axis = 0
Expand All @@ -33,18 +41,12 @@ def test_gradient_1D_non_uniform(dtype):
)


def _dtype_and_axis():
return "axis,dtype", product(range(3), [float, np.float32, np.float64])


@pytest.mark.parametrize(*_dtype_and_axis())
def test_gradient_3D_uniform(axis, dtype):
field = np.arange(9 * 10 * 11, dtype=dtype).reshape((9, 10, 11)) + 5
x = np.arange(field.shape[axis], dtype=dtype)
assert_array_equal(gradient(field, x, axis), np.gradient(field, x, axis=axis))


@pytest.mark.parametrize(*_dtype_and_axis())
def test_gradient_3D_non_uniform(axis, dtype):
field = np.arange(9 * 10 * 11, dtype=dtype).reshape((9, 10, 11)) + 5
x = np.geomspace(1, 10, field.shape[axis], dtype=dtype)
Expand Down
22 changes: 21 additions & 1 deletion tests/test_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _compute_cc_from_list_ref(indexes, x, y, z, max_distance):
adj = _compute_adjacency_list_cartesian_ref(indexes, x, y, z, max_distance)

# ajoute les voisins de p0 dans a_visiter
for i, _ in enumerate(indexes):
for i, _ in enumerate(indexes): # pragma: no branch
if not deja_vus[i]:
composante_connexes.append([i])
a_visiter = np.array([k in adj[i] for k in range(len(indexes))], dtype=bool)
Expand Down Expand Up @@ -172,6 +172,15 @@ def test_adjacency_list(indexes, dtype):
) == _compute_adjacency_list_cartesian_ref(indexes, x, y, z, 1.0)


@pytest.mark.xfail
def test_adjacency_list_unsupported_type(indexes):
x = np.linspace(0, 10, 50, dtype=int)
y = np.linspace(0, 5, 20, dtype=int)
z = np.linspace(0, 1, 5, dtype=int)

compute_adjacency_list_cartesian(indexes, x, y, z, 1.0)


def test_cc_cartesian(cc_params, dtype):
indexes = [[i, 0, 0] for i in range(3)]
x = np.array([0, 1, 10], dtype=dtype)
Expand All @@ -181,3 +190,14 @@ def test_cc_cartesian(cc_params, dtype):

actual = compute_cc(indexes, x, y, z, d, "cartesian")
assert actual == expected


@pytest.mark.xfail
def test_cc_cartesian_unsupported_type(cc_params):
indexes = [[i, 0, 0] for i in range(3)]
x = np.array([0, 1, 10], dtype=int)
y = np.array([0], dtype=int)
z = np.array([0], dtype=int)
d, expected = cc_params

compute_cc(indexes, x, y, z, d, "cartesian")
6 changes: 6 additions & 0 deletions tests/test_clump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from clump_tracker.clumps import Clump


def test_clump():
c = Clump(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7, 8.0, 9.0)
assert c.coords == (0.0, 1.0, 2.0)