55from pathlib import Path
66
77import pytest
8+ from helpers import print_tree
89from pydantic import NonNegativeInt
910from servicelib .archiving_utils ._interface_7zip import (
1011 _7ZipProgressParser ,
@@ -61,12 +62,19 @@ async def _progress_handler(byte_progress: NonNegativeInt) -> None:
6162 assert sum (detected_entries ) == expected_size
6263
6364
65+ def _assert_same_folder_content (f1 : Path , f2 : Path ) -> None :
66+ in_f1 = {x .relative_to (f1 ) for x in f1 .rglob ("*" )}
67+ in_f2 = {x .relative_to (f2 ) for x in f2 .rglob ("*" )}
68+ assert in_f1 == in_f2
69+
70+
6471@pytest .mark .parametrize ("compress" , [True , False ])
6572async def test_archive_unarchive (
6673 mixed_file_types : Path , archive_path : Path , unpacked_archive : Path , compress : bool
6774):
6875 await archive_dir (mixed_file_types , archive_path , compress = compress )
6976 await unarchive_dir (archive_path , unpacked_archive )
77+ _assert_same_folder_content (mixed_file_types , unpacked_archive )
7078
7179
7280@pytest .fixture
@@ -82,6 +90,7 @@ async def test_archive_unarchive_empty_folder(
8290):
8391 await archive_dir (empty_folder , archive_path , compress = compress )
8492 await unarchive_dir (archive_path , unpacked_archive )
93+ _assert_same_folder_content (empty_folder , unpacked_archive )
8594
8695
8796@pytest .mark .parametrize (
@@ -102,3 +111,27 @@ def test__extract_file_names_from_archive(
102111 archive_list_stdout_path .read_text ()
103112 files = _extract_file_names_from_archive (archive_list_stdout_path .read_text ())
104113 assert len (files ) == expected_file_count
114+
115+
116+ @pytest .mark .parametrize ("compress" , [True , False ])
117+ async def test_archive_unarchive_with_names_with_spaces (tmp_path : Path , compress : bool ):
118+ to_archive_path = tmp_path / "'source of files!a ads now strange'"
119+ to_archive_path .mkdir (parents = True , exist_ok = True )
120+ assert to_archive_path .exists ()
121+
122+ # generate some content
123+ for i in range (10 ):
124+ (to_archive_path / f"f{ i } .txt" ).write_text ("*" * i )
125+ print_tree (to_archive_path )
126+
127+ archive_path = tmp_path / "archived version herre!)!(/£)!'"
128+ assert not archive_path .exists ()
129+
130+ extracted_to_path = tmp_path / "this is where i want them to be extracted to''''"
131+ extracted_to_path .mkdir (parents = True , exist_ok = True )
132+ assert extracted_to_path .exists ()
133+
134+ # source and destination all with spaces
135+ await archive_dir (to_archive_path , archive_path , compress = compress )
136+ await unarchive_dir (archive_path , extracted_to_path )
137+ _assert_same_folder_content (to_archive_path , extracted_to_path )
0 commit comments