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
16 changes: 8 additions & 8 deletions tests/arithmetic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,29 +220,29 @@ def test_arithmetic_fail(mismatch_tensors: tuple[GrassmannTensor, GrassmannTenso
tensor_a, tensor_b = mismatch_tensors

# Test __add__ method.
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="must match for arithmetic operations"):
tensor_a + tensor_b
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="must match for arithmetic operations"):
tensor_c = tensor_a.clone()
tensor_c += tensor_b

# Test __sub__ method.
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="must match for arithmetic operations"):
tensor_a - tensor_b
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="must match for arithmetic operations"):
tensor_c = tensor_a.clone()
tensor_c -= tensor_b

# Test __mul__ method.
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="must match for arithmetic operations"):
tensor_a * tensor_b
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="must match for arithmetic operations"):
tensor_c = tensor_a.clone()
tensor_c *= tensor_b

# Test __truediv__ method.
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="must match for arithmetic operations"):
tensor_a / tensor_b
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="must match for arithmetic operations"):
tensor_c = tensor_a.clone()
tensor_c /= tensor_b
6 changes: 3 additions & 3 deletions tests/conversion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def test_conversion(


def test_conversion_duplicated_value(x: GrassmannTensor) -> None:
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="Duplicate device specification"):
x.to(torch.device("cpu"), device=torch.device("cpu"))
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="Duplicate dtype specification"):
x.to(torch.complex128, dtype=torch.complex128)
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="Duplicate device specification"):
x.to("cpu", device=torch.device("cpu"))
6 changes: 3 additions & 3 deletions tests/creation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_creation_success(x: Initialization) -> None:
((False, True), ((1, 1), (2, 2), (1, 1)), torch.randn([2, 4, 2])),
])
def test_creation_invalid_arrow(x: Initialization) -> None:
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="Arrow length"):
GrassmannTensor(*x)


Expand All @@ -30,7 +30,7 @@ def test_creation_invalid_arrow(x: Initialization) -> None:
((False, True, False), ((1, 1), (1, 1)), torch.randn([2, 4, 2])),
])
def test_creation_invalid_edges(x: Initialization) -> None:
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="Edges length"):
GrassmannTensor(*x)


Expand All @@ -40,5 +40,5 @@ def test_creation_invalid_edges(x: Initialization) -> None:
((False, True, False), ((1, 1), (2, 2), (1, 1)), torch.randn([4, 4, 2])),
])
def test_creation_invalid_shape(x: Initialization) -> None:
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match="must equal sum of"):
GrassmannTensor(*x)
12 changes: 6 additions & 6 deletions tests/permute_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ def test_permute(x: PermuteCase) -> None:
assert torch.allclose(result.tensor, expected)


PermuteFailCase = tuple[tuple[bool, ...], tuple[tuple[int, int], ...], torch.Tensor, tuple[int, ...]]
PermuteFailCase = tuple[tuple[bool, ...], tuple[tuple[int, int], ...], torch.Tensor, tuple[int, ...], str]


@pytest.mark.parametrize("x", [
((False, False), ((1, 1), (1, 1)), torch.tensor([[1, 0], [0, 4]]), (0, 0)),
((False, False), ((1, 1), (1, 1)), torch.tensor([[1, 0], [0, 4]]), (2, 0)),
((False, False), ((1, 1), (1, 1)), torch.tensor([[1, 0], [0, 4]]), (0, 0, 1)),
((False, False), ((1, 1), (1, 1)), torch.tensor([[1, 0], [0, 4]]), (0, 0), "Permutation indices must be unique"),
((False, False), ((1, 1), (1, 1)), torch.tensor([[1, 0], [0, 4]]), (2, 0), "Permutation indices must cover all dimensions"),
((False, False), ((1, 1), (1, 1)), torch.tensor([[1, 0], [0, 4]]), (0, 0, 1), "Permutation indices must be unique"),
])
def test_permute_fail(x: PermuteFailCase) -> None:
arrow, edges, tensor, before_by_after = x
arrow, edges, tensor, before_by_after, message = x
grassmann_tensor = GrassmannTensor(arrow, edges, tensor)
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match=message):
grassmann_tensor.permute(before_by_after)


Expand Down
10 changes: 5 additions & 5 deletions tests/reverse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def test_reverse(x: ReverseCase) -> None:
assert torch.allclose(result.tensor, expected)


ReverseFailCase = tuple[tuple[bool, ...], tuple[tuple[int, int], ...], torch.Tensor, tuple[int, ...]]
ReverseFailCase = tuple[tuple[bool, ...], tuple[tuple[int, int], ...], torch.Tensor, tuple[int, ...], str]


@pytest.mark.parametrize("x", [
((False, False), ((1, 1), (1, 1)), torch.tensor([[1, 0], [0, 4]]), (0, 0)),
((False, False), ((1, 1), (1, 1)), torch.tensor([[1, 0], [0, 4]]), (2,)),
((False, False), ((1, 1), (1, 1)), torch.tensor([[1, 0], [0, 4]]), (0, 0), "Indices must be unique"),
((False, False), ((1, 1), (1, 1)), torch.tensor([[1, 0], [0, 4]]), (2,), "Indices must be within tensor dimensions"),
])
def test_reverse_fail(x: ReverseFailCase) -> None:
arrow, edges, tensor, reverse_by = x
arrow, edges, tensor, reverse_by, message = x
grassmann_tensor = GrassmannTensor(arrow, edges, tensor)
with pytest.raises(AssertionError):
with pytest.raises(AssertionError, match=message):
grassmann_tensor.reverse(reverse_by)