1212import textwrap
1313import unittest
1414import warnings
15- from test .support import no_tracing , verbose
15+ from test .support import (
16+ force_not_colorized_test_class ,
17+ infinite_recursion ,
18+ no_tracing ,
19+ requires_resource ,
20+ requires_subprocess ,
21+ verbose ,
22+ )
1623from test .support .import_helper import forget , make_legacy_pyc , unload
17- from test .support .os_helper import create_empty_file , temp_dir
24+ from test .support .os_helper import create_empty_file , temp_dir , FakePath
1825from test .support .script_helper import make_script , make_zip_script
1926
2027
@@ -656,13 +663,14 @@ def test_basic_script(self):
656663 self ._check_script (script_name , "<run_path>" , script_name ,
657664 script_name , expect_spec = False )
658665
659- def test_basic_script_with_path_object (self ):
666+ def test_basic_script_with_pathlike_object (self ):
660667 with temp_dir () as script_dir :
661668 mod_name = 'script'
662- script_name = pathlib .Path (self ._make_test_script (script_dir ,
663- mod_name ))
664- self ._check_script (script_name , "<run_path>" , script_name ,
665- script_name , expect_spec = False )
669+ script_name = self ._make_test_script (script_dir , mod_name )
670+ self ._check_script (FakePath (script_name ), "<run_path>" ,
671+ script_name ,
672+ script_name ,
673+ expect_spec = False )
666674
667675 def test_basic_script_no_suffix (self ):
668676 with temp_dir () as script_dir :
@@ -734,17 +742,18 @@ def test_zipfile_error(self):
734742 self ._check_import_error (zip_name , msg )
735743
736744 @no_tracing
745+ @requires_resource ('cpu' )
737746 def test_main_recursion_error (self ):
738747 with temp_dir () as script_dir , temp_dir () as dummy_dir :
739748 mod_name = '__main__'
740749 source = ("import runpy\n "
741750 "runpy.run_path(%r)\n " ) % dummy_dir
742751 script_name = self ._make_test_script (script_dir , mod_name , source )
743752 zip_name , fname = make_zip_script (script_dir , 'test_zip' , script_name )
744- self .assertRaises (RecursionError , run_path , zip_name )
753+ with infinite_recursion (25 ):
754+ self .assertRaises (RecursionError , run_path , zip_name )
745755
746- # TODO: RUSTPYTHON, detect encoding comments in files
747- @unittest .expectedFailure
756+ @unittest .expectedFailure # TODO: RUSTPYTHON; detect encoding comments in files
748757 def test_encoding (self ):
749758 with temp_dir () as script_dir :
750759 filename = os .path .join (script_dir , 'script.py' )
@@ -757,6 +766,7 @@ def test_encoding(self):
757766 self .assertEqual (result ['s' ], "non-ASCII: h\xe9 " )
758767
759768
769+ @force_not_colorized_test_class
760770class TestExit (unittest .TestCase ):
761771 STATUS_CONTROL_C_EXIT = 0xC000013A
762772 EXPECTED_CODE = (
@@ -783,16 +793,19 @@ def run(self, *args, **kwargs):
783793 )
784794 super ().run (* args , ** kwargs )
785795
786- def assertSigInt (self , * args , ** kwargs ):
787- proc = subprocess .run (* args , ** kwargs , text = True , stderr = subprocess .PIPE )
788- self .assertTrue (proc .stderr .endswith ("\n KeyboardInterrupt\n " ))
796+ @requires_subprocess ()
797+ def assertSigInt (self , cmd , * args , ** kwargs ):
798+ # Use -E to ignore PYTHONSAFEPATH
799+ cmd = [sys .executable , '-E' , * cmd ]
800+ proc = subprocess .run (cmd , * args , ** kwargs , text = True , stderr = subprocess .PIPE )
801+ self .assertTrue (proc .stderr .endswith ("\n KeyboardInterrupt\n " ), proc .stderr )
789802 self .assertEqual (proc .returncode , self .EXPECTED_CODE )
790803
791- @unittest .expectedFailureIfWindows ("TODO: RUSTPYTHON" )
804+ @unittest .expectedFailureIfWindows ("TODO: RUSTPYTHON; " )
792805 def test_pymain_run_file (self ):
793- self .assertSigInt ([sys . executable , self .ham ])
806+ self .assertSigInt ([self .ham ])
794807
795- @unittest .expectedFailureIfWindows ("TODO: RUSTPYTHON" )
808+ @unittest .expectedFailureIfWindows ("TODO: RUSTPYTHON; " )
796809 def test_pymain_run_file_runpy_run_module (self ):
797810 tmp = self .ham .parent
798811 run_module = tmp / "run_module.py"
@@ -804,9 +817,9 @@ def test_pymain_run_file_runpy_run_module(self):
804817 """
805818 )
806819 )
807- self .assertSigInt ([sys . executable , run_module ], cwd = tmp )
820+ self .assertSigInt ([run_module ], cwd = tmp )
808821
809- @unittest .expectedFailureIfWindows ("TODO: RUSTPYTHON" )
822+ @unittest .expectedFailureIfWindows ("TODO: RUSTPYTHON; " )
810823 def test_pymain_run_file_runpy_run_module_as_main (self ):
811824 tmp = self .ham .parent
812825 run_module_as_main = tmp / "run_module_as_main.py"
@@ -818,28 +831,27 @@ def test_pymain_run_file_runpy_run_module_as_main(self):
818831 """
819832 )
820833 )
821- self .assertSigInt ([sys . executable , run_module_as_main ], cwd = tmp )
834+ self .assertSigInt ([run_module_as_main ], cwd = tmp )
822835
823- @unittest .expectedFailureIfWindows ("TODO: RUSTPYTHON" )
836+ @unittest .expectedFailureIfWindows ("TODO: RUSTPYTHON; " )
824837 def test_pymain_run_command_run_module (self ):
825838 self .assertSigInt (
826- [sys . executable , "-c" , "import runpy; runpy.run_module('ham')" ],
839+ ["-c" , "import runpy; runpy.run_module('ham')" ],
827840 cwd = self .ham .parent ,
828841 )
829842
830- @unittest .expectedFailureIfWindows ("TODO: RUSTPYTHON" )
843+ @unittest .expectedFailureIfWindows ("TODO: RUSTPYTHON; " )
831844 def test_pymain_run_command (self ):
832- self .assertSigInt ([sys . executable , "-c" , "import ham" ], cwd = self .ham .parent )
845+ self .assertSigInt (["-c" , "import ham" ], cwd = self .ham .parent )
833846
834- # TODO: RUSTPYTHON
835- @unittest .expectedFailure
847+ @unittest .expectedFailure # TODO: RUSTPYTHON
836848 def test_pymain_run_stdin (self ):
837- self .assertSigInt ([sys . executable ], input = "import ham" , cwd = self .ham .parent )
849+ self .assertSigInt ([], input = "import ham" , cwd = self .ham .parent )
838850
839- @unittest .expectedFailureIfWindows ("TODO: RUSTPYTHON" )
851+ @unittest .expectedFailureIfWindows ("TODO: RUSTPYTHON; " )
840852 def test_pymain_run_module (self ):
841853 ham = self .ham
842- self .assertSigInt ([sys . executable , "-m" , ham .stem ], cwd = ham .parent )
854+ self .assertSigInt (["-m" , ham .stem ], cwd = ham .parent )
843855
844856
845857if __name__ == "__main__" :
0 commit comments