From 73ff0145537a3a0c25768402d12436e72f8db9fc Mon Sep 17 00:00:00 2001 From: Jason Ross Date: Mon, 22 Sep 2025 17:52:04 -0500 Subject: [PATCH 1/4] added pytest.ini to repo --- .gitignore | 2 +- pytest.ini | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 pytest.ini diff --git a/.gitignore b/.gitignore index cc8b0e4..69beff5 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ test-act.yml pkg_dist_debian pkg* .pytest* - +!pytest.ini # Python cache files __pycache__/ *.py[cod] diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..831f611 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,7 @@ +[pytest] +minversion = 7.0 +testpaths = tests +python_files = test_*.py *_test.py +python_classes = Test* +python_functions = test_* +addopts = -v --tb=short -p no:qt \ No newline at end of file -- 2.47.3 From f28e55f70a8b054dff4ef48d145da065e9204b97 Mon Sep 17 00:00:00 2001 From: Jason Ross Date: Mon, 22 Sep 2025 17:57:03 -0500 Subject: [PATCH 2/4] updated Windows path problem --- .github/workflows/release.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 02c9378..11336b9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -55,7 +55,7 @@ jobs: - name: Run tests run: | - poetry run pytest -v + poetry run pytest tests/ -v run-unit-tests-windows: runs-on: windows-latest @@ -69,6 +69,17 @@ jobs: - name: Install Poetry uses: snok/install-poetry@v1 + with: + version: latest + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Ensure Poetry is on PATH (Windows) + shell: pwsh + run: | + # Add Poetry user bin to PATH for subsequent steps in this job + $poetryPath = Join-Path $env:USERPROFILE ".local\bin" + Write-Output $poetryPath >> $Env:GITHUB_PATH - name: Install dependencies run: | @@ -76,7 +87,7 @@ jobs: - name: Run tests run: | - poetry run pytest -v + poetry run pytest tests/ -v build-windows: needs: [run-unit-tests-linux, run-unit-tests-windows] if: contains(github.event.inputs.jobs, 'build-windows') -- 2.47.3 From 318d51a517189fb60f730e129820fe96d52514e7 Mon Sep 17 00:00:00 2001 From: Jason Ross Date: Mon, 22 Sep 2025 18:07:54 -0500 Subject: [PATCH 3/4] updated tests to work with cross platform paths --- tests/core/test_file_transfer.py | 12 ++++++++---- tests/core/test_platform_tools.py | 31 ++++++++++++++++--------------- tests/core/test_platform_utils.py | 15 ++++++++++----- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/tests/core/test_file_transfer.py b/tests/core/test_file_transfer.py index 3fb8dc3..8e6c557 100644 --- a/tests/core/test_file_transfer.py +++ b/tests/core/test_file_transfer.py @@ -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') diff --git a/tests/core/test_platform_tools.py b/tests/core/test_platform_tools.py index 1d7d1da..d8163f1 100644 --- a/tests/core/test_platform_tools.py +++ b/tests/core/test_platform_tools.py @@ -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.""" diff --git a/tests/core/test_platform_utils.py b/tests/core/test_platform_utils.py index e724b0a..e7b58e6 100644 --- a/tests/core/test_platform_utils.py +++ b/tests/core/test_platform_utils.py @@ -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' \ No newline at end of file + expected = os.path.join('/somewhere', 'src', 'platform-tools') + assert result == expected \ No newline at end of file -- 2.47.3 From fb61a11787f7e86bbcba5e21cfc350763cf55af5 Mon Sep 17 00:00:00 2001 From: Jason Ross Date: Mon, 22 Sep 2025 18:16:45 -0500 Subject: [PATCH 4/4] 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.""" -- 2.47.3