Skip to content

Commit 23c4d87

Browse files
committed
fix zipper test for windows
1 parent 8a03d79 commit 23c4d87

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

tests/tools/zipapp/zipper_test.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from tools.private.zipapp import zipper
1010

11+
def symlink_target_path(p):
12+
return p.replace("/", os.sep)
1113

1214
class ZipperTest(unittest.TestCase):
1315
def setUp(self):
@@ -26,7 +28,8 @@ def _create_zip(self, **kwargs):
2628
"workspace_name": "my_ws",
2729
"legacy_external_runfiles": False,
2830
"runfiles_dir": "runfiles",
29-
"platform_pathsep": "/",
31+
# We need to generate paths for the platform we're running on.
32+
"platform_pathsep": os.sep,
3033
}
3134
defaults.update(kwargs)
3235
zipper.create_zip(**defaults)
@@ -106,7 +109,7 @@ def test_create_zip_with_direct_symlink(self):
106109
zf,
107110
"runfiles/path/to/link",
108111
is_symlink=True,
109-
target="../../target/path",
112+
target=symlink_target_path("../../target/path"),
110113
)
111114

112115
def test_pathsep_normalization(self):
@@ -159,7 +162,7 @@ def test_symlink_precedence(self):
159162
zf,
160163
"runfiles/my_ws/path/to/file",
161164
is_symlink=True,
162-
target="../../../symlink/target",
165+
target=symlink_target_path("../../../symlink/target"),
163166
)
164167

165168
def test_timestamps_are_deterministic(self):
@@ -289,6 +292,7 @@ def _extract_zip(self, zip_path, extract_dir):
289292
extract_path.parent.mkdir(parents=True, exist_ok=True)
290293
if self.is_symlink(info):
291294
target = zf.read(info).decode()
295+
# On Windows, relative symlinks must use backslashes to be readable
292296
os.symlink(target, extract_path)
293297
else:
294298
with zf.open(info) as src, open(extract_path, "wb") as dst:
@@ -317,7 +321,7 @@ def test_symlink_extraction(self):
317321

318322
link_path = extract_dir / "runfiles/my_ws/path/to/link"
319323
self.assertTrue(link_path.is_symlink(), f"{link_path} should be a symlink")
320-
self.assertEqual(os.readlink(link_path), "../../target/path")
324+
self.assertEqual(os.readlink(link_path), "../../target/path".replace("/", os.path.sep))
321325
self.assertEqual(link_path.read_text(), "target content")
322326

323327
link2_path = extract_dir / "runfiles/my_ws/same_dir_link"

0 commit comments

Comments
 (0)