Skip to content

Commit

Permalink
simplify testing suite
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD committed Sep 6, 2024
1 parent c7861f4 commit 0f3fb4b
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 147 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/assess-file-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ on:
SOURCE_CHANGED:
description: "Whether or not the files under /src/ were changed."
value: ${{ jobs.build.outputs.SOURCE_CHANGED }}
TESTING_CHANGED:
description: "Whether or not to regenerate the testing files and reupload them to DANI staging."
value: ${{ jobs.build.outputs.TESTING_CHANGED }}

jobs:
build:
runs-on: ubuntu-latest
# Map the job outputs to step outputs
outputs:
SOURCE_CHANGED: ${{ steps.flagged-changes.outputs.SOURCE_CHANGED }}
TESTING_CHANGED: ${{ steps.flagged-changes.outputs.TESTING_CHANGED }}

name: Test changed-files
steps:
Expand All @@ -33,7 +29,6 @@ jobs:
id: flagged-changes
run: |
echo "::set-output name=SOURCE_CHANGED::false"
echo "::set-output name=TESTING_CHANGED::false"
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo $file
if [[ $file == "src/nwbinspector/"* || $file == "requirements.txt" || $file == "setup.py" || $file == "tests/"* ]]
Expand All @@ -43,11 +38,4 @@ jobs:
else
echo "Source not changed"
fi
if [[ $file == "src/nwbinspector/testing.py" ]]
then
echo "Testing changed"
echo "::set-output name=TESTING_CHANGED::true"
else
echo "Testing not changed"
fi
done
12 changes: 6 additions & 6 deletions .github/workflows/dev-gallery.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Development Version Gallery
on: workflow_call

env:
TESTING_FILES_FOLDER_PATH: ./204919/testing_files/

jobs:
build-and-test:
name: Testing against dev PyNWB version
Expand All @@ -16,8 +19,6 @@ jobs:
- uses: actions/checkout@v3
- run: git fetch --prune --unshallow --tags

- name: Install ROS3
run: conda install -c conda-forge h5py
- name: Install pytest
run: |
pip install pytest
Expand All @@ -26,10 +27,9 @@ jobs:
run: |
pip install -e ".[dandi]"
pip install git+https://github.com/neurodatawithoutborders/pynwb@dev
- name: Download testing data and set config path
run: |
dandi download "https://gui-staging.dandiarchive.org/#/dandiset/204919"
python -c "from nwbinspector.testing import update_testing_config; update_testing_config(key='LOCAL_PATH', value='./204919/testing_files/')"
run: dandi download "https://gui-staging.dandiarchive.org/#/dandiset/204919"

- name: Run pytest with coverage
- name: Run pytest
run: pytest -rsx
7 changes: 4 additions & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
CODECOV_TOKEN:
required: true

env:
TESTING_FILES_FOLDER_PATH: ./204919/testing_files/

jobs:
build-and-test:
name: Testing using ${{ matrix.os }} with ${{ matrix.python-version }}
Expand Down Expand Up @@ -33,9 +36,7 @@ jobs:
- name: Install package
run: pip install ".[dandi]"
- name: Download testing data and set config path
run: |
dandi download "https://gui-staging.dandiarchive.org/#/dandiset/204919"
python -c "from nwbinspector.testing import update_testing_config; update_testing_config(key='LOCAL_PATH', value='./204919/testing_files/')"
run: dandi download "https://gui-staging.dandiarchive.org/#/dandiset/204919"

- name: Run pytest with coverage
run: pytest -rsx --cov=nwbinspector --cov-report xml:./coverage.xml
Expand Down
41 changes: 0 additions & 41 deletions .github/workflows/update-testing-files.yml

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Improvements
* Removed the `robust_ros3_read` utility helper. [#506](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/506)
* Simplified the `nwbinspector.testing` configuration framework.



Expand Down
3 changes: 0 additions & 3 deletions base_test_config.json

This file was deleted.

9 changes: 0 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path
from shutil import copy

from setuptools import find_packages, setup

Expand All @@ -11,14 +10,6 @@
with open(root / "src" / "nwbinspector" / "_version.py") as f:
version = f.read()

# Instantiate the testing configuration file from the base file `base_test_config.json`
# This requires the current working directory to be the top level
# of a local copy of the NWB Inspector GitHub repository
BASE_CONFIG_FILE_PATH = Path.cwd() / "base_test_config.json"
TESTING_CONFIG_FILE_PATH = Path.cwd() / "tests" / "testing_config.json"
if not TESTING_CONFIG_FILE_PATH.exists():
copy(src=str(BASE_CONFIG_FILE_PATH), dst=str(TESTING_CONFIG_FILE_PATH))

setup(
name="nwbinspector",
version=version.split('"')[1],
Expand Down
6 changes: 0 additions & 6 deletions src/nwbinspector/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
from ._testing import (
TESTING_CONFIG_FILE_PATH,
check_hdf5_io_open,
check_streaming_enabled,
check_streaming_tests_enabled,
check_zarr_io_open,
generate_image_series_testing_files,
generate_testing_files,
load_testing_config,
make_minimal_nwbfile,
update_testing_config,
)

__all__ = [
"check_streaming_tests_enabled",
"check_streaming_enabled",
"check_hdf5_io_open",
"check_zarr_io_open",
"load_testing_config",
"update_testing_config",
"generate_testing_files",
"generate_image_series_testing_files",
"make_minimal_nwbfile",
"TESTING_CONFIG_FILE_PATH",
]
32 changes: 0 additions & 32 deletions src/nwbinspector/testing/_testing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Helper functions for internal use across the testing suite."""

import json
import os
from datetime import datetime
from pathlib import Path
Expand All @@ -16,9 +15,6 @@

from ..utils import get_package_version, is_module_installed, strtobool

# The tests must be invoked at the outer level of the repository
TESTING_CONFIG_FILE_PATH = Path.cwd() / "tests" / "testing_config.json"


def check_streaming_tests_enabled() -> Tuple[bool, Optional[str]]:
"""
Expand Down Expand Up @@ -52,34 +48,6 @@ def check_streaming_tests_enabled() -> Tuple[bool, Optional[str]]:
return streaming_enabled and not environment_skip_flag_bool and have_dandi, failure_reason


def load_testing_config() -> dict:
"""Helper function for loading the testing configuration file as a dictionary."""
# This error would only occur if someone installed a previous version
# directly from GitHub and then updated the branch/commit in-place
if not TESTING_CONFIG_FILE_PATH.exists(): # pragma: no cover
raise FileNotFoundError(
f"The testing configuration file not found at the location '{TESTING_CONFIG_FILE_PATH}'! "
"Please try reinstalling the package."
)

with open(file=TESTING_CONFIG_FILE_PATH) as file:
test_config = json.load(file)

return test_config


def update_testing_config(key: str, value):
"""Update a key/value pair in the testing configuration file through the API."""
testing_config = load_testing_config()

if key not in testing_config:
raise KeyError("Updating the testing configuration file via the API is only possible for the pre-defined keys!")
testing_config[key] = value

with open(file=TESTING_CONFIG_FILE_PATH, mode="w") as file:
json.dump(testing_config, file)


def generate_testing_files(): # pragma: no cover
"""Generate a local copy of the NWB files required for all tests."""
generate_image_series_testing_files()
Expand Down
23 changes: 0 additions & 23 deletions tests/test_testing_module.py

This file was deleted.

23 changes: 11 additions & 12 deletions tests/unit_tests/test_image_series.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import unittest
from pathlib import Path
from shutil import rmtree
Expand All @@ -14,26 +15,24 @@
check_image_series_external_file_valid,
check_timestamps_match_first_dimension,
)
from nwbinspector.testing import load_testing_config, make_minimal_nwbfile
from nwbinspector.testing import make_minimal_nwbfile

try:
testing_config = load_testing_config()
testing_file = Path(testing_config["LOCAL_PATH"]) / "image_series_testing_file.nwb"
NO_CONFIG = False # Depending on the method of installation, a config may not have generated
except FileNotFoundError:
testing_file = "Not found"
NO_CONFIG = True
TESTING_FILES_FOLDER_PATH = os.environ.get("TESTING_FILES_FOLDER_PATH", None)


@unittest.skipIf(
NO_CONFIG or not testing_file.exists(),
reason=f"The ImageSeries unit tests were skipped because the required file ({testing_file}) was not found!",
TESTING_FILES_FOLDER_PATH is None,
reason=(
f"These ImageSeries unit tests were skipped because the environment variable "
"'TESTING_FILES_FOLDER_PATH' was not set!"
),
)
class TestExternalFileValid(unittest.TestCase):
@classmethod
def setUpClass(cls):
testing_config = load_testing_config()
cls.testing_file = Path(testing_config["LOCAL_PATH"]) / "image_series_testing_file.nwb"
cls.testing_file = Path(TESTING_FILES_FOLDER_PATH) / "image_series_testing_file.nwb"

assert cls.testing_file.exists()

def setUp(self):
self.io = NWBHDF5IO(path=self.testing_file, mode="r")
Expand Down

0 comments on commit 0f3fb4b

Please sign in to comment.