-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
BUG: Make assert_string_equal check str equality simply without regex #11556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ec9d466
to
daba50a
Compare
daba50a
to
37e4d58
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just added a few thoughts / comments; not necessarily problems though.
@@ -1081,6 +1081,12 @@ def test_simple(self): | |||
|
|||
assert_raises(AssertionError, | |||
lambda: assert_string_equal("foo", "hello")) | |||
|
|||
def test_regex(self): | |||
assert_string_equal("a+*b", "a+*b") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it is worth using a parametrized test (from pytest) to probe a few more of the regular expression special characters used in Python. On the other hand, if I'm not mistaken, there may not be much drive for this kind of support in numpy.testing
moving forward with increased adoption of pytest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there may not be much drive for this kind of support in numpy.testing
How so? Does pytest offer an equivalent for the function being tested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably OK to skip complete coverage here unless there is a return to regular expressions.
@tylerjereddy Now that you are working a BIDS, do you need commit privileges?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that's up to the team, but I'm happy to continue without for now. I don't think pytest
has a replacement functionality for what NumPy does here.
assert_string_equal("a+*b", "a+*b") | ||
|
||
assert_raises(AssertionError, | ||
lambda: assert_string_equal("aaa", "a+b")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a bit less awkward to use a context manager (available from assert_raises or the pytest equivalent) instead of using lambda
for a callable. The docstring for assert_string_equal
also claims to return the diff
between strings--not sure if we need to test that case with special regex chars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, the lambda
form used here is consistent with the rest of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests function is pretty old (2009), so could use a rewrite sometime in the future. The fixed code dates back to 2007 ...
Thanks @sh0nk . |
assert_string_equal
on testing utils.py is expected to test string equality, but it fails if there are special characters which are used for regex syntax.This is because this method uses regex pattern on
desired
input to check the equality as it is. There is another way to fix this by escaping the regex pattern:re.match(r'\A'+re.escape(desired)+r'\Z', actual, re.M)
but just to use string equality check (implying__eq__
) should be enough and lightweight.The added test case worked the other way around before fixing.