@@ -511,16 +511,30 @@ def _cleanup_underpth_exe(self, exe_file):
511511 os .unlink (_pth_file )
512512 os .unlink (exe_file )
513513
514+ @classmethod
515+ def _calc_sys_path_for_underpth_nosite (self , sys_prefix , lines ):
516+ sys_path = []
517+ for line in lines :
518+ if not line or line [0 ] == '#' :
519+ continue
520+ abs_path = os .path .abspath (os .path .join (sys_prefix , line ))
521+ sys_path .append (abs_path )
522+ return sys_path
523+
514524 @unittest .skipUnless (sys .platform == 'win32' , "only supported on Windows" )
515525 def test_underpth_nosite_file (self ):
516526 libpath = os .path .dirname (os .path .dirname (encodings .__file__ ))
517527 exe_prefix = os .path .dirname (sys .executable )
518- exe_file = self . _create_underpth_exe ( [
528+ pth_lines = [
519529 'fake-path-name' ,
520530 * [libpath for _ in range (200 )],
531+ '' ,
521532 '# comment' ,
522- 'import site'
523- ])
533+ ]
534+ exe_file = self ._create_underpth_exe (pth_lines )
535+ sys_path = self ._calc_sys_path_for_underpth_nosite (
536+ os .path .dirname (exe_file ),
537+ pth_lines )
524538
525539 try :
526540 env = os .environ .copy ()
@@ -529,14 +543,11 @@ def test_underpth_nosite_file(self):
529543 rc = subprocess .call ([exe_file , '-c' ,
530544 'import sys; sys.exit(sys.flags.no_site and '
531545 'len(sys.path) > 200 and '
532- '%r in sys.path and %r in sys.path and %r not in sys.path)' % (
533- os .path .join (sys .prefix , 'fake-path-name' ),
534- libpath ,
535- os .path .join (sys .prefix , 'from-env' ),
536- )], env = env )
546+ 'sys.path == %r)' % sys_path ,
547+ ], env = env )
537548 finally :
538549 self ._cleanup_underpth_exe (exe_file )
539- self .assertEqual (rc , 0 )
550+ self .assertTrue (rc , "sys.path is incorrect" )
540551
541552 @unittest .skipUnless (sys .platform == 'win32' , "only supported on Windows" )
542553 def test_underpth_file (self ):
@@ -545,23 +556,26 @@ def test_underpth_file(self):
545556 exe_file = self ._create_underpth_exe ([
546557 'fake-path-name' ,
547558 * [libpath for _ in range (200 )],
559+ '' ,
548560 '# comment' ,
549561 'import site'
550562 ])
563+ sys_prefix = os .path .dirname (exe_file )
551564 try :
552565 env = os .environ .copy ()
553566 env ['PYTHONPATH' ] = 'from-env'
554567 env ['PATH' ] = '{};{}' .format (exe_prefix , os .getenv ('PATH' ))
555568 rc = subprocess .call ([exe_file , '-c' ,
556569 'import sys; sys.exit(not sys.flags.no_site and '
557- '%r in sys.path and %r in sys.path and %r not in sys.path)' % (
558- os .path .join (sys .prefix , 'fake-path-name' ),
570+ '%r in sys.path and %r in sys.path and %r not in sys.path and '
571+ 'all("\\ r" not in p and "\\ n" not in p for p in sys.path))' % (
572+ os .path .join (sys_prefix , 'fake-path-name' ),
559573 libpath ,
560- os .path .join (sys . prefix , 'from-env' ),
574+ os .path .join (sys_prefix , 'from-env' ),
561575 )], env = env )
562576 finally :
563577 self ._cleanup_underpth_exe (exe_file )
564- self .assertEqual (rc , 0 )
578+ self .assertTrue (rc , "sys.path is incorrect" )
565579
566580
567581if __name__ == "__main__" :
0 commit comments