|
3 | 3 |
|
4 | 4 | from idlelib import pyshell |
5 | 5 | import os |
| 6 | +import sys |
6 | 7 | import unittest |
7 | | -from test.support import requires |
| 8 | +from unittest import mock |
| 9 | +from test.support import os_helper, requires |
| 10 | +from test.support.script_helper import assert_python_ok |
8 | 11 | from tkinter import Tk |
9 | 12 |
|
10 | 13 |
|
@@ -37,6 +40,24 @@ def test_fix_user_path(self): |
37 | 40 | eq(pyshell.fix_user_path(['/a', '/b']), ['/a', '/b']) |
38 | 41 | eq(pyshell.fix_user_path([idlelib_dir]), []) |
39 | 42 |
|
| 43 | + def test_shadowed_stdlib(self): |
| 44 | + # gh-70331: user files in the current directory must not shadow |
| 45 | + # the stdlib modules imported by IDLE. |
| 46 | + with os_helper.temp_dir() as cwd: |
| 47 | + for name in ('os', 'random', 'tkinter'): |
| 48 | + os_helper.create_empty_file(os.path.join(cwd, f'{name}.py')) |
| 49 | + for module in 'idlelib', 'idlelib.idle', 'idlelib.pyshell': |
| 50 | + with self.subTest(module=module): |
| 51 | + assert_python_ok('-m', module, '-h', |
| 52 | + __isolated=False, __cwd=cwd) |
| 53 | + |
| 54 | + def test_build_subprocess_arglist(self): |
| 55 | + interp = mock.Mock(port=1234) |
| 56 | + args = pyshell.ModifiedInterpreter.build_subprocess_arglist(interp) |
| 57 | + # gh-70331: -P keeps the current directory out of sys.path. |
| 58 | + self.assertEqual(args[:2], [sys.executable, '-P']) |
| 59 | + self.assertEqual(args[-1], '1234') |
| 60 | + |
40 | 61 |
|
41 | 62 | class PyShellFileListTest(unittest.TestCase): |
42 | 63 |
|
|
0 commit comments