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

Refactor: Add arguments block to main MatNWB api functions #619

Merged
merged 36 commits into from
Nov 19, 2024

Conversation

ehennestad
Copy link
Collaborator

@ehennestad ehennestad commented Nov 7, 2024

Fix #606

Motivation

  • Use argument blocks for better input validation of user-facing functions
  • Improve test coverage

How to test the behavior?

Show here how to reproduce the new behavior (can be a bug fix or a new feature)

Checklist

  • Have you ensured the PR description clearly describes the problem and solutions?
  • Have you checked to ensure that there aren't other open or previously closed Pull Requests for the same change?
  • If this PR fixes an issue, is the first line of the PR description fix #XX where XX is the issue number?

- Move some functions io.spec namespace
- Add validation functions in matnwb.common namespace
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 93.15068% with 20 lines in your changes missing coverage. Please review.

Project coverage is 95.16%. Comparing base (21bd143) to head (b18424a).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
+file/fillValidators.m 46.66% 8 Missing ⚠️
+io/+spec/readEmbeddedSpecifications.m 85.18% 4 Missing ⚠️
NwbFile.m 92.59% 2 Missing ⚠️
nwbRead.m 95.00% 2 Missing ⚠️
+io/+spec/+internal/readEmbeddedSpecLocation.m 90.00% 1 Missing ⚠️
+schemes/Namespace.m 83.33% 1 Missing ⚠️
+spec/loadCache.m 91.66% 1 Missing ⚠️
generateExtension.m 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #619      +/-   ##
==========================================
+ Coverage   90.85%   95.16%   +4.30%     
==========================================
  Files         107      113       +6     
  Lines        4781     4734      -47     
==========================================
+ Hits         4344     4505     +161     
+ Misses        437      229     -208     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Extracted function from NwbFile/export to collect all code related to reading and writing embedded specifications in one place

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved rehash statement to file.cloneNwbFileClass

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Use onCleanup to close space and object instead of doing it "conditionally"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Add utility function for finding the latest available nwb schema version

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Add validator function to assert that a path is an NWB filepath

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Add validator function to assert that a versionNumber value is a properly formatted version number string and that the version number is available among the available nwb schemas

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • Specify default values in property block instead of constructor
  • Use assert instead of if to improve coverage

Copy link
Collaborator Author

@ehennestad ehennestad Nov 17, 2024

Choose a reason for hiding this comment

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

  • Also allow schemaSource being a string
  • use fileread instead of fopen, fwrite, fclose sequence

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • Add named arguments and arguments block to simplify argument parsing
  • Negate isempty(fileList) block to remove potentially unreachable code

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Add unit tests to increase coverage for nwbRead, nwbExport

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Add unites to test the file.cloneNwbFileClass function

@@ -131,6 +142,9 @@ function testExternalFilters(testCase)
import types.untyped.datapipe.properties.DynamicFilter;
import types.untyped.datapipe.properties.Shuffle;

% TODO: Why is Filter.LZ4 not part of the exported Pipe, i.e when the
Copy link
Collaborator Author

@ehennestad ehennestad Nov 17, 2024

Choose a reason for hiding this comment

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

@bendichter @lawrence-mbf I need help to understand if this is a bug

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Result of updating class generator to fix word capitalisation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added arguments block

Copy link
Collaborator Author

@ehennestad ehennestad Nov 17, 2024

Choose a reason for hiding this comment

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

Move default output to beginning as it was potentially unreachable for unit tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed unused method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added named arguments and argument block

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed to work for older schema versions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • Add arguments block to constructor and export method
  • Added mode for overwriting file on export
  • Use assertion instead of if block with error on export to improve coverage
  • removed embedSpecifications method. Was moved to io.spec.writeEmbeddedSpecifications

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moved file into resources folder

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • Add named arguments and arguments block
  • Pass namespaceFiles cell array to generateExtension instead of potentially calling it twice

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • Add named arguments and arguments block
  • Added local validator function mustBeYamlFle to check that namespace spec files exist
  • simplified code in loop for generating class files

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • Add optional output argument. Can be used by cleanup operations to regenerate cleared namespaces
  • Add input for specifying root folder where classes to be cleared exist
  • Added option for also clearing the namespace cache

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • Rename input arguments to be more descriptive
  • Added argument blocks for simpler input handling / validation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved to resources folder
Changed to be up-to-date

@@ -0,0 +1,18 @@
function specLocation = readEmbeddedSpecLocation(fid, specLocAttributeName)
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the difference between readEmbeddedSpecLocaation and getEmbeddedSpecLocation? Can you add a comment here indicating the distinction?

Copy link
Collaborator Author

@ehennestad ehennestad Nov 18, 2024

Choose a reason for hiding this comment

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

getEmbeddedSpecLocation - Takes a filepath as an input.
readEmbeddedSpecLocation - Takes a fid as an input, useful if the file is already opened

function closeSpaceAndObject(spaceId, objectId)
H5S.close(spaceId);
H5O.close(objectId);
end
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like it could have some side effects. Are you able to separate this change into a different PR?

Copy link
Collaborator Author

@ehennestad ehennestad Nov 18, 2024

Choose a reason for hiding this comment

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

I would argue that it is more robust than the current code.
When h5CleanupObj is cleared from the workspace, i.e when the function exits, either on returning or on errors, it will run the callback and close the space and objects.

At the moment if the code fails on line 16-18 or 26, these would not be closed, but with the cleanup callback they will

@bendichter bendichter self-requested a review November 19, 2024 15:18
@bendichter bendichter merged commit fa04ab0 into master Nov 19, 2024
7 checks passed
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.

[Feature]: Improve test coverage to 95%
2 participants