Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.3k
gh-93096: fixtest_mimetypes.test_guess_type_conflicting_with_mimetypes
#131408
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
hugovk merged 11 commits intopython:mainfrompicnixz:fix/test/conflicting-mime-types-93096Apr 8, 2025
+64 −63
Merged
Changes from1 commit
Commits
Show all changes
11 commits Select commitHold shift + click to select a range
62863a0
fix `test_mimetypes.test_guess_type_conflicting_with_mimetypes`
picnixz7be23f0
remove checks for linesep
picnixz01e89c3
use `parser.exit()` instead of print + sys.exit()
picnixz60f9eeb
Merge remote-tracking branch 'upstream/main' into fix/test/conflictin…
picnixz1d29b5d
fixup
picnixzeeb5635
Update Lib/test/test_mimetypes.py
picnixzd9d136e
use Hugo's approach for testing `mimetypes`
picnixz8ba9b1d
Merge branch 'main' into fix/test/conflicting-mime-types-93096
picnixzb0c29fa
Update Lib/test/test_mimetypes.py
picnixz56bbd95
[empty commit to trigger CI]
picnixz1efb979
Merge branch 'fix/test/conflicting-mime-types-93096' of github.com:pi…
picnixzFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -669,7 +669,7 @@ def _default_mime_types(): | ||
_default_mime_types() | ||
def _main(args=None): | ||
"""Run the mimetypes command-line interface.""" | ||
import sys | ||
from argparse import ArgumentParser | ||
@@ -686,22 +686,24 @@ def _main(): | ||
help='additionally search for common but non-standard types' | ||
) | ||
parser.add_argument('type', nargs='+', help='a type to search') | ||
args = parser.parse_args(args) | ||
if args.extension: | ||
for gtype in args.type: | ||
guess = guess_extension(gtype, not args.lenient) | ||
if guess: | ||
print(guess) | ||
else: | ||
print(f"error: unknown type {gtype}", file=sys.stderr) | ||
sys.exit(1) | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
else: | ||
for gtype in args.type: | ||
guess, encoding = guess_type(gtype, not args.lenient) | ||
if guess: | ||
print('type:', guess, 'encoding:', encoding) | ||
else: | ||
print(f"error: media type unknown for {gtype}", file=sys.stderr) | ||
sys.exit(1) | ||
if __name__ == '__main__': | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import contextlib | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
import io | ||
import mimetypes | ||
import os | ||
import sys | ||
import tempfile | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
import unittest.mock | ||
from os import linesep | ||
@@ -392,9 +394,19 @@ def test__all__(self): | ||
class MimetypesCliTestCase(unittest.TestCase): | ||
def mimetypes_cmd(self, *args): | ||
# We cannot use run_python_until_end() as the latter would not | ||
# call setUpModule() which unsets mimetypes.knowfiles. Instead, | ||
# we need to directly call the main() function in order to avoid | ||
# re-initializing the database. | ||
rc, out, err = 0, io.StringIO(), io.StringIO() | ||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err): | ||
try: | ||
mimetypes._main(args) | ||
except SystemExit as exc: | ||
self.assertIsInstance(exc.code, int) | ||
rc = exc.code | ||
return rc, out.getvalue(), err.getvalue() | ||
def test_help_option(self): | ||
retcode, out, err = self.mimetypes_cmd('-h') | ||
@@ -430,15 +442,12 @@ def test_guess_type(self): | ||
self.assertEqual(out, f'type: image/webp encoding: None{linesep}') | ||
self.assertEqual(err, '') | ||
def test_z_guess_type_conflicting_with_mimetypes(self): | ||
retcode, out, err = self.mimetypes_cmd('foo.pic') | ||
self.assertEqual(retcode, 1) | ||
self.assertEqual(out, '') | ||
self.assertEqual(err, f'error: media type unknown for foo.pic{linesep}') | ||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.