summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_site.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-01-16 18:23:05 (GMT)
committerGitHub <noreply@github.com>2024-01-16 18:23:05 (GMT)
commit74208ed0c440244fb809d8acc97cb9ef51e888e3 (patch)
treebed8286bdf0f63e38f55db4e5b1c50570e09629b /Lib/test/test_site.py
parent7a24ecc953e1edc9c5bbedbd19cc587c3ff635ea (diff)
downloadcpython-74208ed0c440244fb809d8acc97cb9ef51e888e3.zip
cpython-74208ed0c440244fb809d8acc97cb9ef51e888e3.tar.gz
cpython-74208ed0c440244fb809d8acc97cb9ef51e888e3.tar.bz2
gh-113659: Skip hidden .pth files (GH-113660)
Skip .pth files with names starting with a dot or hidden file attribute.
Diffstat (limited to 'Lib/test/test_site.py')
-rw-r--r--Lib/test/test_site.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index e26b48e..0502181 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -19,6 +19,7 @@ import io
import os
import re
import shutil
+import stat
import subprocess
import sys
import sysconfig
@@ -195,6 +196,45 @@ 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')
+ @support.requires_subprocess()
+ 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):