| 1 |
import importlib |
| 2 |
import json |
| 3 |
import os |
| 4 |
import sys |
| 5 |
from unittest.mock import MagicMock |
| 6 |
|
| 7 |
import briefcase_debugger |
| 8 |
|
| 9 |
|
| 10 |
def test_import_for_code_coverage(monkeypatch, capsys): |
| 11 |
"""Get 100% code coverage.""" |
| 12 |
# The module `briefcase_debugger` is already imported through the .pth |
| 13 |
# file. Code executed during .pth files are not covered by coverage.py. |
| 14 |
# So we need to reload the module to get a 100% code coverage. |
| 15 |
importlib.reload(importlib.import_module("briefcase_debugger")) |
| 16 |
|
| 17 |
|
| 18 |
def test_unknown_debugger(monkeypatch, capsys): |
| 19 |
"""An unknown debugger raises an error and stops the application.""" |
| 20 |
os_environ = {} |
| 21 |
os_environ["BRIEFCASE_DEBUGGER"] = json.dumps( |
| 22 |
{ |
| 23 |
"debugger": "unknown", |
| 24 |
"host": "somehost", |
| 25 |
"port": 9999, |
| 26 |
"host_os": "Windows", |
| 27 |
} |
| 28 |
) |
| 29 |
monkeypatch.setattr(os, "environ", os_environ) |
| 30 |
|
| 31 |
fake_sys_exit = MagicMock() |
| 32 |
monkeypatch.setattr(sys, "exit", fake_sys_exit) |
| 33 |
|
| 34 |
briefcase_debugger.start_remote_debugger() |
| 35 |
|
| 36 |
fake_sys_exit.assert_called_once_with(-1) |
| 37 |
|
| 38 |
captured = capsys.readouterr() |
| 39 |
assert "Unknown debugger" in captured.out |