Skip to content

Commit 639644b

Browse files
committed
fix test
1 parent 69ae20c commit 639644b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Lib/test/test_mimetypes.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import io
23
import mimetypes
34
import os
@@ -476,16 +477,22 @@ def test_invocation(self):
476477
("-e image/jpeg", ".jpg"),
477478
("-l foo.webp", "type: image/webp encoding: None"),
478479
]:
479-
self.assertEqual(mimetypes._main(shlex.split(command)), expected)
480+
with self.subTest(command=command):
481+
out = io.StringIO()
482+
with contextlib.redirect_stdout(out):
483+
mimetypes._main(shlex.split(command))
484+
self.assertEqual(out.getvalue().strip(), expected)
480485

481486
def test_invocation_error(self):
482487
for command, expected in [
483488
("-e image/jpg", "error: unknown type image/jpg"),
484489
("foo.bar_ext", "error: media type unknown for foo.bar_ext"),
485490
]:
486491
with self.subTest(command=command):
487-
with self.assertRaisesRegex(SystemExit, expected):
492+
err = io.StringIO()
493+
with contextlib.redirect_stderr(err):
488494
mimetypes._main(shlex.split(command))
495+
self.assertIn(expected, err.getvalue().strip())
489496

490497

491498
if __name__ == "__main__":

0 commit comments

Comments
 (0)