File tree Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Original file line number Diff line number Diff 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
2628def  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 )
Original file line number Diff line number Diff line change 1+ import  os 
2+ 
13from  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 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments