1212from unittest .mock import patch , call
1313import pytest
1414
15+ import shared
16+
1517# Add parent directory to path to import relink module
1618sys .path .insert (
1719 0 , os .path .dirname (os .path .dirname (os .path .dirname (os .path .abspath (__file__ ))))
2022import relink # noqa: E402
2123
2224
25+ @pytest .fixture (autouse = True )
26+ def configure_logging_for_tests ():
27+ """Configure logging for all tests in this module."""
28+ shared .configure_logging (logging .INFO )
29+ yield
30+ # Cleanup
31+ relink .logger .handlers .clear ()
32+
33+
2334@pytest .fixture (name = "mock_replace_one" )
2435def fixture_mock_replace_one ():
2536 """Fixture that mocks relink.replace_one_file_with_symlink"""
2637 with patch ("relink.replace_one_file_with_symlink" ) as mock :
2738 yield mock
2839
2940
30- def test_basic_file_replacement_given_dir (temp_dirs , current_user , mock_replace_one ):
41+ def test_basic_file_replacement_given_dir (temp_dirs , current_user , mock_replace_one , caplog ):
3142 """Test basic functionality: given directory, replace owned file with symlink."""
3243 inputdata_root , target_dir = temp_dirs
3344 username = current_user
@@ -55,8 +66,11 @@ def test_basic_file_replacement_given_dir(temp_dirs, current_user, mock_replace_
5566 dry_run = False ,
5667 )
5768
69+ # Verify message with filename was printed
70+ assert f"'{ source_file } ':" in caplog .text
5871
59- def test_basic_file_replacement_given_file (temp_dirs , current_user , mock_replace_one ):
72+
73+ def test_basic_file_replacement_given_file (temp_dirs , current_user , mock_replace_one , caplog ):
6074 """Test basic functionality: given owned file, replace with symlink."""
6175 inputdata_root , target_dir = temp_dirs
6276 username = current_user
@@ -84,8 +98,11 @@ def test_basic_file_replacement_given_file(temp_dirs, current_user, mock_replace
8498 dry_run = False ,
8599 )
86100
101+ # Verify message with filename was printed
102+ assert f"'{ source_file } ':" in caplog .text
103+
87104
88- def test_dry_run (temp_dirs , current_user , mock_replace_one ):
105+ def test_dry_run (temp_dirs , current_user , mock_replace_one , caplog ):
89106 """Test that dry_run=True is passed correctly."""
90107 inputdata_root , target_dir = temp_dirs
91108 username = current_user
@@ -117,6 +134,9 @@ def test_dry_run(temp_dirs, current_user, mock_replace_one):
117134 dry_run = True ,
118135 )
119136
137+ # Verify message with filename was printed
138+ assert f"'{ source_file } ':" in caplog .text
139+
120140
121141def test_nested_directory_structure (temp_dirs , current_user , mock_replace_one ):
122142 """Test with nested directory structures."""
@@ -175,6 +195,9 @@ def test_skip_existing_symlinks(temp_dirs, current_user, caplog, mock_replace_on
175195 # Verify replace_one_file_with_symlink() wasn't called
176196 mock_replace_one .assert_not_called ()
177197
198+ # Verify message with filename was NOT printed
199+ assert f"'{ source_link } ':" not in caplog .text
200+
178201
179202def test_missing_target_file (temp_dirs , current_user , caplog , mock_replace_one ):
180203 """Test behavior when target file doesn't exist."""
@@ -224,7 +247,7 @@ def test_invalid_username(temp_dirs, caplog, mock_replace_one):
224247 mock_replace_one .assert_not_called ()
225248
226249
227- def test_multiple_files (temp_dirs , current_user , mock_replace_one ):
250+ def test_multiple_files (temp_dirs , current_user , mock_replace_one , caplog ):
228251 """Test with multiple files in the directory."""
229252 inputdata_root , target_dir = temp_dirs
230253 username = current_user
@@ -251,6 +274,11 @@ def test_multiple_files(temp_dirs, current_user, mock_replace_one):
251274 calls .append (call (inputdata_root , target_dir , source_file , dry_run = False ))
252275 mock_replace_one .assert_has_calls (calls , any_order = True )
253276
277+ # Verify message with filename was printed
278+ for i in range (5 ):
279+ source_file = os .path .join (inputdata_root , f"file_{ i } .txt" )
280+ assert f"'{ source_file } ':" in caplog .text
281+
254282
255283def test_multiple_files_nested (temp_dirs , current_user , mock_replace_one ):
256284 """Test with multiple files scattered throughout a nested directory tree."""
0 commit comments