Repository navigation
Unify tests and test scripts #289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
255bc3d
d593bd4
2cb8aca
ea84afc
ea9a5b3
f9617a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: Tests | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| concurrency: | ||
| # one run per PR (or per branch for pushes): a new push cancels the run in progress | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Python 3.12 | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: 3.12 | ||
| - name: Install Qt system libraries | ||
| run: sudo apt-get update && sudo apt-get install -y libegl1 libgl1 libxkbcommon0 | ||
| - name: Install package, test dependencies and the plugin example | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -e .[test] ./plugin_example | ||
| - name: Cache test datasets | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: spikeinterface_gui/tests/datasets | ||
| key: test-datasets-${{ hashFiles('spikeinterface_gui/tests/testingtools.py') }} | ||
| - name: Test with pytest | ||
| env: | ||
| QT_QPA_PLATFORM: offscreen | ||
| run: pytest spikeinterface_gui/tests -v |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| spikeinterface_gui/tests/*/* | ||
| my_dataset/* | ||
| spikeinterface_gui/tests/datasets/ | ||
| comparison_scripts/ | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import os | ||
|
|
||
| # headless Qt, for the tests and the CI; set before anything imports Qt | ||
| os.environ.setdefault("QT_QPA_PLATFORM", "offscreen") | ||
|
|
||
| import pytest | ||
|
|
||
| import spikeinterface.full as si | ||
|
|
||
| from spikeinterface_gui.tests.testingtools import ( | ||
| get_dataset_folder, make_curation_dict, prepare_analyzer_for_gui, set_comparison_labels, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Code anarchists are very welcome. So in this mess, persona non grata: pre-commit, black, pytest fixture, ..."
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. he lost a battle, but not the war |
||
| def analyzer_folder(): | ||
| return get_dataset_folder("small") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def comparison_folder(): | ||
| return get_dataset_folder("small", comparison=True) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def qapp(): | ||
| pytest.importorskip("PySide6") | ||
| pytest.importorskip("pyqtgraph") | ||
| from spikeinterface_gui.myqt import mkQApp | ||
| return mkQApp() | ||
|
|
||
|
|
||
| def _skip_if_backend_missing(backend): | ||
| if backend == "qt": | ||
| pytest.importorskip("PySide6") | ||
| pytest.importorskip("pyqtgraph") | ||
| else: | ||
| pytest.importorskip("panel") | ||
|
|
||
|
|
||
| def load_controller(analyzer_folder, backend): | ||
| """A Controller with curation and events, so every view of the main GUI is possible.""" | ||
| from spikeinterface_gui.controller import Controller | ||
|
|
||
| _skip_if_backend_missing(backend) | ||
| analyzer = si.load_sorting_analyzer(analyzer_folder / "sorting_analyzer") | ||
| extra_unit_properties, events = prepare_analyzer_for_gui(analyzer, events="times", seed=0) | ||
| return Controller(analyzer, backend=backend, curation=True, curation_data=make_curation_dict(analyzer), | ||
| extra_unit_properties=extra_unit_properties, events=events) | ||
|
|
||
|
|
||
| def load_comparison_controller(comparison_folder, backend): | ||
| from spikeinterface_gui.controllercomparison import ControllerComparison | ||
|
|
||
| _skip_if_backend_missing(backend) | ||
| analyzer1 = si.load_sorting_analyzer(comparison_folder / "sorting_analyzer_1") | ||
| analyzer2 = si.load_sorting_analyzer(comparison_folder / "sorting_analyzer_2") | ||
| set_comparison_labels(analyzer1, analyzer2) | ||
| return ControllerComparison(analyzer1, analyzer2, analyzer1_name="sorter1", analyzer2_name="sorter2", | ||
| backend=backend) | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| """ | ||
| Launch the GUI on a test dataset from tests/datasets, built on first use. | ||
|
|
||
| python run_gui.py # desktop, small dataset, with curation | ||
| python run_gui.py --mode web --events samples | ||
| python run_gui.py --comparison --mode web | ||
| python run_gui.py --launcher | ||
| panel serve run_gui.py --autoreload # web, default options | ||
| """ | ||
| from argparse import ArgumentParser | ||
|
|
||
| from spikeinterface import load_sorting_analyzer | ||
|
|
||
| from spikeinterface_gui import run_mainwindow, run_mainwindow_comparison, run_launcher | ||
| from spikeinterface_gui.tests.testingtools import ( | ||
| DATASETS_FOLDER, get_dataset_folder, make_curation_dict, prepare_analyzer_for_gui, set_comparison_labels, | ||
| ) | ||
|
|
||
| parser = ArgumentParser(description=__doc__.split("\n\n")[0]) | ||
| parser.add_argument('--mode', default="desktop", choices=["desktop", "web"]) | ||
| parser.add_argument('--comparison', action="store_true", help='Compare two analyzers') | ||
| parser.add_argument('--dataset', default="small", | ||
| help='small | medium-split | multiprobe | big, or small | medium with --comparison') | ||
| parser.add_argument('--regenerate', action="store_true", help='Rebuild the dataset') | ||
| parser.add_argument('--events', choices=["times", "samples"], help='Simulate events, given as times or samples') | ||
| parser.add_argument('--no-curation', action="store_true", help='Disable curation') | ||
| parser.add_argument('--iterative', action="store_true", help='Run iterative curation') | ||
| parser.add_argument('--layout', default="default", help='Layout preset') | ||
| parser.add_argument('--lazy', action="store_true", help='Lazy load') | ||
| parser.add_argument('--port', default=0, type=int, help='Port for the web server') | ||
| parser.add_argument('--no-start', action="store_true", help='Do not start the app') | ||
| parser.add_argument('--launcher', action="store_true", help='Open the launcher on all datasets in tests/datasets') | ||
|
|
||
|
|
||
| def main(args, start_app=True): | ||
| if args.launcher: | ||
| return run_launcher(mode=args.mode, root_folder=DATASETS_FOLDER, port=args.port, verbose=True) | ||
|
|
||
| folder = get_dataset_folder(args.dataset, comparison=args.comparison, regenerate=args.regenerate) | ||
|
|
||
| if args.comparison: | ||
| analyzer1 = load_sorting_analyzer(folder / "sorting_analyzer_1", lazy=args.lazy) | ||
| analyzer2 = load_sorting_analyzer(folder / "sorting_analyzer_2", lazy=args.lazy) | ||
| set_comparison_labels(analyzer1, analyzer2) | ||
| return run_mainwindow_comparison( | ||
| analyzer1, analyzer2, analyzer1_name="sorter1", analyzer2_name="sorter2", | ||
| mode=args.mode, start_app=start_app, verbose=True, port=args.port, | ||
| ) | ||
|
|
||
| analyzer = load_sorting_analyzer(folder / "sorting_analyzer", load_extensions=False, lazy=args.lazy) | ||
| extra_unit_properties, events = prepare_analyzer_for_gui(analyzer, events=args.events) | ||
| curation = not args.no_curation | ||
| return run_mainwindow( | ||
| analyzer, | ||
| mode=args.mode, | ||
| start_app=start_app, | ||
| verbose=True, | ||
| curation=curation, | ||
| curation_dict=make_curation_dict(analyzer) if curation else None, | ||
| iterative_curation=args.iterative, | ||
| extra_unit_properties=extra_unit_properties, | ||
| layout_preset=args.layout, | ||
| events=events, | ||
| port=args.port, | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| args = parser.parse_args() | ||
| win = main(args, start_app=not args.no_start) | ||
| elif __name__.startswith("bokeh"): | ||
| # panel serve: the window registers itself as servable | ||
| win = main(parser.parse_args(["--mode", "web"]), start_app=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magnifico