From f29e39a36735f0509a3ebc66e7a1a9a4a06185ed Mon Sep 17 00:00:00 2001 From: Jason Ross Date: Mon, 22 Sep 2025 18:16:45 -0500 Subject: [PATCH] fix path mocking --- tests/core/test_platform_tools.py | 34 +++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/core/test_platform_tools.py b/tests/core/test_platform_tools.py index d8163f1..537092e 100644 --- a/tests/core/test_platform_tools.py +++ b/tests/core/test_platform_tools.py @@ -58,26 +58,34 @@ class TestPlatformTools(unittest.TestCase): def test_ensure_platform_tools_simple(self): """Test basic platform tools installation.""" # Just test the function doesn't crash with basic mocking + def mock_isdir(path): + # Return True for the extracted platform-tools directory and target directory checks + if path == '/tmp/test/platform-tools': + return True + if path.endswith('platform-tools') and 'tmp' in path: + return True + # Return False for other directory checks (like existing target_dir) + return False + with patch('os.makedirs'): with patch('os.path.islink', return_value=False): - with patch('os.path.isdir', return_value=False): + with patch('os.path.isdir', side_effect=mock_isdir): with patch('tempfile.mkdtemp', return_value='/tmp/test'): with patch('os.listdir', return_value=['platform-tools']): # Mock directory listing with patch('requests.get') as mock_get: with patch('builtins.open', mock_open()): with patch('zipfile.ZipFile') as mock_zip: - with patch('os.path.isdir', side_effect=lambda p: p == '/tmp/test/platform-tools'): - with patch('shutil.move'): - with patch('os.chmod'): - with patch('os.symlink'): - with patch('shutil.rmtree'): - mock_response = Mock() - mock_response.iter_content.return_value = [b'content'] - mock_response.raise_for_status.return_value = None - mock_get.return_value = mock_response - - result = ensure_platform_tools_in_user_dir() - assert result is not None + with patch('shutil.move'): + with patch('os.chmod'): + with patch('os.symlink'): + with patch('shutil.rmtree'): + mock_response = Mock() + mock_response.iter_content.return_value = [b'content'] + mock_response.raise_for_status.return_value = None + mock_get.return_value = mock_response + + result = ensure_platform_tools_in_user_dir() + assert result is not None def test_download_and_extract_adb_linux(self): """Test ADB download and extraction on Linux."""