Skip to content

Commit 19af603

Browse files
authored
fix(v3): align error and regex v3 matcher args with v2 (#325)
1 parent 47579a0 commit 19af603

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

decoy/next/_internal/matcher.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,35 +216,35 @@ def contains(
216216
)
217217

218218
@staticmethod
219-
def matches(pattern: str) -> "Matcher[str]":
219+
def matches(match: str) -> "Matcher[str]":
220220
"""Match a string by a pattern.
221221
222222
Arguments:
223-
pattern: Regular expression pattern.
223+
match: Regular expression pattern.
224224
"""
225-
pattern_re = re.compile(pattern)
225+
match_re = re.compile(match)
226226

227227
return Matcher(
228-
match=functools.partial(matches, pattern_re),
229-
description=repr(pattern),
228+
match=functools.partial(matches, match_re),
229+
description=repr(match),
230230
)
231231

232232
@staticmethod
233-
def error(type: type[ErrorT], message: str | None = None) -> "Matcher[ErrorT]":
233+
def error(type: type[ErrorT], match: str | None = None) -> "Matcher[ErrorT]":
234234
"""Match an exception object.
235235
236236
Arguments:
237237
type: The type of exception to match.
238-
message: An optional regular expression pattern to match.
238+
match: An optional regular expression pattern to match.
239239
"""
240-
message_re = re.compile(message or "")
240+
match_re = re.compile(match or "")
241241
description = type.__name__
242242

243-
if message:
244-
description = f"{description} message={message!r}"
243+
if match:
244+
description = f"{description} match={match!r}"
245245

246246
return Matcher(
247-
match=functools.partial(error, type, message_re),
247+
match=functools.partial(error, type, match_re),
248248
name="error",
249249
description=description,
250250
)

tests/test_matcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ def test_error_type() -> None:
249249

250250
def test_error_type_and_message() -> None:
251251
"""It matches an exception type and message."""
252-
subject = Matcher.error(RuntimeError, message="^oh")
252+
subject = Matcher.error(RuntimeError, match="^oh")
253253

254254
assert RuntimeError("oh no") == subject
255255
assert RuntimeError("oh canada") == subject
256256
assert TypeError("oh no") != subject
257-
assert str(subject) == "<Matcher.error RuntimeError message='^oh'>"
257+
assert str(subject) == "<Matcher.error RuntimeError match='^oh'>"

0 commit comments

Comments
 (0)