-
-
Notifications
You must be signed in to change notification settings - Fork 31k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh-90329: Add _winapi.GetLongPathName and GetShortPathName and use in…
… venv to reduce warnings (GH-117817)
- Loading branch information
Showing
6 changed files
with
333 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Test the Windows-only _winapi module | ||
|
||
import os | ||
import pathlib | ||
import re | ||
import unittest | ||
from test.support import import_helper | ||
|
||
_winapi = import_helper.import_module('_winapi', required_on=['win']) | ||
|
||
class WinAPITests(unittest.TestCase): | ||
def test_getlongpathname(self): | ||
testfn = pathlib.Path(os.getenv("ProgramFiles")).parents[-1] / "PROGRA~1" | ||
if not os.path.isdir(testfn): | ||
raise unittest.SkipTest("require x:\\PROGRA~1 to test") | ||
|
||
# pathlib.Path will be rejected - only str is accepted | ||
with self.assertRaises(TypeError): | ||
_winapi.GetLongPathName(testfn) | ||
|
||
actual = _winapi.GetLongPathName(os.fsdecode(testfn)) | ||
|
||
# Can't assume that PROGRA~1 expands to any particular variation, so | ||
# ensure it matches any one of them. | ||
candidates = set(testfn.parent.glob("Progra*")) | ||
self.assertIn(pathlib.Path(actual), candidates) | ||
|
||
def test_getshortpathname(self): | ||
testfn = pathlib.Path(os.getenv("ProgramFiles")) | ||
if not os.path.isdir(testfn): | ||
raise unittest.SkipTest("require '%ProgramFiles%' to test") | ||
|
||
# pathlib.Path will be rejected - only str is accepted | ||
with self.assertRaises(TypeError): | ||
_winapi.GetShortPathName(testfn) | ||
|
||
actual = _winapi.GetShortPathName(os.fsdecode(testfn)) | ||
|
||
# Should contain "PROGRA~" but we can't predict the number | ||
self.assertIsNotNone(re.match(r".\:\\PROGRA~\d", actual.upper()), actual) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Misc/NEWS.d/next/Windows/2024-04-12-14-02-58.gh-issue-90329.YpEeaO.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Suppress the warning displayed on virtual environment creation when the | ||
requested and created paths differ only by a short (8.3 style) name. | ||
Warnings will continue to be shown if a junction or symlink in the path | ||
caused the venv to be created in a different location than originally | ||
requested. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.