Debian Codegraph @

tests/platforms/windows/app/test_dev.py

raw
1 import subprocess
2 import sys
3 from unittest import mock
4
5 import pytest
6
7 from briefcase.integrations.subprocess import Subprocess
8 from briefcase.integrations.virtual_environment import VenvContext
9 from briefcase.platforms.windows.app import WindowsAppDevCommand
10
11
12 @pytest.fixture
13 def dev_command(dummy_console, tmp_path):
14 """Fixture for a WindowsAppDevCommand instance."""
15 command = WindowsAppDevCommand(
16 console=dummy_console,
17 base_path=tmp_path / "base_path",
18 data_path=tmp_path / "briefcase",
19 )
20 command.tools.home_path = tmp_path / "home"
21 command.tools.subprocess = mock.MagicMock(spec_set=Subprocess)
22 command._stream_app_logs = mock.MagicMock()
23 return command
24
25
26 @pytest.fixture
27 def default_env() -> VenvContext:
28 """Create a venv mock for tests that require a venv parameter."""
29 mock_venv = mock.MagicMock(spec=VenvContext)
30 mock_venv.run.return_value = mock.MagicMock()
31 mock_venv.check_output.return_value = ""
32 mock_venv.Popen.return_value = mock.MagicMock()
33 mock_venv.executable = "/mock/venv/Scripts/python.exe"
34 return mock_venv
35
36
37 def test_dev_app_starts(dev_command, first_app_config, tmp_path, default_env):
38 """A Windows app can be started in development mode using Python."""
39 log_popen = mock.MagicMock()
40 default_env.Popen.return_value = log_popen
41
42 # Run the app
43 dev_command.run_dev_app(first_app_config, env={}, venv=default_env, passthrough=[])
44
45 # Extract the actual Popen call arguments
46 popen_args, popen_kwargs = default_env.Popen.call_args
47
48 # Check that the command uses the Python executable
49 assert popen_args[0][0] == sys.executable
50
51 # The inline Python command should reference the app's main module
52 assert "runpy.run_module" in popen_args[0][2]
53 assert first_app_config.module_name in popen_args[0][2]
54
55 # Verify other subprocess parameters
56 assert popen_kwargs["cwd"] == tmp_path / "home"
57 assert popen_kwargs["encoding"] == "UTF-8"
58 assert popen_kwargs["stdout"] == subprocess.PIPE
59 assert popen_kwargs["stderr"] == subprocess.STDOUT
60 assert popen_kwargs["bufsize"] == 1
61
62 # The log streamer should be called
63 dev_command._stream_app_logs.assert_called_once_with(
64 first_app_config,
65 popen=log_popen,
66 clean_output=False,
67 )