@@ -116,7 +116,9 @@ def _check_output(self, script_name, exit_code, data,
116116 self .assertIn (printed_file .encode ('utf-8' ), data )
117117 self .assertIn (printed_package .encode ('utf-8' ), data )
118118 self .assertIn (printed_argv0 .encode ('utf-8' ), data )
119- self .assertIn (printed_path0 .encode ('utf-8' ), data )
119+ # PYTHONSAFEPATH=1 changes the default sys.path[0]
120+ if not sys .flags .safe_path :
121+ self .assertIn (printed_path0 .encode ('utf-8' ), data )
120122 self .assertIn (printed_cwd .encode ('utf-8' ), data )
121123
122124 def _check_script (self , script_exec_args , expected_file ,
@@ -492,7 +494,6 @@ def test_dash_m_errors(self):
492494 br'ModuleNotFoundError' ),
493495 ('builtins.x.y' , br'Error while finding module specification.*'
494496 br'ModuleNotFoundError.*No module named.*not a package' ),
495- ('os.path' , br'loader.*cannot handle' ),
496497 ('importlib' , br'No module named.*'
497498 br'is a package and cannot be directly executed' ),
498499 ('importlib.nonexistent' , br'No module named' ),
@@ -577,8 +578,9 @@ def test_non_ascii(self):
577578 # Mac OS X denies the creation of a file with an invalid UTF-8 name.
578579 # Windows allows creating a name with an arbitrary bytes name, but
579580 # Python cannot a undecodable bytes argument to a subprocess.
581+ # WASI does not permit invalid UTF-8 names.
580582 if (os_helper .TESTFN_UNDECODABLE
581- and sys .platform not in ('win32' , 'darwin' )):
583+ and sys .platform not in ('win32' , 'darwin' , 'emscripten' , 'wasi' )):
582584 name = os .fsdecode (os_helper .TESTFN_UNDECODABLE )
583585 elif os_helper .TESTFN_NONASCII :
584586 name = os_helper .TESTFN_NONASCII
@@ -770,14 +772,28 @@ def test_nonexisting_script(self):
770772 self .assertIn (": can't open file " , err )
771773 self .assertNotEqual (proc .returncode , 0 )
772774
773- # TODO: RUSTPYTHON
774- # def tearDownModule():
775- def test_main ():
776- support .run_unittest (CmdLineTest )
775+ @unittest .skipUnless (os .path .exists ('/dev/fd/0' ), 'requires /dev/fd platform' )
776+ @unittest .skipIf (sys .platform .startswith ("freebsd" ) and
777+ os .stat ("/dev" ).st_dev == os .stat ("/dev/fd" ).st_dev ,
778+ "Requires fdescfs mounted on /dev/fd on FreeBSD" )
779+ @unittest .skipIf (sys .platform .startswith ("darwin" ), "TODO: RUSTPYTHON Problems with Mac os descriptor" )
780+ def test_script_as_dev_fd (self ):
781+ # GH-87235: On macOS passing a non-trivial script to /dev/fd/N can cause
782+ # problems because all open /dev/fd/N file descriptors share the same
783+ # offset.
784+ script = 'print("12345678912345678912345")'
785+ with os_helper .temp_dir () as work_dir :
786+ script_name = _make_test_script (work_dir , 'script.py' , script )
787+ with open (script_name , "r" ) as fp :
788+ p = spawn_python (f"/dev/fd/{ fp .fileno ()} " , close_fds = False , pass_fds = (0 ,1 ,2 ,fp .fileno ()))
789+ out , err = p .communicate ()
790+ self .assertEqual (out , b"12345678912345678912345\n " )
791+
792+
793+
794+ def tearDownModule ():
777795 support .reap_children ()
778796
779797
780798if __name__ == '__main__' :
781- # TODO: RUSTPYTHON
782- # unittest.main()
783- test_main ()
799+ unittest .main ()
0 commit comments