Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/debugpy/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def configure(properties=None, **kwargs):
properties = dict(properties)
properties.update(kwargs)

# Validate everything before changing anything, so that a call which raises
# leaves the existing configuration untouched.
for k, v in properties.items():
if k not in _config:
raise ValueError("Unknown property {0!r}".format(k))
Expand All @@ -90,7 +92,8 @@ def configure(properties=None, **kwargs):
valid_values = _config_valid_values.get(k)
if (valid_values is not None) and (v not in valid_values):
raise ValueError("{0!r} must be one of: {1!r}".format(k, valid_values))
_config[k] = v

_config.update(properties)


def _starts_debugging(func):
Expand Down
22 changes: 22 additions & 0 deletions tests/debugpy/server/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,25 @@ def test_listen_empty_adapter_read_raises(monkeypatch):
str(exc_info.value)
== "error retrieving adapter endpoints: EOF while reading adapter endpoints"
)


@pytest.mark.parametrize(
"properties",
[
{"qt": "auto", "subProcess": "yes"},
{"qt": "pyside", "unknown": 1},
{"subProcess": False, "qt": "not-a-qt-mode"},
],
ids=["bad-type", "unknown-property", "bad-value"],
)
def test_configure_failure_leaves_config_unchanged(monkeypatch, properties):
# configure() raises ValueError for a property it cannot accept. When it does,
# none of the other properties passed in the same call may have been applied,
# or the caller is left with a configuration it never asked for.
monkeypatch.setattr(api, "ensure_logging", lambda: None)
monkeypatch.setattr(api, "_config", {"qt": "none", "subProcess": True})

with pytest.raises(ValueError):
api.configure(properties)

assert api._config == {"qt": "none", "subProcess": True}