From 21c1e5e1057e01fd9cc514c2b77bd0f423923edb Mon Sep 17 00:00:00 2001 From: Iain Date: Sun, 6 Sep 2026 02:48:46 +0100 Subject: [PATCH] Fix the -e flag of moabb.run splitting its value into characters --- docs/source/whats_new.rst | 2 +- moabb/run.py | 7 ++++--- moabb/tests/test_run.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 moabb/tests/test_run.py diff --git a/docs/source/whats_new.rst b/docs/source/whats_new.rst index fddffd360f..7bc4aa4b61 100644 --- a/docs/source/whats_new.rst +++ b/docs/source/whats_new.rst @@ -35,7 +35,7 @@ Requirements Bugs ~~~~ -- None yet. +- Fix the ``-e``/``--evaluations`` flag of ``python -m moabb.run``, which used ``type=list`` and so split its value into single characters: ``-e WithinSession`` reached :func:`moabb.benchmark` as ``['W', 'i', 't', ...]`` and raised ``KeyError: 'W'``. It now takes one or more evaluation names, space separated (by `Iain`_) Code health ~~~~~~~~~~~ diff --git a/moabb/run.py b/moabb/run.py index 0d5c8a31ab..1bdd6f422f 100644 --- a/moabb/run.py +++ b/moabb/run.py @@ -34,10 +34,11 @@ def parser_init(): "-e", "--evaluations", dest="evaluations", - type=list, + type=str, + nargs="+", default=None, - help="Evaluation types to be run. Must be given as a list. " - 'Options - ["WithinSession","CrossSession","CrossSubject"]' + help="Evaluation types to be run, space separated. " + 'Options - "WithinSession", "CrossSession", "CrossSubject". ' "By default, all 3 types of evaluations will be done", ) parser.add_argument( diff --git a/moabb/tests/test_run.py b/moabb/tests/test_run.py new file mode 100644 index 0000000000..7078dc9f14 --- /dev/null +++ b/moabb/tests/test_run.py @@ -0,0 +1,15 @@ +import pytest + +from moabb.run import parser_init + + +@pytest.mark.parametrize( + "argv,expected", + [ + (["-e", "WithinSession"], ["WithinSession"]), + (["-e", "WithinSession", "CrossSession"], ["WithinSession", "CrossSession"]), + ([], None), + ], +) +def test_parser_evaluations(argv, expected): + assert parser_init().parse_args(argv).evaluations == expected