From fc89ca9cfea2629dc4c1edc5cfe90ae29a857c29 Mon Sep 17 00:00:00 2001 From: Ramesh Raghupathy Date: Wed, 13 Nov 2024 08:04:00 -0800 Subject: [PATCH] Debugging --- sonic-chassisd/tests/test_chassisd.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sonic-chassisd/tests/test_chassisd.py b/sonic-chassisd/tests/test_chassisd.py index 4e71636cc..d60420ed9 100644 --- a/sonic-chassisd/tests/test_chassisd.py +++ b/sonic-chassisd/tests/test_chassisd.py @@ -472,21 +472,22 @@ def ss_mock_open(*args, **kwargs): ''' def ss_mock_open(expected_path, read_data=None): - """ - Custom mock_open function for SmartSwitchModuleUpdater tests. - Only allows specific file paths and content expectations. - """ - mock_file = mock_open(read_data=read_data) - mock_open_instance = mock_file() - - # Set up mock to match only specific paths + # Create a mock open instance with the specified read data + mock_open_instance = mock_open(read_data=read_data) + + # Define a custom side effect that only opens the specified path def custom_open(file, mode='r', *args, **kwargs): - if file == expected_path: + # Check if args has at least one item to avoid IndexError + if args and args[0] == PLATFORM_ENV_CONF_FILE: + # Handle PLATFORM_ENV_CONF_FILE case if needed + return mock_open_instance + elif file == expected_path: return mock_open_instance else: raise FileNotFoundError(f"No such file or directory: '{file}'") - return MagicMock(side_effect=custom_open) + # Patch builtins.open to use the custom side effect + return patch("builtins.open", new=custom_open) def test_smartswitch_module_db_update():