Repository navigation
gh-131178: Fix mimetypes CLI docs to mention that errors go to stdout #149683
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
c87667b
77e5b2a
5b75aaa
ad605cd
f6db7b1
edf95da
b00896c
e0409b3
277b007
4b28aed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,9 @@ | |
| import unittest.mock | ||
| from platform import win32_edition | ||
| from test import support | ||
| from test.support import cpython_only, force_not_colorized, os_helper | ||
| from test.support import cpython_only, force_not_colorized, os_helper, requires_subprocess | ||
| from test.support.import_helper import ensure_lazy_imports | ||
| from test.support.script_helper import assert_python_ok, assert_python_failure | ||
|
|
||
| try: | ||
| import _winapi | ||
|
|
@@ -508,5 +509,57 @@ def test_invocation_error(self): | |
| self.assertEqual(result, expected) | ||
|
|
||
|
|
||
| @requires_subprocess() | ||
| class CommandLineSubprocessTest(unittest.TestCase): | ||
| def test_help(self): | ||
| rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', '--help') | ||
| self.assertIn(b'mimetypes', stdout) | ||
| self.assertIn(b'--extension', stdout) | ||
| self.assertIn(b'--lenient', stdout) | ||
|
|
||
| def test_type_lookup(self): | ||
| rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', 'foo.pdf') | ||
| self.assertEqual(stdout.strip(), b'type: application/pdf encoding: None') | ||
| self.assertEqual(stderr, b'') | ||
|
|
||
| def test_type_lookup_unknown(self): | ||
| rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', 'foo.unknownext12345') | ||
| self.assertEqual(stdout.strip(), b'error: media type unknown for foo.unknownext12345') | ||
| self.assertEqual(stderr, b'') | ||
|
|
||
| def test_extension_flag(self): | ||
| rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', '-e', 'image/jpeg') | ||
| self.assertIn(b'.jpg', stdout) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use |
||
| self.assertEqual(stderr, b'') | ||
|
|
||
| def test_extension_flag_unknown(self): | ||
| rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', '-e', 'image/unknowntype12345') | ||
| self.assertEqual(stdout.strip(), b'error: unknown type image/unknowntype12345') | ||
| self.assertEqual(stderr, b'') | ||
|
|
||
| def test_lenient_flag(self): | ||
| rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', '-e', '--lenient', 'text/xul') | ||
| self.assertIn(b'.xul', stdout) | ||
| self.assertEqual(stderr, b'') | ||
|
|
||
| def test_multiple_inputs(self): | ||
| rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', 'foo.pdf', 'foo.png') | ||
| self.assertIn(b'type: application/pdf encoding: None', stdout) | ||
| self.assertIn(b'type: image/png encoding: None', stdout) | ||
| self.assertEqual(stderr, b'') | ||
|
|
||
| def test_multiple_inputs_with_error(self): | ||
| rc, stdout, stderr = assert_python_failure( | ||
| '-m', 'mimetypes', 'foo.pdf', 'foo.unknownext12345' | ||
| ) | ||
| self.assertIn(b'type: application/pdf encoding: None', stdout) | ||
| self.assertIn(b'error: media type unknown for foo.unknownext12345', stdout) | ||
| self.assertEqual(stderr, b'') | ||
|
|
||
| def test_unknown_flag(self): | ||
| rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', '--unknown-flag') | ||
| self.assertNotEqual(rc, 0) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert the output please :) |
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Add subprocess-based tests for the :mod:`mimetypes` command-line interface, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't add news for docs / tests only changes. |
||
| verifying output format and exit codes for known and unknown types. | ||
Uh oh!
There was an error while loading. Please reload this page.