Skip to content
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

GH-94808: Cover PyOS_mystrnicmp and PyOS_mystricmp #102469

Merged
merged 3 commits into from
Mar 22, 2023

Conversation

artemmukhin
Copy link
Contributor

@artemmukhin artemmukhin commented Mar 6, 2023

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@cpython-cla-bot
Copy link

cpython-cla-bot bot commented Mar 6, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@artemmukhin
Copy link
Contributor Author

I'm not sure who is best positioned to review this, but maybe @corona10 could take a look?

@corona10 corona10 self-requested a review March 10, 2023 15:05
@corona10
Copy link
Member

I'm not sure who is best positioned to review this, but maybe @corona10 could take a look?

Okay, I will take a look by this weekend :)

@corona10 corona10 self-assigned this Mar 10, 2023
@artemmukhin
Copy link
Contributor Author

@corona10 Thank you!

Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like to separate the file into Modules/_testcapi/pyos.c
likewise https://github.com/python/cpython/blob/main/Modules/_testcapi/float.c ?

The test itself looks good.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@artemmukhin artemmukhin requested a review from a team as a code owner March 11, 2023 15:56
@artemmukhin
Copy link
Contributor Author

artemmukhin commented Mar 11, 2023

I have made the requested changes; please review again.

@corona10 Thank you for the review! I've separated the tests.

Although I haven't managed to run the tests from Modules/_testcapi on my machine. Before separating, I ran my tests via ./python -m test -v test_capi, but now they are not executed as I see. I found the C API Tests paragraph in the devguide, but I didn't find how to run these tests. Could you please clarify?

@bedevere-bot
Copy link

Thanks for making the requested changes!

@corona10: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from corona10 March 11, 2023 16:08
@artemmukhin
Copy link
Contributor Author

I've found out that the tests were not executed because of the wrong naming.

Test_testcapi only executes the test method if its built-in name starts with test_ and doesn't end with _code:

class Test_testcapi(unittest.TestCase):
locals().update((name, getattr(_testcapi, name))
for name in dir(_testcapi)
if name.startswith('test_') and not name.endswith('_code'))

It is mentioned in the C API Tests paragraph to some extent:

Functions named test_* are used as tests directly

But at first reading, I got confused because in _testcapi/float.c file, the test_ prefix is only used in the C function name:

static PyMethodDef test_methods[] = {
{"float_pack", test_float_pack, METH_VARARGS, NULL},
{"float_unpack", test_float_unpack, METH_VARARGS, NULL},
{NULL},
};

However, in contrast to my tests, these test methods are actually executed through test_float.py:

cpython/Lib/test/test_float.py

Lines 1516 to 1519 in 534660f

class PackTests(unittest.TestCase):
def test_pack(self):
self.assertEqual(_testcapi.float_pack(2, 1.5, BIG_ENDIAN),
b'>\x00')

I hope this investigation might help other first-time contributors.

@corona10 If you think it would be helpful to clarify this point in the devguide, please let me know, and I'll be happy to open a corresponding PR.

@corona10
Copy link
Member

I've found out that the tests were not executed because of the wrong naming.
Test_testcapi only executes the test method if its built-in name starts with test_ and doesn't end with _code:
But at first reading, I got confused because in testcapi/float.c file, the test prefix is only used in the C function name:
However, in contrast to my tests, these test methods are actually executed through test_float.py:

AFAIK, those things are intended.

Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

But I want to listen to the opinion of @erlend-aasland for this testing structure.

@artemmukhin
Copy link
Contributor Author

@erlend-aasland could you please take a look?

@artemmukhin
Copy link
Contributor Author

Thank you!

Cc @corona10

@corona10 corona10 merged commit 0a60dea into python:main Mar 22, 2023
Fidget-Spinner pushed a commit to Fidget-Spinner/cpython that referenced this pull request Mar 27, 2023
@artemmukhin artemmukhin deleted the cover-pystrcmp branch April 2, 2023 22:17
warsaw pushed a commit to warsaw/cpython that referenced this pull request Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants