summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_winapi.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2024-04-15 14:36:06 (GMT)
committerGitHub <noreply@github.com>2024-04-15 14:36:06 (GMT)
commit185999bb3ad3f1484da8fa4b84813980b976dc3c (patch)
treed288110bc9bac2e1459443a9a9d34ce12ac663b8 /Lib/test/test_winapi.py
parent64cd6fc9a6a3c3c19091a1c81cbbe8994583017d (diff)
downloadcpython-185999bb3ad3f1484da8fa4b84813980b976dc3c.zip
cpython-185999bb3ad3f1484da8fa4b84813980b976dc3c.tar.gz
cpython-185999bb3ad3f1484da8fa4b84813980b976dc3c.tar.bz2
gh-90329: Add _winapi.GetLongPathName and GetShortPathName and use in venv to reduce warnings (GH-117817)
Diffstat (limited to 'Lib/test/test_winapi.py')
-rw-r--r--Lib/test/test_winapi.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_winapi.py b/Lib/test/test_winapi.py
index 014aeea..2ac6f36 100644
--- a/Lib/test/test_winapi.py
+++ b/Lib/test/test_winapi.py
@@ -1,6 +1,9 @@
# Test the Windows-only _winapi module
+import os
+import pathlib
import random
+import re
import threading
import time
import unittest
@@ -92,3 +95,35 @@ class WinAPIBatchedWaitForMultipleObjectsTests(unittest.TestCase):
def test_max_events_waitany(self):
self._events_waitany_test(MAXIMUM_BATCHED_WAIT_OBJECTS)
+
+
+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)