summaryrefslogtreecommitdiffstats
path: root/test/test_matcherrror.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 06:24:57 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 06:24:57 +0000
commit1faea9a6c75f33109e8f66b57b432fdad57b3f46 (patch)
tree4184ce38ac0cf9d5a46bbbae03c87be82927f12b /test/test_matcherrror.py
parentAdding upstream version 6.17.2. (diff)
downloadansible-lint-upstream.tar.xz
ansible-lint-upstream.zip
Adding upstream version 24.6.1.upstream/24.6.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/test_matcherrror.py')
-rw-r--r--test/test_matcherrror.py48
1 files changed, 22 insertions, 26 deletions
diff --git a/test/test_matcherrror.py b/test/test_matcherrror.py
index 03d9cbd..5b67e23 100644
--- a/test/test_matcherrror.py
+++ b/test/test_matcherrror.py
@@ -1,7 +1,8 @@
"""Tests for MatchError."""
import operator
-from typing import Any, Callable
+from collections.abc import Callable
+from typing import Any
import pytest
@@ -121,18 +122,18 @@ class TestMatchErrorCompare:
@pytest.mark.parametrize(
"other",
(
- None,
- "foo",
- 42,
- Exception("foo"),
+ pytest.param(None, id="none"),
+ pytest.param("foo", id="str"),
+ pytest.param(42, id="int"),
+ pytest.param(Exception("foo"), id="exc"),
),
ids=repr,
)
@pytest.mark.parametrize(
("operation", "operator_char"),
(
- pytest.param(operator.le, "<=", id="<="),
- pytest.param(operator.gt, ">", id=">"),
+ pytest.param(operator.le, "<=", id="le"),
+ pytest.param(operator.gt, ">", id="gt"),
),
)
def test_matcherror_compare_no_other_fallback(
@@ -143,12 +144,9 @@ def test_matcherror_compare_no_other_fallback(
"""Check that MatchError comparison with other types causes TypeError."""
expected_error = (
r"^("
- r"unsupported operand type\(s\) for {operator!s}:|"
- r"'{operator!s}' not supported between instances of"
- r") 'MatchError' and '{other_type!s}'$".format(
- other_type=type(other).__name__,
- operator=operator_char,
- )
+ rf"unsupported operand type\(s\) for {operator_char!s}:|"
+ rf"'{operator_char!s}' not supported between instances of"
+ rf") 'MatchError' and '{type(other).__name__!s}'$"
)
with pytest.raises(TypeError, match=expected_error):
operation(MatchError("foo"), other)
@@ -157,21 +155,20 @@ def test_matcherror_compare_no_other_fallback(
@pytest.mark.parametrize(
"other",
(
- None,
- "foo",
- 42,
- Exception("foo"),
- DummyTestObject(),
+ pytest.param(None, id="none"),
+ pytest.param("foo", id="str"),
+ pytest.param(42, id="int"),
+ pytest.param(Exception("foo"), id="exception"),
+ pytest.param(DummyTestObject(), id="obj"),
),
ids=repr,
)
@pytest.mark.parametrize(
("operation", "expected_value"),
(
- (operator.eq, False),
- (operator.ne, True),
+ pytest.param(operator.eq, False, id="eq"),
+ pytest.param(operator.ne, True, id="ne"),
),
- ids=("==", "!="),
)
def test_matcherror_compare_with_other_fallback(
other: object,
@@ -185,16 +182,15 @@ def test_matcherror_compare_with_other_fallback(
@pytest.mark.parametrize(
("operation", "expected_value"),
(
- (operator.eq, "EQ_SENTINEL"),
- (operator.ne, "NE_SENTINEL"),
+ pytest.param(operator.eq, "EQ_SENTINEL", id="eq"),
+ pytest.param(operator.ne, "NE_SENTINEL", id="ne"),
# NOTE: these are swapped because when we do `x < y`, and `x.__lt__(y)`
# NOTE: returns `NotImplemented`, Python will reverse the check into
# NOTE: `y > x`, and so `y.__gt__(x) is called.
# Ref: https://docs.python.org/3/reference/datamodel.html#object.__lt__
- (operator.lt, "GT_SENTINEL"),
- (operator.gt, "LT_SENTINEL"),
+ pytest.param(operator.lt, "GT_SENTINEL", id="gt"),
+ pytest.param(operator.gt, "LT_SENTINEL", id="lt"),
),
- ids=("==", "!=", "<", ">"),
)
def test_matcherror_compare_with_dummy_sentinel(
operation: Callable[..., bool],