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

Throw error on export if required dependent properties are missing #667

Merged
merged 6 commits into from
Feb 12, 2025

Conversation

ehennestad
Copy link
Collaborator

@ehennestad ehennestad commented Feb 11, 2025

Motivation

Some properties are only required in the presence of other properties. For example, the source_script is an optional dataset of an NWBFile, but the file_name attribute is required. Therefore, if the source_script property of an NWBFile object has a value, the source_script_file_name property is required in the NWBFile.

Schema definition:
https://github.com/NeurodataWithoutBorders/nwb-schema/blob/f9fb35fb18b55444bfef45869133b6039c730df4/core/nwb.file.yaml#L236-L243

This PR throws an error on export if such a required dependent property is empty.

How to test the behavior?

nwbFile = NwbFile( ...
    'session_description', 'test file for nwb export', ...
    'identifier', 'export_test', ...
    'session_start_time', datetime("now", 'TimeZone', 'local') );

fileName = "testExportWithMissingRequiredDependentProperty";

% Should work without error
nwbExport(nwbFile, fileName + "_1.nwb")

% Now we add a value to the "general_source_script" property. This
% is a dataset with a required attribute called "file_name".
% Hence, the property "general_source_script_file_name" becomes
% required when we add a value to the "general_source_script"
% property.
nwbFile.general_source_script = '.../nwbExportTest.m';

% Exporting should now throw an error
nwbExport(nwbFile, fileName + "_2.nwb")

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?

Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.39%. Comparing base (faa4e59) to head (f3f387d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #667      +/-   ##
==========================================
- Coverage   95.39%   95.39%   -0.01%     
==========================================
  Files         137      137              
  Lines        5276     5274       -2     
==========================================
- Hits         5033     5031       -2     
  Misses        243      243              

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

@ehennestad ehennestad merged commit c8c855d into main Feb 12, 2025
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.

2 participants