mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-23427: Add sys.orig_argv attribute (GH-20729)
Add sys.orig_argv attribute: the list of the original command line arguments passed to the Python executable. Rename also PyConfig._orig_argv to PyConfig.orig_argv and document it.
This commit is contained in:
parent
2fb5f038f2
commit
dd8a93e23b
9 changed files with 104 additions and 35 deletions
|
@ -434,6 +434,11 @@ class SysModuleTest(unittest.TestCase):
|
|||
def test_attributes(self):
|
||||
self.assertIsInstance(sys.api_version, int)
|
||||
self.assertIsInstance(sys.argv, list)
|
||||
for arg in sys.argv:
|
||||
self.assertIsInstance(arg, str)
|
||||
self.assertIsInstance(sys.orig_argv, list)
|
||||
for arg in sys.orig_argv:
|
||||
self.assertIsInstance(arg, str)
|
||||
self.assertIn(sys.byteorder, ("little", "big"))
|
||||
self.assertIsInstance(sys.builtin_module_names, tuple)
|
||||
self.assertIsInstance(sys.copyright, str)
|
||||
|
@ -930,6 +935,21 @@ class SysModuleTest(unittest.TestCase):
|
|||
out = out.decode('ascii', 'replace').rstrip()
|
||||
self.assertEqual(out, 'mbcs replace')
|
||||
|
||||
def test_orig_argv(self):
|
||||
code = textwrap.dedent('''
|
||||
import sys
|
||||
print(sys.argv)
|
||||
print(sys.orig_argv)
|
||||
''')
|
||||
args = [sys.executable, '-I', '-X', 'utf8', '-c', code, 'arg']
|
||||
proc = subprocess.run(args, check=True, capture_output=True, text=True)
|
||||
expected = [
|
||||
repr(['-c', 'arg']), # sys.argv
|
||||
repr(args), # sys.orig_argv
|
||||
]
|
||||
self.assertEqual(proc.stdout.rstrip().splitlines(), expected,
|
||||
proc)
|
||||
|
||||
|
||||
@test.support.cpython_only
|
||||
class UnraisableHookTest(unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue