@@ -533,33 +533,45 @@ class TestRealPathCallSitesWindowsUNC(TestBase):
533533 """
534534
535535 def test_bundle_relpath_does_not_raise_on_different_unc_roots (self ):
536- """os.path.relpath raises ValueError when realpath expands two drive-letter
537- paths to different UNC roots .
536+ """_adjust_variant_for_bundling must not raise ValueError when
537+ os.path.realpath would have expanded drive-letter paths to UNC form .
538538
539- Mirrors the pattern in resolved_context.py::
540- relpath(realpath(repo_path), realpath(bundle_path))
541-
542- This test currently FAILS because os.path.realpath expands N:\\ ->
543- \\ \\ nas\\ studio\\ and M:\\ -> \\ \\ backup\\ bundles\\ , making relpath
544- raise ValueError (can't make-relative across different UNC roots).
545- Fix: replace both realpath() calls with real_path().
539+ Exercises the real call site in resolved_context.py. is_subdirectory
540+ is mocked True to force the relpath branch. With real_path() (abspath)
541+ the drive-letter form is preserved and os.path.relpath succeeds.
546542 """
547- repo_path = "N:\\ packages\\ mypkg"
548- bundle_path = "M:\\ bundles\\ mybundle"
549-
550- with unittest .mock .patch ("os.path.realpath" , side_effect = _multi_drive_unc_realpath ):
543+ from rez .resolved_context import ResolvedContext
544+
545+ bundle_path = "N:\\ bundles\\ mybundle"
546+ repo_path = "N:\\ bundles\\ mybundle\\ packages\\ mypkg"
547+
548+ handle = {
549+ "variables" : {
550+ "repository_type" : "filesystem" ,
551+ "location" : repo_path ,
552+ }
553+ }
554+
555+ with unittest .mock .patch .object (
556+ ResolvedContext , "_get_bundle_path" , return_value = bundle_path
557+ ), unittest .mock .patch (
558+ "rez.resolved_context.is_subdirectory" , return_value = True
559+ ):
551560 try :
552- os .path .relpath (
553- os .path .realpath (repo_path ),
554- os .path .realpath (bundle_path ),
555- )
556- except ValueError :
561+ ResolvedContext ._adjust_variant_for_bundling (handle , out = True )
562+ except ValueError as e :
557563 self .fail (
558- "os.path.realpath expanded drive-letter paths to different "
559- "UNC roots, causing os.path.relpath to raise ValueError. "
560- "Replace os.path.realpath with real_path() at this call site."
564+ "_adjust_variant_for_bundling raised ValueError: %s \n "
565+ "Ensure real_path() (not os.path.realpath) is used at "
566+ "the os.path.relpath call site in resolved_context.py." % e
561567 )
562568
569+ self .assertNotEqual (
570+ handle ["variables" ]["location" ],
571+ repo_path ,
572+ "Expected location to be updated to a relative path, was unchanged." ,
573+ )
574+
563575 def test_bundle_relpath_must_not_use_canonical_path_regression (self ):
564576 """canonical_path lowercases the path, which corrupts case-sensitive
565577 path components stored in bundle files.
0 commit comments