@@ -488,6 +488,58 @@ def test_startup_interactivehook_isolated_explicit(self):
488488 'import site, sys; site.enablerlcompleter(); sys.exit(hasattr(sys, "__interactivehook__"))' ]).wait ()
489489 self .assertTrue (r , "'__interactivehook__' not added by enablerlcompleter()" )
490490
491+ @unittest .skipUnless (sys .platform == 'win32' , "only supported on Windows" )
492+ def test_underpth_nosite_file (self ):
493+ _pth_file = os .path .splitext (sys .executable )[0 ] + '._pth'
494+ try :
495+ libpath = os .path .dirname (os .path .dirname (encodings .__file__ ))
496+ with open (_pth_file , 'w' ) as f :
497+ print ('fake-path-name' , file = f )
498+ # Ensure the generated path is very long so that buffer
499+ # resizing in getpathp.c is exercised
500+ for _ in range (200 ):
501+ print (libpath , file = f )
502+ print ('# comment' , file = f )
503+
504+ env = os .environ .copy ()
505+ env ['PYTHONPATH' ] = 'from-env'
506+ rc = subprocess .call ([sys .executable , '-c' ,
507+ 'import sys; sys.exit(sys.flags.no_site and '
508+ 'len(sys.path) > 200 and '
509+ '%r in sys.path and %r in sys.path and %r not in sys.path)' % (
510+ os .path .join (sys .prefix , 'fake-path-name' ),
511+ libpath ,
512+ os .path .join (sys .prefix , 'from-env' ),
513+ )], env = env )
514+ self .assertEqual (rc , 0 )
515+ finally :
516+ os .unlink (_pth_file )
517+
518+ @unittest .skipUnless (sys .platform == 'win32' , "only supported on Windows" )
519+ def test_underpth_file (self ):
520+ _pth_file = os .path .splitext (sys .executable )[0 ] + '._pth'
521+ try :
522+ libpath = os .path .dirname (os .path .dirname (encodings .__file__ ))
523+ with open (_pth_file , 'w' ) as f :
524+ print ('fake-path-name' , file = f )
525+ for _ in range (200 ):
526+ print (libpath , file = f )
527+ print ('# comment' , file = f )
528+ print ('import site' , file = f )
529+
530+ env = os .environ .copy ()
531+ env ['PYTHONPATH' ] = 'from-env'
532+ rc = subprocess .call ([sys .executable , '-c' ,
533+ 'import sys; sys.exit(not sys.flags.no_site and '
534+ '%r in sys.path and %r in sys.path and %r not in sys.path)' % (
535+ os .path .join (sys .prefix , 'fake-path-name' ),
536+ libpath ,
537+ os .path .join (sys .prefix , 'from-env' ),
538+ )], env = env )
539+ self .assertEqual (rc , 0 )
540+ finally :
541+ os .unlink (_pth_file )
542+
491543
492544if __name__ == "__main__" :
493545 unittest .main ()
0 commit comments