mirror of
https://github.com/python/cpython.git
synced 2025-08-09 19:38:42 +00:00
[3.9] gh-113659: Skip hidden .pth files (GH-113660) (GH-114146)
(cherry picked from commit 74208ed0c4
)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
dd068eaf48
commit
8fc8c45b67
3 changed files with 50 additions and 1 deletions
|
@ -16,6 +16,7 @@ import glob
|
|||
import os
|
||||
import re
|
||||
import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import sysconfig
|
||||
|
@ -185,6 +186,44 @@ class HelperFunctionsTests(unittest.TestCase):
|
|||
finally:
|
||||
pth_file.cleanup()
|
||||
|
||||
def test_addsitedir_dotfile(self):
|
||||
pth_file = PthFile('.dotfile')
|
||||
pth_file.cleanup(prep=True)
|
||||
try:
|
||||
pth_file.create()
|
||||
site.addsitedir(pth_file.base_dir, set())
|
||||
self.assertNotIn(site.makepath(pth_file.good_dir_path)[0], sys.path)
|
||||
self.assertIn(pth_file.base_dir, sys.path)
|
||||
finally:
|
||||
pth_file.cleanup()
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'chflags'), 'test needs os.chflags()')
|
||||
def test_addsitedir_hidden_flags(self):
|
||||
pth_file = PthFile()
|
||||
pth_file.cleanup(prep=True)
|
||||
try:
|
||||
pth_file.create()
|
||||
st = os.stat(pth_file.file_path)
|
||||
os.chflags(pth_file.file_path, st.st_flags | stat.UF_HIDDEN)
|
||||
site.addsitedir(pth_file.base_dir, set())
|
||||
self.assertNotIn(site.makepath(pth_file.good_dir_path)[0], sys.path)
|
||||
self.assertIn(pth_file.base_dir, sys.path)
|
||||
finally:
|
||||
pth_file.cleanup()
|
||||
|
||||
@unittest.skipUnless(sys.platform == 'win32', 'test needs Windows')
|
||||
def test_addsitedir_hidden_file_attribute(self):
|
||||
pth_file = PthFile()
|
||||
pth_file.cleanup(prep=True)
|
||||
try:
|
||||
pth_file.create()
|
||||
subprocess.check_call(['attrib', '+H', pth_file.file_path])
|
||||
site.addsitedir(pth_file.base_dir, set())
|
||||
self.assertNotIn(site.makepath(pth_file.good_dir_path)[0], sys.path)
|
||||
self.assertIn(pth_file.base_dir, sys.path)
|
||||
finally:
|
||||
pth_file.cleanup()
|
||||
|
||||
# This tests _getuserbase, hence the double underline
|
||||
# to distinguish from a test for getuserbase
|
||||
def test__getuserbase(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue