From 6410049ee0722365e2b28747fe5c58c90616476f Mon Sep 17 00:00:00 2001 From: techy4shri Date: Mon, 28 Oct 2024 16:44:42 +0530 Subject: [PATCH] Added normalised expected path to tackle windows specific error. --- tests/test_flagController.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/test_flagController.py b/tests/test_flagController.py index 11a844e..2c18ebf 100644 --- a/tests/test_flagController.py +++ b/tests/test_flagController.py @@ -1,3 +1,4 @@ +import os import pytest from unittest.mock import patch, MagicMock from twinTrim.flagController import handleAllFlag @@ -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 @@ -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 @@ -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 @@ -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