updated tests to work with cross platform paths
This commit is contained in:
@@ -48,7 +48,8 @@ class TestADBFileTransfer:
|
||||
result = transfer.pull_file("/sdcard/test.txt", "/local/test.txt")
|
||||
|
||||
assert result is True
|
||||
mock_runner.run_adb_command.assert_called_with(['pull', '/sdcard/test.txt', '/local/test.txt'])
|
||||
expected_local_path = os.path.normpath('/local/test.txt')
|
||||
mock_runner.run_adb_command.assert_called_with(['pull', '/sdcard/test.txt', expected_local_path])
|
||||
|
||||
@patch('src.core.file_transfer.ADBCommandRunner')
|
||||
@patch('os.path.exists')
|
||||
@@ -93,7 +94,8 @@ class TestADBFileTransfer:
|
||||
result = transfer.push_file("/local/test.txt", "/sdcard/test.txt")
|
||||
|
||||
assert result is True
|
||||
mock_runner.run_adb_command.assert_called_with(['push', '/local/test.txt', '/sdcard/test.txt'])
|
||||
expected_local_path = os.path.normpath('/local/test.txt')
|
||||
mock_runner.run_adb_command.assert_called_with(['push', expected_local_path, '/sdcard/test.txt'])
|
||||
|
||||
@patch('src.core.file_transfer.ADBCommandRunner')
|
||||
@patch('os.path.exists')
|
||||
@@ -140,7 +142,8 @@ class TestADBFileTransfer:
|
||||
result = transfer.pull_folder("/sdcard/Documents", "/local/Documents")
|
||||
|
||||
assert result is True
|
||||
mock_runner.run_adb_command.assert_called_with(['pull', '/sdcard/Documents', '/local/Documents'])
|
||||
expected_local_path = os.path.normpath('/local/Documents')
|
||||
mock_runner.run_adb_command.assert_called_with(['pull', '/sdcard/Documents', expected_local_path])
|
||||
|
||||
@patch('src.core.file_transfer.ADBCommandRunner')
|
||||
@patch('os.path.exists')
|
||||
@@ -171,7 +174,8 @@ class TestADBFileTransfer:
|
||||
result = transfer.push_folder("/local/Documents", "/sdcard/Documents")
|
||||
|
||||
assert result is True
|
||||
mock_runner.run_adb_command.assert_called_with(['push', '/local/Documents', '/sdcard/Documents'])
|
||||
expected_local_path = os.path.normpath('/local/Documents')
|
||||
mock_runner.run_adb_command.assert_called_with(['push', expected_local_path, '/sdcard/Documents'])
|
||||
|
||||
@patch('src.core.file_transfer.ADBCommandRunner')
|
||||
@patch('os.path.exists')
|
||||
|
||||
@@ -62,21 +62,22 @@ class TestPlatformTools(unittest.TestCase):
|
||||
with patch('os.path.islink', return_value=False):
|
||||
with patch('os.path.isdir', return_value=False):
|
||||
with patch('tempfile.mkdtemp', return_value='/tmp/test'):
|
||||
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('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
|
||||
|
||||
def test_download_and_extract_adb_linux(self):
|
||||
"""Test ADB download and extraction on Linux."""
|
||||
|
||||
@@ -58,21 +58,24 @@ class TestPlatformUtils:
|
||||
with patch.object(sys, 'frozen', True, create=True):
|
||||
with patch('src.core.platform_utils.get_executable_directory', return_value='/app/dir'):
|
||||
result = get_platform_tools_directory()
|
||||
assert result == '/app/dir/platform-tools'
|
||||
expected = os.path.join('/app/dir', 'platform-tools')
|
||||
assert result == expected
|
||||
|
||||
def test_get_platform_tools_directory_src(self):
|
||||
"""Test platform-tools directory when running from src."""
|
||||
with patch.object(sys, 'frozen', False, create=True):
|
||||
with patch('src.core.platform_utils.get_executable_directory', return_value='/project/src'):
|
||||
result = get_platform_tools_directory()
|
||||
assert result == '/project/src/platform-tools'
|
||||
expected = os.path.join('/project/src', 'platform-tools')
|
||||
assert result == expected
|
||||
|
||||
def test_get_platform_tools_directory_gui_subdirectory(self):
|
||||
"""Test platform-tools directory when running from src/gui."""
|
||||
with patch.object(sys, 'frozen', False, create=True):
|
||||
with patch('src.core.platform_utils.get_executable_directory', return_value='/project/src/gui'):
|
||||
result = get_platform_tools_directory()
|
||||
assert result == '/project/src/platform-tools'
|
||||
expected = os.path.join('/project/src', 'platform-tools')
|
||||
assert result == expected
|
||||
|
||||
def test_get_platform_tools_directory_project_root(self):
|
||||
"""Test platform-tools directory when running from project root."""
|
||||
@@ -80,7 +83,8 @@ class TestPlatformUtils:
|
||||
with patch('src.core.platform_utils.get_executable_directory', return_value='/project'):
|
||||
with patch('os.path.exists', return_value=True):
|
||||
result = get_platform_tools_directory()
|
||||
assert result == '/project/src/platform-tools'
|
||||
expected = os.path.join('/project', 'src', 'platform-tools')
|
||||
assert result == expected
|
||||
|
||||
def test_get_platform_tools_directory_fallback(self):
|
||||
"""Test platform-tools directory fallback behavior."""
|
||||
@@ -88,4 +92,5 @@ class TestPlatformUtils:
|
||||
with patch('src.core.platform_utils.get_executable_directory', return_value='/somewhere'):
|
||||
with patch('os.path.exists', return_value=False):
|
||||
result = get_platform_tools_directory()
|
||||
assert result == '/somewhere/src/platform-tools'
|
||||
expected = os.path.join('/somewhere', 'src', 'platform-tools')
|
||||
assert result == expected
|
||||
Reference in New Issue
Block a user