Skip to content

Commit

Permalink
Testing: Check that an error is raised for invalid shortcut options
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Nov 30, 2024
1 parent dbb5fb8 commit 7b1a3fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ def pytest_collection_modifyitems(config, items):


@pytest.fixture(autouse=True)
def reset_conf_before_test():
def reset_conf_before_test(request):
# To prevent running this fixture for a specific test, you need to use this
# marker.
if 'no_reset_conf' in request.keywords:
return

from spyder.config.manager import CONF
CONF.reset_to_defaults(notification=False)

Expand Down
24 changes: 24 additions & 0 deletions spyder/config/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,30 @@ def test_userconfig_cleanup(userconfig):
assert not os.path.isfile(configpath)


@pytest.mark.no_reset_conf
def test_invalid_shortcuts(tmp_path):
name = 'invalid-shortcuts'
path = str(tmp_path)

for defaults in [
# Shortcut is not of the form context/name
[('shortcuts', {'foo': "Ctrl+I"})],
# Shortcut contains more than one slash, which breaks the way we parse
# them
[('shortcuts', {'editor/foo/bar': "Ctrl+I"})],
]:
with pytest.raises(ValueError):
UserConfig(
name=name,
path=path,
defaults=defaults,
load=False,
version="1.0.0",
backup=False,
raw_mode=True,
)


# --- SpyderUserConfig tests
# ============================================================================
# --- Compatibility API
Expand Down

0 comments on commit 7b1a3fe

Please sign in to comment.