summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sys.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-06-29 22:49:03 (GMT)
committerGitHub <noreply@github.com>2020-06-29 22:49:03 (GMT)
commitdd8a93e23b5c4f9290e1cea6183d97eb9b5e61c0 (patch)
treee313d1898cff674146bfb1fef17f082f56628ed4 /Lib/test/test_sys.py
parent2fb5f038f2a2e91a7293d62dfd5601e6eb500c55 (diff)
downloadcpython-dd8a93e23b5c4f9290e1cea6183d97eb9b5e61c0.zip
cpython-dd8a93e23b5c4f9290e1cea6183d97eb9b5e61c0.tar.gz
cpython-dd8a93e23b5c4f9290e1cea6183d97eb9b5e61c0.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_sys.py')
-rw-r--r--Lib/test/test_sys.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 194128e..aaba663 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -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):