@@ -28,32 +28,55 @@ def _kill_python_and_exit_code(p):
2828 returncode = p .wait ()
2929 return data , returncode
3030
31+
3132class CmdLineTest (unittest .TestCase ):
3233 def test_directories (self ):
3334 assert_python_failure ('.' )
3435 assert_python_failure ('< .' )
3536
3637 def verify_valid_flag (self , cmd_line ):
37- rc , out , err = assert_python_ok (* cmd_line )
38+ rc , out , err = assert_python_ok (cmd_line )
3839 self .assertTrue (out == b'' or out .endswith (b'\n ' ))
3940 self .assertNotIn (b'Traceback' , out )
4041 self .assertNotIn (b'Traceback' , err )
42+ return out
4143
42- def test_optimize (self ):
43- self .verify_valid_flag ('-O' )
44- self .verify_valid_flag ('-OO' )
44+ def test_help (self ):
45+ self .verify_valid_flag ('-h' )
46+ self .verify_valid_flag ('-?' )
47+ out = self .verify_valid_flag ('--help' )
48+ lines = out .splitlines ()
49+ self .assertIn (b'usage' , lines [0 ])
50+ self .assertNotIn (b'PYTHONHOME' , out )
51+ self .assertNotIn (b'-X dev' , out )
52+ self .assertLess (len (lines ), 50 )
4553
46- def test_site_flag (self ):
47- self .verify_valid_flag ('-S' )
54+ def test_help_env (self ):
55+ out = self .verify_valid_flag ('--help-env' )
56+ self .assertIn (b'PYTHONHOME' , out )
57+
58+ def test_help_xoptions (self ):
59+ out = self .verify_valid_flag ('--help-xoptions' )
60+ self .assertIn (b'-X dev' , out )
4861
49- def test_usage (self ):
50- rc , out , err = assert_python_ok ('-h ' )
62+ def test_help_all (self ):
63+ out = self . verify_valid_flag ('--help-all ' )
5164 lines = out .splitlines ()
5265 self .assertIn (b'usage' , lines [0 ])
66+ self .assertIn (b'PYTHONHOME' , out )
67+ self .assertIn (b'-X dev' , out )
68+
5369 # The first line contains the program name,
5470 # but the rest should be ASCII-only
5571 b'' .join (lines [1 :]).decode ('ascii' )
5672
73+ def test_optimize (self ):
74+ self .verify_valid_flag ('-O' )
75+ self .verify_valid_flag ('-OO' )
76+
77+ def test_site_flag (self ):
78+ self .verify_valid_flag ('-S' )
79+
5780 def test_version (self ):
5881 version = ('Python %d.%d' % sys .version_info [:2 ]).encode ("ascii" )
5982 for switch in '-V' , '--version' , '-VV' :
@@ -93,7 +116,7 @@ def get_xoptions(*args):
93116 def test_unknown_xoptions (self ):
94117 rc , out , err = assert_python_failure ('-X' , 'blech' )
95118 self .assertIn (b'Unknown value for option -X' , err )
96- msg = b'Fatal Python error: Unknown value for option -X'
119+ msg = b'Fatal Python error: Unknown value for option -X (see --help-xoptions) '
97120 self .assertEqual (err .splitlines ().count (msg ), 1 )
98121 self .assertEqual (b'' , out )
99122
@@ -137,7 +160,6 @@ def test_xoption_frozen_modules(self):
137160 }
138161 for raw , expected in tests :
139162 cmd = ['-X' , f'frozen_modules{ raw } ' ,
140- #'-c', 'import os; print(os.__spec__.loader.__name__, end="")']
141163 '-c' , 'import os; print(os.__spec__.loader, end="")' ]
142164 with self .subTest (raw ):
143165 res = assert_python_ok (* cmd )
@@ -170,7 +192,6 @@ def test_relativedir_bug46421(self):
170192 # Test `python -m unittest` with a relative directory beginning with ./
171193 # Note: We have to switch to the project's top module's directory, as per
172194 # the python unittest wiki. We will switch back when we are done.
173- defaultwd = os .getcwd ()
174195 projectlibpath = os .path .dirname (__file__ ).removesuffix ("test" )
175196 with os_helper .change_cwd (projectlibpath ):
176197 # Testing with and without ./
@@ -250,7 +271,6 @@ def test_invalid_utf8_arg(self):
250271 #
251272 # Test with default config, in the C locale, in the Python UTF-8 Mode.
252273 code = 'import sys, os; s=os.fsencode(sys.argv[1]); print(ascii(s))'
253- base_cmd = [sys .executable , '-c' , code ]
254274
255275 def run_default (arg ):
256276 cmd = [sys .executable , '-c' , code , arg ]
@@ -895,6 +915,7 @@ def test_sys_flags_not_set(self):
895915 PYTHONSAFEPATH = "1" ,
896916 )
897917
918+
898919class SyntaxErrorTests (unittest .TestCase ):
899920 def check_string (self , code ):
900921 proc = subprocess .run ([sys .executable , "-" ], input = code ,
0 commit comments