FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-131178: Add tests for mimetypes command-line interface by htjworld · Pull Request #149681 · python/cpython · GitHub

/ cpython Public
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
49 changes: 48 additions & 1 deletion Lib/test/test_mimetypes.py
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
Expand Up @@ -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
Expand Down Expand Up @@ -508,5 +509,51 @@ 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'--help', 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.assertIn(b'application/pdf', stdout)

def test_type_lookup_unknown(self):
rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', 'foo.unknownext12345')
self.assertIn(b'error:', stdout)

def test_extension_flag(self):
rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', '-e', 'image/jpeg')
self.assertIn(b'.jpg', stdout)

def test_extension_flag_unknown(self):
rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', '-e', 'image/unknowntype12345')
self.assertIn(b'error:', stdout)

def test_lenient_flag(self):
rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', '--lenient', 'foo.webp')
self.assertIn(b'image/webp', stdout)

def test_multiple_inputs(self):
rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', 'foo.pdf', 'foo.png')
self.assertIn(b'application/pdf', stdout)
self.assertIn(b'image/png', stdout)

def test_multiple_inputs_with_error(self):
rc, stdout, stderr = assert_python_failure(
'-m', 'mimetypes', 'foo.pdf', 'foo.unknownext12345'
)
self.assertIn(b'application/pdf', stdout)
self.assertIn(b'error:', stdout)

def test_unknown_flag(self):
rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', '--unknown-flag')
self.assertNotEqual(rc, 0)


if __name__ == "__main__":
unittest.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
@@ -0,0 +1 @@
Add tests for the :mod:`mimetypes` command-line interface.
Loading

Back | FazBrowse Home | New Git URL