Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion src/hamcrest/core/core/raises.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def _call_function(self, function: Callable[..., Any]) -> bool:

if isinstance(self.actual, self.expected):
if self.pattern is not None:
if re.search(self.pattern, str(self.actual)) is None:
if re.search(
self.pattern, str(self.actual)
) is None and self.pattern is not str(self.actual):
Comment thread
tallus marked this conversation as resolved.
Outdated
return False
if self.matcher is not None:
if not self.matcher.matches(self.actual):
Expand Down
17 changes: 17 additions & 0 deletions tests/hamcrest_unit_test/core/raises_with_parens_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest

Comment thread
tallus marked this conversation as resolved.
Outdated
from hamcrest import assert_that, calling, raises


def raise_error(msg):
raise AssertionError(msg)


class ParensTest(unittest.TestCase):
def test_literal_parens(self):

message = "Message with (parens)"
assert_that(calling(raise_error).with_args(message), raises(AssertionError, message))

def test_parens_in_regex(self):
assert_that(calling(raise_error).with_args("abab"), raises(AssertionError, r"(ab)+"))