Skip to content

Commit 0cf86da

Browse files
authored
CM-23327 - Fix concat_unique_id on Windows (#116)
1 parent 344d1be commit 0cf86da

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

cycode/cli/zip_file.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ def __init__(self):
1111

1212
def append(self, filename, unique_id, content):
1313
# Write the file to the in-memory zip
14-
filename = filename if unique_id is None else concat_unique_id(filename, unique_id)
14+
if unique_id:
15+
filename = concat_unique_id(filename, unique_id)
16+
1517
self.zip.writestr(filename, content)
1618

1719
def close(self):
@@ -24,4 +26,8 @@ def read(self) -> bytes:
2426

2527

2628
def concat_unique_id(filename: str, unique_id: str) -> str:
27-
return f'{unique_id}{filename}' if filename.startswith(os.sep) else os.path.join(unique_id, filename)
29+
if filename.startswith(os.sep):
30+
# remove leading slash to join path correctly
31+
filename = filename[len(os.sep):]
32+
33+
return os.path.join(unique_id, filename)

tests/test_zip_file.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1+
import os
2+
13
from cycode.cli import zip_file
24

35

4-
def test_concat_unique_id_to_file_starting_with_seperator():
5-
assert zip_file.concat_unique_id('/path/to/file', 'unique_id') == 'unique_id/path/to/file'
6+
def test_concat_unique_id_to_file_with_leading_slash():
7+
filename = os.path.join('path', 'to', 'file') # we should care about slash characters in tests
8+
unique_id = 'unique_id'
9+
10+
expected_path = os.path.join(unique_id, filename)
11+
12+
filename = os.sep + filename
13+
assert zip_file.concat_unique_id(filename, unique_id) == expected_path
14+
15+
16+
def test_concat_unique_id_to_file_without_leading_slash():
17+
filename = os.path.join('path', 'to', 'file') # we should care about slash characters in tests
18+
unique_id = 'unique_id'
619

20+
expected_path = os.path.join(unique_id, *filename.split('/'))
721

8-
def test_concat_unique_id_to_file_starting_without_seperator():
9-
assert zip_file.concat_unique_id('path/to/file', 'unique_id') == 'unique_id/path/to/file'
22+
assert zip_file.concat_unique_id(filename, unique_id) == expected_path

0 commit comments

Comments
 (0)