Debian Codegraph @

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