diff --git a/.github/workflows/version_gallery.yml b/.github/workflows/version_gallery.yml new file mode 100644 index 000000000..44872daa2 --- /dev/null +++ b/.github/workflows/version_gallery.yml @@ -0,0 +1,32 @@ +name: Past PyNWB Version +on: + schedule: + - cron: "0 0 * * *" # daily + pull_request: + +jobs: + build-and-test: + name: Testing against past PyNWB versions + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + pynwb-version: ["2.1.0", "2.0.0"] + steps: + - uses: s-weigand/setup-conda@v1 + with: + update-conda: true + python-version: 3.9 + conda-channels: conda-forge + - uses: actions/checkout@v2 + - run: git fetch --prune --unshallow --tags + - name: Install pytest + run: | + pip install pytest + pip install pytest-cov + - name: Install package + run: | + pip install -e . + pip install pynwb==${{ matrix.pynwb-version }} + - name: Run pytest with coverage + run: pytest -rsx diff --git a/nwbinspector/checks/icephys.py b/nwbinspector/checks/icephys.py index 0358e6530..c27fdc16f 100644 --- a/nwbinspector/checks/icephys.py +++ b/nwbinspector/checks/icephys.py @@ -6,5 +6,5 @@ @register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=IntracellularElectrode) def check_intracellular_electrode_cell_id_exists(intracellular_electrode: IntracellularElectrode): """Check if the IntracellularElectrode contains a cell_id.""" - if intracellular_electrode.cell_id is None: + if hasattr(intracellular_electrode, "cell_id") and intracellular_electrode.cell_id is None: return InspectorMessage(message="Please include a unique cell_id associated with this IntracellularElectrode.") diff --git a/tests/unit_tests/test_icephys.py b/tests/unit_tests/test_icephys.py index 59e4ee6fa..fe3fa02a7 100644 --- a/tests/unit_tests/test_icephys.py +++ b/tests/unit_tests/test_icephys.py @@ -1,15 +1,23 @@ +import pytest +from packaging.version import Version from pynwb.icephys import IntracellularElectrode from pynwb.device import Device from nwbinspector import InspectorMessage, Importance, check_intracellular_electrode_cell_id_exists +from nwbinspector.utils import get_package_version +PYNWB_VERSION_LOWER_2_1_0 = get_package_version(name="pynwb") < Version("2.1.0") +PYNWB_VERSION_LOWER_SKIP_REASON = "This test requires PyNWB>=2.1.0" + +@pytest.mark.skipif(PYNWB_VERSION_LOWER_2_1_0, reason=PYNWB_VERSION_LOWER_SKIP_REASON) def test_pass_check_intracellular_electrode_cell_id_exists(): device = Device(name="device") ielec = IntracellularElectrode(name="ielec", cell_id="123", device=device, description="an intracellular electrode") assert check_intracellular_electrode_cell_id_exists(ielec) is None +@pytest.mark.skipif(PYNWB_VERSION_LOWER_2_1_0, reason=PYNWB_VERSION_LOWER_SKIP_REASON) def test_fail_check_intracellular_electrode_cell_id_exists(): device = Device(name="device") ielec = IntracellularElectrode(name="ielec", device=device, description="an intracellular electrode") @@ -21,3 +29,10 @@ def test_fail_check_intracellular_electrode_cell_id_exists(): object_name="ielec", location="/", ) + + +@pytest.mark.skipif(not PYNWB_VERSION_LOWER_2_1_0, reason="This test requires PyNWB<2.1.0") +def test_skip_check_for_lower_versions(): + device = Device(name="device") + ielec = IntracellularElectrode(name="ielec", device=device, description="an intracellular electrode") + assert check_intracellular_electrode_cell_id_exists(ielec) is None