|
6 | 6 | import unittest.mock |
7 | 7 | from platform import win32_edition |
8 | 8 | from test import support |
9 | | -from test.support import cpython_only, force_not_colorized, os_helper |
| 9 | +from test.support import cpython_only, force_not_colorized, os_helper, requires_subprocess |
10 | 10 | from test.support.import_helper import ensure_lazy_imports |
| 11 | +from test.support.script_helper import assert_python_ok, assert_python_failure |
11 | 12 |
|
12 | 13 | try: |
13 | 14 | import _winapi |
@@ -508,5 +509,51 @@ def test_invocation_error(self): |
508 | 509 | self.assertEqual(result, expected) |
509 | 510 |
|
510 | 511 |
|
| 512 | +@requires_subprocess() |
| 513 | +class CommandLineSubprocessTest(unittest.TestCase): |
| 514 | + def test_help(self): |
| 515 | + rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', '--help') |
| 516 | + self.assertIn(b'mimetypes', stdout) |
| 517 | + self.assertIn(b'--help', stdout) |
| 518 | + self.assertIn(b'--extension', stdout) |
| 519 | + self.assertIn(b'--lenient', stdout) |
| 520 | + |
| 521 | + def test_type_lookup(self): |
| 522 | + rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', 'foo.pdf') |
| 523 | + self.assertIn(b'application/pdf', stdout) |
| 524 | + |
| 525 | + def test_type_lookup_unknown(self): |
| 526 | + rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', 'foo.unknownext12345') |
| 527 | + self.assertIn(b'error:', stdout) |
| 528 | + |
| 529 | + def test_extension_flag(self): |
| 530 | + rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', '-e', 'image/jpeg') |
| 531 | + self.assertIn(b'.jpg', stdout) |
| 532 | + |
| 533 | + def test_extension_flag_unknown(self): |
| 534 | + rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', '-e', 'image/unknowntype12345') |
| 535 | + self.assertIn(b'error:', stdout) |
| 536 | + |
| 537 | + def test_lenient_flag(self): |
| 538 | + rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', '--lenient', 'foo.webp') |
| 539 | + self.assertIn(b'image/webp', stdout) |
| 540 | + |
| 541 | + def test_multiple_inputs(self): |
| 542 | + rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', 'foo.pdf', 'foo.png') |
| 543 | + self.assertIn(b'application/pdf', stdout) |
| 544 | + self.assertIn(b'image/png', stdout) |
| 545 | + |
| 546 | + def test_multiple_inputs_with_error(self): |
| 547 | + rc, stdout, stderr = assert_python_failure( |
| 548 | + '-m', 'mimetypes', 'foo.pdf', 'foo.unknownext12345' |
| 549 | + ) |
| 550 | + self.assertIn(b'application/pdf', stdout) |
| 551 | + self.assertIn(b'error:', stdout) |
| 552 | + |
| 553 | + def test_unknown_flag(self): |
| 554 | + rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', '--unknown-flag') |
| 555 | + self.assertNotEqual(rc, 0) |
| 556 | + |
| 557 | + |
511 | 558 | if __name__ == "__main__": |
512 | 559 | unittest.main() |
0 commit comments