Skip to content
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

Pytest revamp #743

Merged
merged 18 commits into from
Jan 19, 2024
Merged

Pytest revamp #743

merged 18 commits into from
Jan 19, 2024

Conversation

CBroz1
Copy link
Member

@CBroz1 CBroz1 commented Dec 29, 2023

Description

Completely revises pytests to favor use of minirec as a data source. Avoids direct assertion of values read from data, instead favoring a cross-ref of data in tables with data in the raw file.

If coverage assessment is limited to common, lfp and utils subpackages, this PR increases coverage from 26% to 67%

  • Adjustments to package proper motivated by testing needs or linting suggestions
    • .github/workflow/test-conda.yaml: add download of data from box
    • ./pyproject.toml: Add docker package as tests dependency. Add config options for running tests
    • common/common_device.py: use new test_mode boolean to determine if user should be prompted for confirmation. Centralize prompt logic to prompt_insert function to be used across all device tables.
    • common_dio.py, common_filter.py, and common_interval.py: Add boolean flag for returning plots from functions. This permits tests to check then contents of plots. Do people use these plots or can they be deprecated?
    • common_position: @edeno - did you make a release of the updated position_tools? Rather than set requirements to pull from git, I run a try/except import that falls back on get_centriod and log a warning.
    • common_session: rewrap comment to 80c, permit *args, **kwargs for helper functions. This permits tests to pass safemode=False to avoid prompts.
    • data_import/__init__.py add note regarding the naming collision across module and func insert_session. This caused some errors in testing I was able to overcome, but should be changed in the future.
    • insert_sessions.py: warnings->logger to make printouts show as spyglass-specific
    • decoding_merge.py: add noqa to pass pre-commit linter check
    • settings.py: add test_mode to prevent prompts
    • dj_merge_tables.py: typo on edge case
    • dj_mixin.py: add refresh cache secondary check.
  • Increase coverage of common and lfp pipelines as first pass
    • tests/readme: Developer notes
    • tests/datajoint/etc -> container.py: remove kackery dependency as a wrapper on subprocess in favor of docker package designed for container management
    • tests/*/conftest.py: home of fixtures shared across tests
    • tests/{pipeline}/: reorganize to mirror package organization.
    • test_interval: parameterize tests to run same funcs on expected input/output
    • various: add pytest.mark.skip on items we don't expect to cover

Checklist:

  • This PR should be accompanied by a release: no
  • (If release) I have updated the CITATION.cff
  • I have updated the CHANGELOG.md
  • I have added/edited docs/notebooks to reflect the changes

src/spyglass/common/common_session.py Show resolved Hide resolved
src/spyglass/common/common_device.py Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
src/spyglass/common/common_session.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
tests/data_import/test_insert_sessions.py Show resolved Hide resolved
tests/old_tests.py Outdated Show resolved Hide resolved
tests/utils/test_nwb_helper_fn.py Show resolved Hide resolved
CBroz1 added 5 commits January 5, 2024 17:43
- Add `return_fig` param to plotting helper functions to permit tests
  - `common_filter`
  - `common_interval`
- Add coverage for ~1/2 of `common`
  - `common_behav`
  - `common_device`
  - `common_ephys`
  - `common_filter`
  - `common_interval` - with helper funcs tested seperately
  - `common_lab`
  - `common_nwbfile` - partial
@edeno edeno mentioned this pull request Jan 18, 2024
4 tasks
@CBroz1 CBroz1 marked this pull request as ready for review January 18, 2024 16:54
@CBroz1 CBroz1 requested a review from edeno January 18, 2024 16:55
Copy link
Collaborator

@edeno edeno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor change. I did make an updated position_tools release.

src/spyglass/common/common_filter.py Show resolved Hide resolved
src/spyglass/data_import/insert_sessions.py Outdated Show resolved Hide resolved
@edeno edeno merged commit 0089d5e into LorenFrankLab:master Jan 19, 2024
7 checks passed
edeno added a commit that referenced this pull request Jan 20, 2024
* Docs fixes: tidy decoding docstrings, change hatch version get, add inits

* Pytest revamp (#743)

* WIP: Pull from old stash, resolve conflicts

* Pytest WIP. Position centriod fix. Centralize device prompt logic

* Add tests for all tables in

* WIP: Improve coverage behav, dio

* WIP: Add coverage, see details:

- Add `return_fig` param to plotting helper functions to permit tests
  - `common_filter`
  - `common_interval`
- Add coverage for ~1/2 of `common`
  - `common_behav`
  - `common_device`
  - `common_ephys`
  - `common_filter`
  - `common_interval` - with helper funcs tested seperately
  - `common_lab`
  - `common_nwbfile` - partial

* WIP pytest common 2nd half, start lfp

* WIP lfp tests, ahead of fetch upstream

* Add lfp pipeline tests

* Run pre-commit checks

* Fix bug

* Unpin position_tools for CI

* Change download data dir

* Change download data dir 2

* Fix teardown. Coverage 67%

* Update changelog

* logger.warn -> logger.warning

* Minor decoding fixes (#769)

* Add non-local detector and remove replay_trajectory_classification

* Reorganize

* Fix formatting and imports

* Update .gitignore

* Remove because of circular import

* Fix name of parameter

* Handle case where ther is only one interval

* Fix settings

* Handle single interval

* from_unit_dict does not exist in 0.98.2 of spike interface

* Simplify call

* Update for SpikeSorting merge table and add spyglass mixin

* Fix dependencies

* Fix merge conflict

* Update src/spyglass/decoding/v1/clusterless.py

Co-authored-by: Chris Brozdowski <[email protected]>

* Update src/spyglass/decoding/v1/clusterless.py

Co-authored-by: Chris Brozdowski <[email protected]>

* Update src/spyglass/decoding/v1/clusterless.py

Co-authored-by: Chris Brozdowski <[email protected]>

* Update src/spyglass/decoding/v1/clusterless.py

Co-authored-by: Chris Brozdowski <[email protected]>

* Apply suggestions from code review

Co-authored-by: Chris Brozdowski <[email protected]>

* Remove unused imports and format

* Add saving of waveform features

* Don't store electrodes, full waveforms, waveform mean

* Fix spike times and add convenience method

* Add spike location and some formatting

* Remove circular import

* Fix dict expansion

* Initial working clusterless pipeline

* Add position group

* Rename classifier to decoding

* Handle encoding and decoding intervals

* Put old files under v0, try/except for old decoding package

* Rename visualization and remove from v0

v0 visualization is redundant with visualization

* Place parameters and position group in core.py

* Add sorted spikes decoding

* Add objects to init for convenience

* Remove unused imports

* Fix fetching of spike times

* Insert into merge table

* Update CHANGELOG.md

* Function for removing decoding outputs not in DecodingOutput

* Fix name

* Add draft of tutorials and rearrange notebooks

* Fix config loading

* Add 1D decoding and some notes on estimate_parameters kwarg

* Update 43_Decoding_SortedSpikes.ipynb

* Remove old decoding notebook

* Save initial conditions and discrete transitions

* Apply suggestions from code review

Co-authored-by: Chris Brozdowski <[email protected]>

* Be more specific with import error

* Remove unneeded comments

* Remove incorrect dimension name

* Project merge_id from SpikeSortingOutput for clarity

* Update src/spyglass/decoding/v0/clusterless.py

Co-authored-by: Chris Brozdowski <[email protected]>

* Update src/spyglass/decoding/v0/clusterless.py

Co-authored-by: Chris Brozdowski <[email protected]>

* Update src/spyglass/decoding/v0/clusterless.py

Co-authored-by: Chris Brozdowski <[email protected]>

* Fix linting

* Update notebooks

* Ignore .pem

* Add session as a primary key for Groups

* Add some helper methods

* Update notebooks

* Update README.md

* Update pyscripts

* Update 42_Decoding_Clusterless.ipynb

* Update CHANGELOG.md

* Add fetch and insert

* Simplify class conversion

* Do the dictionary conversion of class for the user

* Update CHANGELOG.md

* Update .gitignore

* Use methods in populate

* Avoid fetching interval range if not needed

* Generalize finding class from modules

* Use args/kwargs

* Simplify tuple unpacking

* Make decoding kwargs nullable

* Add function for get_recording and get_sorting to the spikesorting merge table

* make decoding waveform features agnostic to spikesorting source

* Fix spelling

* Use fetch1_dataframe for position

* Use self instead of class

* Update src/spyglass/decoding/v1/sorted_spikes.py

Co-authored-by: Samuel Bray <[email protected]>

* Be more careful about populating select keys

* Make more readable/remove unused imports

* Save classifier

* Clean up saved model paths

* add function load_linear_position_info

* Update src/spyglass/decoding/v1/sorted_spikes.py

Co-authored-by: Samuel Bray <[email protected]>

* Update 41_Extracting_Clusterless_Waveform_Features.py

* Update docstring

* Apply suggestions from code review

Co-authored-by: Chris Brozdowski <[email protected]>

* Update src/spyglass/decoding/v1/clusterless.py

Co-authored-by: Chris Brozdowski <[email protected]>

* Update src/spyglass/decoding/v1/clusterless.py

Co-authored-by: Chris Brozdowski <[email protected]>

* Fix linting

* Fix syntax

* Rename variable to avoid confusion

* Restrict UnitWaveformFeaturesGroup and SortedSpikesGroup

* Concatenate linear position and position dataframes

* Static methods don't require instantiating class

* Avoid merge restrict

* Add version to defaults

* Remove unused import

* Fix classifier path

* Add dry run

* Remove non-default

* Handle permissions and file not found

* Keep position info within encoding/decoding interval

* Add methods to get the spike_times, spike_indicators, firing rate

* Fix docstring to match default

* Implement function rather than import

* Remove unused broken imports

* Add decoding cleanup

* Fix import

* Put old vis code back

* Fix import

* Add draft helper functions

* Limit options on input

* Fix logic

* Fix where the key is passed

* Update notebooks

* Host main visualizations in non_local_detector repo

* Update notebooks/py_scripts/41_Extracting_Clusterless_Waveform_Features.py

Co-authored-by: Chris Brozdowski <[email protected]>

* Update src/spyglass/spikesorting/merge.py

Co-authored-by: Chris Brozdowski <[email protected]>

* Update src/spyglass/decoding/decoding_merge.py

Co-authored-by: Chris Brozdowski <[email protected]>

* Revert "Limit options on input"

This reverts commit 386714c.

* Use f-string for version

* Add useful imports to the top level

This would have to change a bit if there were multiple versions of the pipeline.

* Make source class a hidden attribute

* Update CHANGELOG.md

---------

Co-authored-by: Chris Brozdowski <[email protected]>
Co-authored-by: Sam Bray <[email protected]>

* DLC notebooks 21 and 22 (#772)

* add envs to bashrc; multi cam addition

* 12/11/23 using TackEpoch to define interval_names

* 12/11/23 remove comment

* del smooth duration

* jan 10 again

* DLC noteboks 5 and 6

* 5 and 6

* fix ignore and 21

* Removed submodule

* removed .gitignore

* DLC notebooks

* Docs fixes: tidy decoding docstrings, change hatch version get, add inits

* Jupysync, blackify, purge old .py nbs

* Docs updates for new notebooks

* Update changelog

* Spell fix, pre-commit

---------

Co-authored-by: Eric Denovellis <[email protected]>
Co-authored-by: Sam Bray <[email protected]>
Co-authored-by: emreybroyles <[email protected]>
@CBroz1 CBroz1 deleted the tests branch February 9, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants