Skip to content

Commit

Permalink
Added normalised expected path to tackle windows specific error.
Browse files Browse the repository at this point in the history
  • Loading branch information
techy4shri committed Oct 28, 2024
1 parent 0720c0f commit 6410049
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tests/test_flagController.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pytest
from unittest.mock import patch, MagicMock
from twinTrim.flagController import handleAllFlag
Expand Down Expand Up @@ -29,7 +30,7 @@ def test_handle_all_flag_filtered_files(mock_progress_bar, mock_add_or_update_fi
"""Test handleAllFlag with files that pass the filter."""
# Simulate a directory with 3 files
mock_os_walk.return_value = [
('/path/to/files', [], ['file1.txt', 'file2.txt', 'file3.txt'])
(os.path.normpath('/path/to/files'), [], ['file1.txt', 'file2.txt', 'file3.txt'])
]

# Mock file_filter to filter out some files
Expand All @@ -40,10 +41,13 @@ def test_handle_all_flag_filtered_files(mock_progress_bar, mock_add_or_update_fi
mock_progress_bar.return_value.__enter__.return_value = MagicMock()

# Call the function
handleAllFlag('/path/to/files', mock_file_filter, 'yellow', 'white')

handleAllFlag(os.path.normpath('/path/to/files'), mock_file_filter, 'yellow', 'white')

# Normalizing the expected file path to handle platform-specific slashes (Windows != \\)
expected_path = os.path.normpath('/path/to/files/file2.txt')

# Assertions
mock_add_or_update_file.assert_called_once_with('/path/to/files/file2.txt') # Only file2.txt should be processed
mock_add_or_update_file.assert_called_once_with(expected_path) # Only file2.txt should be processed
mock_progress_bar.assert_called_once() # Progress bar should still be created


Expand All @@ -54,7 +58,7 @@ def test_handle_all_flag_success(mock_progress_bar, mock_add_or_update_file, moc
"""Test handleAllFlag successful execution."""
# Simulate a directory with 3 files
mock_os_walk.return_value = [
('/path/to/files', [], ['file1.txt', 'file2.txt', 'file3.txt'])
(os.path.normpath('/path/to/files'), [], ['file1.txt', 'file2.txt', 'file3.txt'])
]

# Mock file_filter to allow all files
Expand All @@ -65,7 +69,7 @@ def test_handle_all_flag_success(mock_progress_bar, mock_add_or_update_file, moc
mock_progress_bar.return_value.__enter__.return_value = MagicMock()

# Call the function
handleAllFlag('/path/to/files', mock_file_filter, 'yellow', 'white')
handleAllFlag(os.path.normpath('/path/to/files'), mock_file_filter, 'yellow', 'white')

# Assertions
assert mock_add_or_update_file.call_count == 3 # All 3 files should be processed
Expand Down

0 comments on commit 6410049

Please sign in to comment.