-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15de2c5
commit d13f1d9
Showing
2 changed files
with
320 additions
and
335 deletions.
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,47 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from coola import objects_are_equal | ||
from coola.testing import torch_available | ||
from tests.unit.equality.comparators.test_torch import ( | ||
TORCH_PACKED_SEQUENCE_EQUAL, | ||
TORCH_PACKED_SEQUENCE_NOT_EQUAL, | ||
TORCH_TENSOR_EQUAL, | ||
TORCH_TENSOR_NOT_EQUAL, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from tests.unit.equality.comparators.utils import ExamplePair | ||
|
||
|
||
@torch_available | ||
@pytest.mark.parametrize("example", TORCH_TENSOR_EQUAL + TORCH_PACKED_SEQUENCE_EQUAL) | ||
@pytest.mark.parametrize("show_difference", [True, False]) | ||
def test_objects_are_equal_true( | ||
example: ExamplePair, show_difference: bool, caplog: pytest.LogCaptureFixture | ||
) -> None: | ||
with caplog.at_level(logging.INFO): | ||
assert objects_are_equal(example.object1, example.object2, show_difference) | ||
assert not caplog.messages | ||
|
||
|
||
@torch_available | ||
@pytest.mark.parametrize("example", TORCH_TENSOR_NOT_EQUAL + TORCH_PACKED_SEQUENCE_NOT_EQUAL) | ||
def test_objects_are_equal_false(example: ExamplePair, caplog: pytest.LogCaptureFixture) -> None: | ||
with caplog.at_level(logging.INFO): | ||
assert not objects_are_equal(example.object1, example.object2) | ||
assert not caplog.messages | ||
|
||
|
||
@torch_available | ||
@pytest.mark.parametrize("example", TORCH_TENSOR_NOT_EQUAL + TORCH_PACKED_SEQUENCE_NOT_EQUAL) | ||
def test_objects_are_equal_false_show_difference( | ||
example: ExamplePair, caplog: pytest.LogCaptureFixture | ||
) -> None: | ||
with caplog.at_level(logging.INFO): | ||
assert not objects_are_equal(example.object1, example.object2, show_difference=True) | ||
assert caplog.messages[-1].startswith(example.expected_message) |
Oops, something went wrong.