Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added normalised expected path to tackle windows specific error. #158

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading