Visitar URL original
gh-102580 Add tests for the MIME image module's content subtype inference mechanism by JosephSBoyle · Pull Request #102579 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20260312220454/https://github.com/python/cpython/pull/102579
Skip to content
/ cpython Public

gh-102580 Add tests for the MIME image module's content subtype inference mechanism#102579

Closed
JosephSBoyle wants to merge 7 commits intopython:mainfrom
JosephSBoyle:add-tests-to-mime-image-and-refactor
Closed

gh-102580 Add tests for the MIME image module's content subtype inference mechanism#102579
JosephSBoyle wants to merge 7 commits intopython:mainfrom
JosephSBoyle:add-tests-to-mime-image-and-refactor

Conversation

@JosephSBoyle
Copy link
Contributor

@JosephSBoyle JosephSBoyle commented Mar 10, 2023 •

Adds a basic set of tests covering all branches of the subtype inference mechanism in image.py
Add a test covering a branch on line 68-69 of image.py that is not covered by the existing tests.

Refactor the content subtype inference mechanism.
@JosephSBoyle JosephSBoyle changed the title Add tests to the MIME image module's content subtype inference mechanism gh-102580 Add tests to the MIME image module's content subtype inference mechanism Mar 10, 2023
Change `if _subtype is None` to `if not _subtype`; all falsy values are invalid
and should error. `is None` implies that there exists exceptions to this
@JosephSBoyle JosephSBoyle force-pushed the add-tests-to-mime-image-and-refactor branch from 9dc4247 to ad3a6b2 Compare March 10, 2023 13:49
@JosephSBoyle JosephSBoyle marked this pull request as ready for review March 10, 2023 13:50
@JosephSBoyle JosephSBoyle requested a review from a team as a code owner March 10, 2023 13:50
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

I am not a big fan of refactoring anything in the stdlib for no good reason 😞

But, I think adding tests is ok.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

This PR bundles several changes into one PR. It should be split into multiple PRs, so that the changes can be reviewed independently:

  1. First, make a PR to improve test coverage. This PR should state clearly why each new test is being added -- which lines/branches it adds coverage for, or whatever other reason the test is being added.
  2. Once that PR has been merged and we're confident that this module has a strong level of test coverage, we can consider a second PR to refactor this module. That PR should state clearly why the module is being refactored. Valid reasons for refactoring a module include improving performance, or opening up the possibility to make some other changes that might fix bugs.

We generally don't accept PRs making changes purely for the sake of simplifying the code, as the risk of accidentally breaking something is too great, even for modules with 100% test coverage. But, there can be some exceptions.

@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.

@AlexWaygood
Copy link
Member

FYI there's a guide to how to work on improving CPython's test coverage here, which may be useful: https://devguide.python.org/testing/coverage/ :)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks, could you indicate which lines/branches exactly this adds coverage for?

@AlexWaygood AlexWaygood changed the title gh-102580 Add tests to the MIME image module's content subtype inference mechanism gh-102580 Add tests for the MIME image module's content subtype inference mechanism Mar 10, 2023
@warsaw
Copy link
Member

warsaw commented Mar 10, 2023

I plan on reviewing this in more detail, but I've just been pretty busy lately.

@AlexWaygood AlexWaygood dismissed their stale review March 10, 2023 17:10

requested changes were made

@JosephSBoyle JosephSBoyle marked this pull request as draft March 11, 2023 17:02
@JosephSBoyle
Copy link
Contributor Author

These changes don't actually improve the coverage, other than a single elif branch on lines 68-69. Moving back to draft.

@JosephSBoyle
Copy link
Contributor Author

JosephSBoyle commented Mar 11, 2023 •

This PR now simply adds test coverage to a branch of image.py on lines 68-69 that was previously not covered. (See the tests above the added lines).

Ideally, we'd roll this into the existing test (right above), by creating a new jpeg image file for the test which begins with the bytes b'\xff\xd8\xff\xdb', so as to hit the uncovered branch. That way we could delete this new test:)

I had a go but I'm afraid I'm not quite sure how to create such a file..

@JosephSBoyle JosephSBoyle marked this pull request as ready for review March 11, 2023 18:45
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@arhadthedev arhadthedev added the tests Tests in the Lib/test dir label Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants