5
5
from pathlib import Path
6
6
7
7
import pytest
8
+ from helpers import print_tree
8
9
from pydantic import NonNegativeInt
9
10
from servicelib .archiving_utils ._interface_7zip import (
10
11
_7ZipProgressParser ,
@@ -61,12 +62,19 @@ async def _progress_handler(byte_progress: NonNegativeInt) -> None:
61
62
assert sum (detected_entries ) == expected_size
62
63
63
64
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
+
64
71
@pytest .mark .parametrize ("compress" , [True , False ])
65
72
async def test_archive_unarchive (
66
73
mixed_file_types : Path , archive_path : Path , unpacked_archive : Path , compress : bool
67
74
):
68
75
await archive_dir (mixed_file_types , archive_path , compress = compress )
69
76
await unarchive_dir (archive_path , unpacked_archive )
77
+ _assert_same_folder_content (mixed_file_types , unpacked_archive )
70
78
71
79
72
80
@pytest .fixture
@@ -82,6 +90,7 @@ async def test_archive_unarchive_empty_folder(
82
90
):
83
91
await archive_dir (empty_folder , archive_path , compress = compress )
84
92
await unarchive_dir (archive_path , unpacked_archive )
93
+ _assert_same_folder_content (empty_folder , unpacked_archive )
85
94
86
95
87
96
@pytest .mark .parametrize (
@@ -102,3 +111,27 @@ def test__extract_file_names_from_archive(
102
111
archive_list_stdout_path .read_text ()
103
112
files = _extract_file_names_from_archive (archive_list_stdout_path .read_text ())
104
113
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