Skip to content

Commit 6111fd2

Browse files
committed
relink.py: Add test_multiple_files_nested.
1 parent a551c4a commit 6111fd2

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

tests/relink/test_replace_files_with_symlinks.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,50 @@ def test_multiple_files(temp_dirs, current_user):
178178
assert os.readlink(source_file) == target_file
179179

180180

181+
def test_multiple_files_nested(temp_dirs, current_user):
182+
"""Test with multiple files scattered throughout a nested directory tree."""
183+
source_dir, target_dir = temp_dirs
184+
username = current_user
185+
186+
# Create nested directory structure with files at different levels
187+
test_files = [
188+
"root_file1.txt",
189+
"root_file2.txt",
190+
os.path.join("level1", "file_a.txt"),
191+
os.path.join("level1", "file_b.txt"),
192+
os.path.join("level1", "subdir", "file_c.txt"),
193+
os.path.join("level2", "deep", "nested", "file_d.txt"),
194+
os.path.join("level2", "file_e.txt"),
195+
]
196+
197+
# Create all files and their parent directories
198+
for rel_path in test_files:
199+
source_file = os.path.join(source_dir, rel_path)
200+
target_file = os.path.join(target_dir, rel_path)
201+
202+
# Create parent directories
203+
os.makedirs(os.path.dirname(source_file), exist_ok=True)
204+
os.makedirs(os.path.dirname(target_file), exist_ok=True)
205+
206+
# Create files
207+
with open(source_file, "w", encoding="utf-8") as f:
208+
f.write(f"source content for {rel_path}")
209+
with open(target_file, "w", encoding="utf-8") as f:
210+
f.write(f"target content for {rel_path}")
211+
212+
# Run the function
213+
relink.replace_files_with_symlinks(source_dir, target_dir, username)
214+
215+
# Verify all files are now symlinks pointing to correct targets
216+
for rel_path in test_files:
217+
source_file = os.path.join(source_dir, rel_path)
218+
target_file = os.path.join(target_dir, rel_path)
219+
assert os.path.islink(source_file), f"{source_file} should be a symlink"
220+
assert (
221+
os.readlink(source_file) == target_file
222+
), f"{source_file} should point to {target_file}"
223+
224+
181225
def test_absolute_paths(temp_dirs, current_user):
182226
"""Test that function handles relative paths by converting to absolute."""
183227
source_dir, target_dir = temp_dirs

0 commit comments

Comments
 (0)