@@ -900,20 +900,17 @@ def test_executable_symlink(self):
900900 Test creation using a symlink to python executable.
901901 """
902902 rmtree (self .env_dir )
903- with tempfile .TemporaryDirectory () as symlink_dir :
904- executable_symlink = os .path .join (
905- os .path .realpath (symlink_dir ),
906- os .path .basename (sys .executable ))
907- os .symlink (os .path .abspath (sys .executable ), executable_symlink )
908- cmd = [executable_symlink , "-m" , "venv" , "--without-pip" ,
909- self .env_dir ]
903+ exe = pathlib .Path (sys .executable ).absolute ()
904+ with tempfile .TemporaryDirectory () as tmp_dir :
905+ symlink_dir = pathlib .Path (tmp_dir ).resolve (strict = True )
906+ exe_symlink = symlink_dir / exe .name
907+ exe_symlink .symlink_to (exe )
908+ cmd = [exe_symlink , "-m" , "venv" , "--without-pip" , self .env_dir ]
910909 subprocess .check_call (cmd )
911910 data = self .get_text_file_contents ('pyvenv.cfg' )
912- executable = sys ._base_executable
913- path = os .path .dirname (executable )
911+ path = os .path .dirname (sys ._base_executable )
914912 self .assertIn ('home = %s' % path , data )
915- self .assertIn ('executable = %s' %
916- os .path .realpath (sys .executable ), data )
913+ self .assertIn ('executable = %s' % exe .resolve (), data )
917914
918915 @requires_subprocess ()
919916 @unittest .skipIf (os .name == 'nt' , 'not relevant on Windows' )
@@ -924,24 +921,18 @@ def test_tree_symlink(self):
924921 Test creation using a symlink to python tree.
925922 """
926923 rmtree (self .env_dir )
927- executable_abspath = os .path .abspath (sys ._base_executable )
928- tree_abspath = os .path .dirname (os .path .dirname (executable_abspath ))
929- with tempfile .TemporaryDirectory () as symlink_dir :
930- tree_symlink = os .path .join (
931- os .path .realpath (symlink_dir ),
932- os .path .basename (tree_abspath ))
933- executable_symlink = os .path .join (
934- tree_symlink ,
935- os .path .basename (os .path .dirname (executable_abspath )),
936- os .path .basename (sys ._base_executable ))
937- os .symlink (tree_abspath , tree_symlink )
938- cmd = [executable_symlink , "-m" , "venv" , "--without-pip" ,
939- self .env_dir ]
924+ exe = pathlib .Path (sys ._base_executable ).absolute ()
925+ tree = exe .parent .parent
926+ with tempfile .TemporaryDirectory () as tmp_dir :
927+ symlink_dir = pathlib .Path (tmp_dir ).resolve (strict = True )
928+ tree_symlink = symlink_dir / tree .name
929+ exe_symlink = tree_symlink / exe .relative_to (tree )
930+ tree_symlink .symlink_to (tree )
931+ cmd = [exe_symlink , "-m" , "venv" , "--without-pip" , self .env_dir ]
940932 subprocess .check_call (cmd )
941933 data = self .get_text_file_contents ('pyvenv.cfg' )
942934 self .assertIn ('home = %s' % tree_symlink , data )
943- self .assertIn ('executable = %s' %
944- os .path .realpath (sys ._base_executable ), data )
935+ self .assertIn ('executable = %s' % exe .resolve (), data )
945936
946937
947938@requireVenvCreate
0 commit comments