path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py def test_pidof_fail_exit_0(adb): """If adb.pidof() returns a PID of 0, it is interpreted as the process not existing.""" path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py adb.run = Mock(return_value="5678\n") assert adb.pidof("com.example") == "5678" adb.run.assert_called_once_with("shell", "pidof", "-s", "com.example") path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py def test_pidof_fail_exit_1(adb): """If adb.pidof() fails, it is interpreted as the process not existing.""" adb.run = Mock(side_effect=subprocess.CalledProcessError(1, "adb shell")) path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py def test_pidof_fail_exit_0(adb): """If adb.pidof() returns a PID of 0, it is interpreted as the process not existing.""" adb.run = Mock(return_value="") path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py adb.run = Mock(return_value="") assert adb.pidof("com.example") is None adb.run.assert_called_once_with("shell", "pidof", "-s", "com.example") path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py def test_pidof_fail_exit_1(adb): """If adb.pidof() fails, it is interpreted as the process not existing.""" adb.run = Mock(side_effect=subprocess.CalledProcessError(1, "adb shell")) path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py adb.run = Mock(return_value="5678\n") assert adb.pidof("com.example", quiet=True) == "5678" adb.run.assert_called_once_with("shell", "pidof", "-s", "com.example", quiet=True) path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py assert adb.pidof("com.example") == "5678" adb.run.assert_called_once_with("shell", "pidof", "-s", "com.example") path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py def test_pidof_quiet(adb): """adb.pidof() can be called in quiet mode on a process that exists.""" adb.run = Mock(return_value="5678\n") path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py def test_pidof_quiet(adb): """adb.pidof() can be called in quiet mode on a process that exists.""" adb.run = Mock(return_value="5678\n") path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py def test_pidof_succeed(adb): """adb.pidof() can be called on a process that exists.""" adb.run = Mock(return_value="5678\n") path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py adb.run = Mock(side_effect=subprocess.CalledProcessError(1, "adb shell")) assert adb.pidof("com.example") is None adb.run.assert_called_once_with("shell", "pidof", "-s", "com.example") path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py assert adb.pidof("com.example") is None adb.run.assert_called_once_with("shell", "pidof", "-s", "com.example") path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py assert adb.pidof("com.example") is None adb.run.assert_called_once_with("shell", "pidof", "-s", "com.example") path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py assert adb.pidof("com.example", quiet=True) == "5678" adb.run.assert_called_once_with("shell", "pidof", "-s", "com.example", quiet=True) path: python-briefcase_0.3.25-2/tests/integrations/android_sdk/ADB/test_pidof.py def test_pidof_succeed(adb): """adb.pidof() can be called on a process that exists.""" adb.run = Mock(return_value="5678\n") path: python-briefcase_0.3.25-2/src/briefcase/integrations/android_sdk.py running. """ # The pidof command is available since API level 24. The level 23 emulator image also # includes it, but it doesn't work correctly (it returns all processes). try: path: python-briefcase_0.3.25-2/src/briefcase/integrations/android_sdk.py raise BriefcaseCommandError("Error starting 'adb reverse --remove'.") from e def pidof(self, package: str, **kwargs) -> str | None: """Obtain the PID of a running app by package name. path: python-briefcase_0.3.25-2/src/briefcase/integrations/android_sdk.py # Exit status is unreliable: some devices (e.g. Nexus 4) return 0 even when no # process was found. return self.run("shell", "pidof", "-s", package, **kwargs).strip() or None except subprocess.CalledProcessError: return None path: python-briefcase_0.3.25-2/tests/platforms/android/gradle/test_run.py ) run_command.tools.mock_adb.pidof.assert_called_once_with( f"{first_app_config.package_name}.{first_app_config.module_name}", quiet=2, path: python-briefcase_0.3.25-2/tests/platforms/android/gradle/test_run.py ) run_command.tools.mock_adb.pidof.assert_called_once_with( f"{first_app_config.package_name}.{first_app_config.module_name}", quiet=2, path: python-briefcase_0.3.25-2/tests/platforms/android/gradle/test_run.py ) # Mock the pidof call failing multiple times before a timeout. run_command.tools.mock_adb.pidof.side_effect = [None] * 5 monkeypatch.setattr(time, "sleep", mock.MagicMock()) path: python-briefcase_0.3.25-2/tests/platforms/android/gradle/test_run.py # Mock the pidof call failing multiple times before a timeout. run_command.tools.mock_adb.pidof.side_effect = [None] * 5 monkeypatch.setattr(time, "sleep", mock.MagicMock()) path: python-briefcase_0.3.25-2/tests/platforms/android/gradle/test_run.py def test_run_slow_start(run_command, first_app_config, monkeypatch): """If the app is slow to start, multiple calls to pidof will be made.""" run_command.tools.android_sdk.select_target_device = mock.MagicMock( return_value=("exampleDevice", "ExampleDevice", None) path: python-briefcase_0.3.25-2/tests/platforms/android/gradle/test_run.py assert ( run_command.tools.mock_adb.pidof.mock_calls == [mock.call("com.example.first_app", quiet=2)] * 5 ) path: python-briefcase_0.3.25-2/tests/platforms/android/gradle/test_run.py ) run_command.tools.mock_adb.pidof.assert_called_once_with( f"{first_app_config.package_name}.{first_app_config.module_name}", quiet=2, path: python-briefcase_0.3.25-2/tests/platforms/android/gradle/test_run.py run_command.tools.mock_adb.logcat.return_value = log_popen # Mock the pidof call taking 3 attempts to return run_command.tools.mock_adb.pidof.side_effect = [None, None, "888"] monkeypatch.setattr(time, "sleep", mock.MagicMock()) path: python-briefcase_0.3.25-2/tests/platforms/android/gradle/test_run.py assert ( run_command.tools.mock_adb.pidof.mock_calls == [mock.call("com.example.first_app", quiet=2)] * 3 ) path: python-briefcase_0.3.25-2/tests/platforms/android/gradle/test_run.py # Mock the pidof call taking 3 attempts to return run_command.tools.mock_adb.pidof.side_effect = [None, None, "888"] monkeypatch.setattr(time, "sleep", mock.MagicMock()) path: python-briefcase_0.3.25-2/tests/platforms/android/gradle/test_run.py ) command.tools.mock_adb = mock.MagicMock(spec_set=ADB) command.tools.mock_adb.pidof = mock.MagicMock(return_value="777") command.tools.java = mock.MagicMock(spec=JDK) command.tools.java.java_home = "/path/to/java" path: python-briefcase_0.3.25-2/tests/platforms/android/gradle/test_run.py run_command.tools.mock_adb.reverse_remove.assert_not_called() run_command.tools.mock_adb.pidof.assert_called_once_with( f"{first_app_config.package_name}.{first_app_config.module_name}", quiet=2, path: python-briefcase_0.3.25-2/src/briefcase/platforms/android/gradle.py # Try to get the PID; run in quiet mode because we may # need to do this a lot in the next 5 seconds. pid = adb.pidof(package, quiet=2) if not pid: time.sleep(0.01)