Skip to content
Merged
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
6 changes: 4 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def pytest_make_parametrize_id(config, val, argname):
elif isinstance(val, nullcontext):
optional_string = "does_not_raise()"

if isinstance(optional_string, str) and len(optional_string) > MAX_SIZE:
optional_string = optional_string[: MAX_SIZE - 3] + "+++" # Can't use dots with pytest
if isinstance(optional_string, str):
optional_string = optional_string.replace("\n", " ")
if len(optional_string) > MAX_SIZE:
optional_string = optional_string[: MAX_SIZE - 3] + "+++" # Can't use dots with pytest

return optional_string
3 changes: 2 additions & 1 deletion tests/unit/aggregation/test_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
TrimmedMean,
UPGrad,
UPGradWeighting,
Weighting,
)

J_base = tensor([[-4.0, 1.0, 1.0], [6.0, 1.0, 1.0]])
Expand Down Expand Up @@ -116,7 +117,7 @@ def test_aggregator_output(A: Aggregator, J: Tensor, expected_output: Tensor):


@mark.parametrize(["W", "G", "expected_output"], WEIGHTING_PARAMETRIZATIONS)
def test_weighting_output(W: Aggregator, G: Tensor, expected_output: Tensor):
def test_weighting_output(W: Weighting, G: Tensor, expected_output: Tensor):
"""Test that the output values of a weighting are fixed (on cpu)."""

assert_close(W(G), expected_output, rtol=0, atol=1e-4)
8 changes: 5 additions & 3 deletions tests/unit/autogram/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,13 @@ def test_compute_gramian_various_output_shapes(
assert_close(autogram_gramian, expected_gramian, rtol=1e-4, atol=1e-5)


def _non_empty_subsets(elements: set) -> list[set]:
def _non_empty_subsets(S: set) -> list[list]:
"""
Generates the list of subsets of the given set, excluding the empty set.
Generates the list of subsets of the given set, excluding the empty set. The sets are returned
in the form of sorted lists so that the order is always the same, to make the parametrization of
the test reproducible.
"""
return [set(c) for r in range(1, len(elements) + 1) for c in combinations(elements, r)]
return [sorted(set(c)) for r in range(1, len(S) + 1) for c in combinations(S, r)]


@mark.parametrize("gramian_module_names", _non_empty_subsets({"fc0", "fc1", "fc2", "fc3", "fc4"}))
Expand Down