@@ -198,6 +198,24 @@ def test_drive_letter_case_folded(self):
198198 )
199199
200200
201+ def _windows_longpaths_enabled () -> bool :
202+ """Return True if the Windows LongPathsEnabled registry key is set.
203+
204+ When False, the Win32 API cannot open paths longer than MAX_PATH (260
205+ chars) without an explicit ``\\ ?\\ `` extended-length prefix.
206+ """
207+ try :
208+ import winreg
209+ with winreg .OpenKey (
210+ winreg .HKEY_LOCAL_MACHINE ,
211+ r"SYSTEM\CurrentControlSet\Control\FileSystem" ,
212+ ) as key :
213+ value , _ = winreg .QueryValueEx (key , "LongPathsEnabled" )
214+ return bool (value )
215+ except OSError :
216+ return False
217+
218+
201219@unittest .skipIf (
202220 platform_ .name != "windows" ,
203221 "Windows symlink/junction resolution tests are Windows-only." ,
@@ -267,3 +285,21 @@ def test_non_symlink_path_unchanged(self):
267285
268286 result = canonical_path (d , platform = self ._mock_windows_platform ())
269287 self .assertEqual (result , d .lower ())
288+
289+ def test_long_path_symlink_resolved (self ):
290+ """canonical_path resolves a symlink whose target exceeds MAX_PATH (260
291+ chars) on hosts with LongPathsEnabled set in the registry."""
292+ if not _windows_longpaths_enabled ():
293+ self .skipTest (
294+ "LongPathsEnabled not set in registry; skipping long-path test."
295+ )
296+
297+ # self.root is typically ~60-70 chars; 220 'a' chars puts the full
298+ # target path comfortably past the 260-char Win32 MAX_PATH limit.
299+ target = os .path .join (self .root , "a" * 220 )
300+ link = os .path .join (self .root , "longpath_link" )
301+ os .makedirs (target )
302+ os .symlink (target , link , target_is_directory = True )
303+
304+ result = canonical_path (link , platform = self ._windows_platform_mock ())
305+ self .assertEqual (result , target .lower ())
0 commit comments