From 6da0a848ab10d29c8b2012e1dcca7fead2afef6e Mon Sep 17 00:00:00 2001 From: Florian Rau Date: Mon, 11 Sep 2023 16:20:15 +0200 Subject: [PATCH] fix cryptic error msgs for bpod + frame2ttl (#479) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix cryptic error msgs for bpod + frame2ttl fixes #478 * flake8 * add helpful msg for rotary encoder at null port * fix directory for CI unit-tests * use pip cache for CI * commit of shame * and another one * commit of shame, vol 2 * it's never ending * perhaps? * - * -- * --- * this one's gonna work for sure * Update test_scripts.py * create setting files * added project_extraction * Update main.yaml * Update test_scripts.py * Update main.yaml * Update main.yaml * Update main.yaml * Update main.yaml * ### * Update main.yaml * ¯\_(ツ)_/¯ * Update main.yaml * giving up for today * actually ...? * Update main.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update installation.rst --------- Co-authored-by: olivier --- .github/workflows/main.yaml | 28 ++++++++++++++++++---------- docs/source/installation.rst | 2 +- iblrig/base_tasks.py | 13 +++++++++++++ iblrig/test/test_base_tasks.py | 16 +++++++++++++++- iblrig/test/test_scripts.py | 10 ++-------- requirements.txt | 2 +- 6 files changed, 50 insertions(+), 21 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index c2c711799..f4f5358f6 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -17,25 +17,25 @@ jobs: steps: - name: Checkout iblrig repo uses: actions/checkout@v3 - with: - path: iblrig - name: Setup Python uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + cache: 'pip' + cache-dependency-path: '**/requirements*.txt' - name: flake8 run: | + pip install --upgrade pip pip install flake8 --quiet - cd iblrig python -m flake8 - name: iblrig and iblpybpod requirements shell: bash -l {0} run: | pip install --editable iblrig - pip install -r iblrig/requirements.txt + pip install -r requirements.txt - name: Install audio library (Ubuntu only) if: matrix.os == 'ubuntu-latest' @@ -45,17 +45,25 @@ jobs: if: matrix.os == 'windows-latest' shell: pwsh -l {0} run: | - cd iblrig\Bonsai + cd Bonsai powershell.exe .\install.ps1 + - name: Create config files (Ubuntu) + if: matrix.os == 'ubuntu-latest' + run: | + cp settings/hardware_settings_template.yaml settings/hardware_settings.yaml + cp settings/iblrig_settings_template.yaml settings/iblrig_settings.yaml + + - name: Create config files (Windows) + if: matrix.os == 'windows-latest' + run: | + copy settings\hardware_settings_template.yaml settings\hardware_settings.yaml + copy settings\iblrig_settings_template.yaml settings\iblrig_settings.yaml + - name: iblrig unit tests shell: bash -l {0} run: | - cd iblrig - cd test - python -m unittest discover - cd test_tasks - python -m unittest discover + python -m unittest discover -s ./iblrig/test -t . - name: Generate requirements_frozen.txt run: pip freeze > requirements_frozen.txt diff --git a/docs/source/installation.rst b/docs/source/installation.rst index 835f1b8ed..87500096f 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -68,7 +68,7 @@ Install iblrigv8 pip install -r requirements.txt -4. Install additional tasks and extractors +4. Install additional tasks and extractors for personal projects (optional) .. code-block:: powershell diff --git a/iblrig/base_tasks.py b/iblrig/base_tasks.py index 3ec8cc118..4ff8e4a53 100644 --- a/iblrig/base_tasks.py +++ b/iblrig/base_tasks.py @@ -646,6 +646,10 @@ def stop_mixin_bpod(self): self.bpod.close() def start_mixin_bpod(self): + if self.hardware_settings['device_bpod']['COM_BPOD'] is None: + raise ValueError("The value for device_bpod:COM_BPOD in " + "settings/hardware_settings.yaml is null. Please " + "provide a valid port name.") self.bpod = Bpod(self.hardware_settings['device_bpod']['COM_BPOD']) self.bpod.define_rotary_encoder_actions() @@ -688,6 +692,10 @@ def init_mixin_frame2ttl(self, *args, **kwargs): def start_mixin_frame2ttl(self): # todo assert calibration # todo release port on failure + if self.hardware_settings['device_frame2ttl']['COM_F2TTL'] is None: + raise ValueError("The value for device_frame2ttl:COM_F2TTL in " + "settings/hardware_settings.yaml is null. Please " + "provide a valid port name.") self.frame2ttl = frame2TTL.frame2ttl_factory(self.hardware_settings['device_frame2ttl']['COM_F2TTL']) try: self.frame2ttl.set_thresholds( @@ -714,6 +722,11 @@ def init_mixin_rotary_encoder(self, *args, **kwargs): ) def start_mixin_rotary_encoder(self): + if self.hardware_settings['device_rotary_encoder']['COM_ROTARY_ENCODER'] is None: + raise ValueError( + "The value for device_rotary_encoder:COM_ROTARY_ENCODER in " + "settings/hardware_settings.yaml is null. Please " + "provide a valid port name.") try: self.device_rotary_encoder.connect() except serial.serialutil.SerialException as e: diff --git a/iblrig/test/test_base_tasks.py b/iblrig/test/test_base_tasks.py index 81554631f..46ce83eb4 100644 --- a/iblrig/test/test_base_tasks.py +++ b/iblrig/test/test_base_tasks.py @@ -13,7 +13,8 @@ import ibllib.io.session_params as ses_params from iblrig.test.base import TASK_KWARGS -from iblrig.base_tasks import SoundMixin, RotaryEncoderMixin, BaseSession, BpodMixin, ValveMixin +from iblrig.base_tasks import (SoundMixin, RotaryEncoderMixin, BaseSession, BpodMixin, + ValveMixin, Frame2TTLMixin) from iblrig.base_choice_world import BiasedChoiceWorldSession from ibllib.io.session_params import read_params from iblrig.misc import _get_task_argument_parser, _post_parse_arguments @@ -62,6 +63,17 @@ def test_rotary_encoder_mixin(self): -2: 'RotaryEncoder1_3', 2: 'RotaryEncoder1_4' } + with self.assertRaises(ValueError): + RotaryEncoderMixin.start_mixin_rotary_encoder(session) + + def test_frame2ttl_mixin(self): + """ + Instantiates a bare session with the frame2ttl mixin + """ + session = self.session + Frame2TTLMixin.init_mixin_frame2ttl(session) + with self.assertRaises(ValueError): + Frame2TTLMixin.start_mixin_frame2ttl(session) def test_sound_card_mixin(self): """ @@ -75,6 +87,8 @@ def test_bpod_mixin(self): session = self.session BpodMixin.init_mixin_bpod(session) assert hasattr(session, 'bpod') + with self.assertRaises(ValueError): + BpodMixin.start_mixin_bpod(session) def test_valve_mixin(self): session = self.session diff --git a/iblrig/test/test_scripts.py b/iblrig/test/test_scripts.py index 0a2f62638..10e81cc42 100644 --- a/iblrig/test/test_scripts.py +++ b/iblrig/test/test_scripts.py @@ -9,13 +9,7 @@ import scripts.transfer_rig_data as transfer_rig_data from scripts.ibllib.purge_rig_data import purge_local_data, session_name - -OPENALYX_PARAMETERS = { - "base_url": "https://openalyx.internationalbrainlab.org", - "username": "intbrainlab", - "password": "international", - "silent": True -} +from ibllib.tests import TEST_DB class TestScripts(unittest.TestCase): @@ -29,7 +23,7 @@ def test_purge_rig_data(self): local_data = root.joinpath('iblrig_data', 'Subjects') local_data.mkdir(parents=True) # Need to add a username/password to the ONE call for the test to function - one = ONE(**OPENALYX_PARAMETERS) + one = ONE(**TEST_DB) # Find a session with at least 5 or so datasets and touch those files sessions = one.search(lab='cortex') session = next(x for x in sessions if len(one.list_datasets(x, collection='raw*')) > 5) diff --git a/requirements.txt b/requirements.txt index 53643c656..c668bdd11 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,4 +17,4 @@ pywin32; sys_platform == "win32" PySocks PyYAML scipy -sounddevice \ No newline at end of file +sounddevice