gh-136507: Fix mimetypes CLI to handle multiple file parameters (GH-1… · python/cpython@81268a3 · GitHub
Skip to content

Commit 81268a3

Browse files
Wulian233hugovk
andauthored
gh-136507: Fix mimetypes CLI to handle multiple file parameters (GH-136508)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent edf6e68 commit 81268a3

3 files changed

Lines changed: 36 additions & 11 deletions

File tree

Lib/mimetypes.py

Lines changed: 14 additions & 8 deletions

Lib/test/test_mimetypes.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,22 +470,40 @@ def test_parse_args(self):
470470
self.assertFalse(args.lenient)
471471
self.assertEqual(args.type, ["foo.pic"])
472472

473+
def test_multiple_inputs(self):
474+
result = "\n".join(mimetypes._main(shlex.split("foo.pdf foo.png")))
475+
self.assertEqual(
476+
result,
477+
"type: application/pdf encoding: None\n"
478+
"type: image/png encoding: None"
479+
)
480+
481+
def test_multiple_inputs_error(self):
482+
result = "\n".join(mimetypes._main(shlex.split("foo.pdf foo.bar_ext")))
483+
self.assertEqual(
484+
result,
485+
"type: application/pdf encoding: None\n"
486+
"error: media type unknown for foo.bar_ext"
487+
)
488+
489+
473490
def test_invocation(self):
474491
for command, expected in [
475492
("-l -e image/jpg", ".jpg"),
476493
("-e image/jpeg", ".jpg"),
477494
("-l foo.webp", "type: image/webp encoding: None"),
478495
]:
479-
self.assertEqual(mimetypes._main(shlex.split(command)), expected)
496+
result = "\n".join(mimetypes._main(shlex.split(command)))
497+
self.assertEqual(result, expected)
480498

481499
def test_invocation_error(self):
482500
for command, expected in [
483501
("-e image/jpg", "error: unknown type image/jpg"),
484502
("foo.bar_ext", "error: media type unknown for foo.bar_ext"),
485503
]:
486504
with self.subTest(command=command):
487-
with self.assertRaisesRegex(SystemExit, expected):
488-
mimetypes._main(shlex.split(command))
505+
result = "\n".join(mimetypes._main(shlex.split(command)))
506+
self.assertEqual(result, expected)
489507

490508

491509
if __name__ == "__main__":
Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)