1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
# The run command inherits most of its behavior from the common base
# implementation. Do a surface-level verification here, but the app
# tests provide the actual test coverage.
import subprocess
from unittest import mock
import pytest
from briefcase.integrations.subprocess import Subprocess
from briefcase.platforms.windows.visualstudio import WindowsVisualStudioRunCommand
@pytest.fixture
def run_command(dummy_console, tmp_path):
command = WindowsVisualStudioRunCommand(
console=dummy_console,
base_path=tmp_path / "base_path",
data_path=tmp_path / "briefcase",
)
command.tools.home_path = tmp_path / "home"
command.tools.subprocess = mock.MagicMock(spec_set=Subprocess)
command._stream_app_logs = mock.MagicMock()
return command
def test_run_app(run_command, first_app_config, tmp_path):
"""A windows Visual Studio project app can be started."""
# Set up the log streamer to return a known stream with a good returncode
log_popen = mock.MagicMock()
run_command.tools.subprocess.Popen.return_value = log_popen
# Run the app
run_command.run_app(first_app_config, passthrough=[])
# Popen was called
run_command.tools.subprocess.Popen.assert_called_with(
[
tmp_path
/ "base_path/build/first-app/windows/visualstudio/x64/Release/First App.exe"
],
cwd=tmp_path / "home",
encoding="UTF-8",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
bufsize=1,
)
# The streamer was started
run_command._stream_app_logs.assert_called_once_with(
first_app_config,
popen=log_popen,
clean_output=False,
)
def test_run_app_with_args(run_command, first_app_config, tmp_path):
"""A windows Visual Studio project app can be started with args."""
# Set up the log streamer to return a known stream with a good returncode
log_popen = mock.MagicMock()
run_command.tools.subprocess.Popen.return_value = log_popen
# Run the app with args
run_command.run_app(
first_app_config,
passthrough=["foo", "--bar"],
)
# Popen was called
run_command.tools.subprocess.Popen.assert_called_with(
[
tmp_path
/ "base_path/build/first-app/windows/visualstudio/x64/Release/First App.exe",
"foo",
"--bar",
],
cwd=tmp_path / "home",
encoding="UTF-8",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
bufsize=1,
)
# The streamer was started
run_command._stream_app_logs.assert_called_once_with(
first_app_config,
popen=log_popen,
clean_output=False,
)
def test_run_app_test_mode(run_command, first_app_config, tmp_path):
"""A windows Visual Studio project app can be started in test mode."""
first_app_config.test_mode = True
# Set up the log streamer to return a known stream with a good returncode
log_popen = mock.MagicMock()
run_command.tools.subprocess.Popen.return_value = log_popen
# Run the app in test mode
run_command.run_app(first_app_config, passthrough=[])
# Popen was called
run_command.tools.subprocess.Popen.assert_called_with(
[
tmp_path
/ "base_path/build/first-app/windows/visualstudio/x64/Release/First App.exe"
],
cwd=tmp_path / "home",
encoding="UTF-8",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
bufsize=1,
env={"BRIEFCASE_MAIN_MODULE": "tests.first_app"},
)
# The streamer was started
run_command._stream_app_logs.assert_called_once_with(
first_app_config,
popen=log_popen,
clean_output=False,
)
def test_run_app_test_mode_with_args(run_command, first_app_config, tmp_path):
"""A windows Visual Studio project app can be started in test mode with args."""
first_app_config.test_mode = True
# Set up the log streamer to return a known stream with a good returncode
log_popen = mock.MagicMock()
run_command.tools.subprocess.Popen.return_value = log_popen
# Run the app with args
run_command.run_app(
first_app_config,
passthrough=["foo", "--bar"],
)
# Popen was called
run_command.tools.subprocess.Popen.assert_called_with(
[
tmp_path
/ "base_path/build/first-app/windows/visualstudio/x64/Release/First App.exe",
"foo",
"--bar",
],
cwd=tmp_path / "home",
encoding="UTF-8",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
bufsize=1,
env={"BRIEFCASE_MAIN_MODULE": "tests.first_app"},
)
# The streamer was started
run_command._stream_app_logs.assert_called_once_with(
first_app_config,
popen=log_popen,
clean_output=False,
)
|