Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
11 commits
Select commitHold shift + click to select a range
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
10 changes: 6 additions & 4 deletionsLib/mimetypes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -669,7 +669,7 @@ def _default_mime_types():
_default_mime_types()


def _main():
def _main(args=None):
"""Run the mimetypes command-line interface."""
import sys
from argparse import ArgumentParser
Expand All@@ -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 = parser.parse_args(args)

if args.extension:
for gtype in args.type:
guess = guess_extension(gtype, not args.lenient)
if guess:
print(guess)
else:
sys.exit(f"error: unknown type {gtype}")
print(f"error: unknown type {gtype}", file=sys.stderr)
sys.exit(1)
else:
for gtype in args.type:
guess, encoding = guess_type(gtype, not args.lenient)
if guess:
print('type:', guess, 'encoding:', encoding)
else:
sys.exit(f"error: media type unknown for {gtype}")
print(f"error: media type unknown for {gtype}", file=sys.stderr)
sys.exit(1)


if __name__ == '__main__':
Expand Down
25 changes: 17 additions & 8 deletionsLib/test/test_mimetypes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
import contextlib
import io
import mimetypes
import os
import sys
import tempfile
import unittest.mock
from os import linesep

Expand DownExpand Up@@ -392,9 +394,19 @@ def test__all__(self):

class MimetypesCliTestCase(unittest.TestCase):

def mimetypes_cmd(cls, *args, **kwargs):
result, _ = run_python_until_end('-m', 'mimetypes', *args)
return result.rc, result.out.decode(), result.err.decode()
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')
Expand DownExpand Up@@ -430,15 +442,12 @@ def test_guess_type(self):
self.assertEqual(out, f'type: image/webp encoding: None{linesep}')
self.assertEqual(err, '')

@unittest.skipIf(
sys.platform == 'darwin',
'macOS lists common_types in mime.types thus making them always known'
)
def test_guess_type_conflicting_with_mimetypes(self):
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()
Loading

[8]ページ先頭

©2009-2025 Movatter.jp