mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-90329: Add _winapi.GetLongPathName and GetShortPathName and use in venv to reduce warnings (GH-117817)
This commit is contained in:
parent
64cd6fc9a6
commit
185999bb3a
6 changed files with 328 additions and 3 deletions
|
@ -23,7 +23,8 @@ from test.support import (captured_stdout, captured_stderr,
|
|||
is_emscripten, is_wasi,
|
||||
requires_venv_with_pip, TEST_HOME_DIR,
|
||||
requires_resource, copy_python_src_ignore)
|
||||
from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree)
|
||||
from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree,
|
||||
TESTFN)
|
||||
import unittest
|
||||
import venv
|
||||
from unittest.mock import patch, Mock
|
||||
|
@ -744,6 +745,36 @@ class BasicTest(BaseTest):
|
|||
with self.assertRaises(FileNotFoundError):
|
||||
self.get_text_file_contents('.gitignore')
|
||||
|
||||
def test_venv_same_path(self):
|
||||
same_path = venv.EnvBuilder._same_path
|
||||
if sys.platform == 'win32':
|
||||
# Case-insensitive, and handles short/long names
|
||||
tests = [
|
||||
(True, TESTFN, TESTFN),
|
||||
(True, TESTFN.lower(), TESTFN.upper()),
|
||||
]
|
||||
import _winapi
|
||||
# ProgramFiles is the most reliable path that will have short/long
|
||||
progfiles = os.getenv('ProgramFiles')
|
||||
if progfiles:
|
||||
tests = [
|
||||
*tests,
|
||||
(True, progfiles, progfiles),
|
||||
(True, _winapi.GetShortPathName(progfiles), _winapi.GetLongPathName(progfiles)),
|
||||
]
|
||||
else:
|
||||
# Just a simple case-sensitive comparison
|
||||
tests = [
|
||||
(True, TESTFN, TESTFN),
|
||||
(False, TESTFN.lower(), TESTFN.upper()),
|
||||
]
|
||||
for r, path1, path2 in tests:
|
||||
with self.subTest(f"{path1}-{path2}"):
|
||||
if r:
|
||||
self.assertTrue(same_path(path1, path2))
|
||||
else:
|
||||
self.assertFalse(same_path(path1, path2))
|
||||
|
||||
@requireVenvCreate
|
||||
class EnsurePipTest(BaseTest):
|
||||
"""Test venv module installation of pip."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue