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

Update test suite: Suppress output & expected warnings + improve performance #658

Merged
merged 169 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
fc9ca2a
Coarse fix for #595
ehennestad Sep 14, 2024
1b4dbfb
Merge branch 'master' into 595-use-empty-indices-for-datastub
ehennestad Oct 31, 2024
a458d62
Only include namespaces for types that are included in NWB file on ex…
ehennestad Nov 4, 2024
13822a8
Merge branch 'master' into 607-fix-namespace-embedding-in-file
ehennestad Nov 23, 2024
35150e9
Add functionality for installing extensions
ehennestad Nov 23, 2024
bd40894
Minor fixes
ehennestad Nov 23, 2024
132aa67
Update comment
ehennestad Nov 23, 2024
781f303
Add comment + print message when extension has been installed
ehennestad Nov 23, 2024
eab998e
Update installExtension.m
ehennestad Nov 23, 2024
be4be3d
Fix changed variable name
ehennestad Nov 23, 2024
650ceec
Update matnwb_createNwbInstallExtension.m
ehennestad Nov 23, 2024
8e18448
Create listNwbTypeHierarchy.m
ehennestad Nov 25, 2024
7c41ca6
Add private method for embedding specifications to file on export
ehennestad Nov 25, 2024
a467c46
Fix variable name
ehennestad Nov 25, 2024
0911141
Update testCreateParsedType.m
ehennestad Nov 25, 2024
744fef9
Suppress output of nwbfile
ehennestad Nov 27, 2024
ff95e98
Add workflow for updating nwbInstallExtension
ehennestad Nov 28, 2024
bb3514b
Add option to save extension in custom location
ehennestad Nov 28, 2024
184fa81
Create InstallExtensionTest.m
ehennestad Nov 28, 2024
e0cba2f
Add .env file to replace env.mat
ehennestad Nov 28, 2024
df37d10
Update .gitignore
ehennestad Nov 28, 2024
ddbe9dc
Update docstring
ehennestad Dec 6, 2024
44a6a20
Merge branch 'master' into add-nwb-install-extension
ehennestad Dec 12, 2024
24c3899
Merge branch 'add-nwb-install-extension' of https://github.com/Neurod…
ehennestad Dec 12, 2024
da00cea
Change dispExtensionInfo to return info instead of displaying + add test
ehennestad Dec 12, 2024
40b7703
Reorganize code into separate functions and add tests
ehennestad Dec 12, 2024
eeb2006
Merge branch 'master' into 607-fix-namespace-embedding-in-file
ehennestad Dec 12, 2024
e3b4906
Merge branch 'master' into add-nwb-install-extension
ehennestad Dec 12, 2024
6faba21
Minor changes to improve test coverage
ehennestad Dec 12, 2024
a74a2d2
add nwbInstallExtension to docs
ehennestad Dec 12, 2024
16877f9
Update update_extension_list.yml
ehennestad Dec 12, 2024
0bc735f
Update downloadExtensionRepository.m
ehennestad Dec 12, 2024
67680c2
Update docstring for nwbInstallExtension
ehennestad Jan 2, 2025
b2e679a
Fix docstring indentation in nwbInstallExtension
ehennestad Jan 2, 2025
69f07d9
Add doc pages describing how to use (ndx) extensions
ehennestad Jan 2, 2025
07d5162
Fix typo
ehennestad Jan 2, 2025
13b0d1b
Update +tests/+unit/InstallExtensionTest.m
ehennestad Jan 9, 2025
32342ed
Update docs/source/pages/getting_started/using_extensions/generating_…
ehennestad Jan 9, 2025
81a2259
Merge branch 'master' into add-nwb-install-extension
bendichter Jan 14, 2025
b9f8f2c
Add docstrings for functions to retrieve and list extension info
ehennestad Jan 14, 2025
2b0e820
Fix docstring formatting/whitespace
ehennestad Jan 14, 2025
bcb2584
Update listExtensions.m
ehennestad Jan 14, 2025
691ef81
Move static test methods into io.internal.h5 namespace
ehennestad Jan 16, 2025
5958136
Update writeEmbeddedSpecifications.m
ehennestad Jan 16, 2025
f5af434
Add validateEmbeddedSpecifications
ehennestad Jan 16, 2025
9de778b
Update NwbFile.m
ehennestad Jan 16, 2025
258b8dc
Create listEmbeddedSpecNamespaces.m
ehennestad Jan 16, 2025
c694d10
Update nwbExportTest.m
ehennestad Jan 16, 2025
8f0ec28
Update test for spec/namespace embedding
ehennestad Jan 16, 2025
7e9aac6
Merge branch 'add-nwb-install-extension' into 607-fix-namespace-embed…
ehennestad Jan 16, 2025
09ec654
Merge branch 'master' into 607-fix-namespace-embedding-in-file
ehennestad Jan 22, 2025
ab79e41
Update read_indexed_column.m
ehennestad Jan 22, 2025
7a32b7c
Add disclaimer in deleteGroup function
ehennestad Jan 22, 2025
d97c83e
Update read_indexed_column.m
ehennestad Jan 30, 2025
863d319
Fix broken test
ehennestad Jan 30, 2025
63c2194
add test-requirement
ehennestad Jan 30, 2025
9acd164
Merge branch 'ehennestad-patch-fix-typo' into 607-fix-namespace-embed…
ehennestad Jan 30, 2025
b56c632
Merge branch 'master' into 607-fix-namespace-embedding-in-file
ehennestad Jan 31, 2025
29bf432
Fix: Ensure object is group before deleting
ehennestad Jan 31, 2025
680c4cf
Fix error id
ehennestad Jan 31, 2025
2a3c862
Add unittests for functions in io.internal.h5 namespace
ehennestad Jan 31, 2025
031949f
Merge branch '607-fix-namespace-embedding-in-file' of https://github.…
ehennestad Jan 31, 2025
cdca7a9
Merge branch 'master' into update-tests-suppress-expected-warnings
ehennestad Jan 31, 2025
26964c1
Suppress output
ehennestad Jan 31, 2025
418c69b
Remove duplicated code
ehennestad Jan 31, 2025
8cf32a5
Update fillClass.m
ehennestad Jan 31, 2025
177e209
Update fillClass/fillExport to add check for dependent & required pro…
ehennestad Feb 1, 2025
9150171
Add warnIfRequiredDependencyMissing
ehennestad Feb 1, 2025
174dc5c
Update generated types
ehennestad Feb 1, 2025
f7f1f43
Add default property values to generated type classes
ehennestad Feb 1, 2025
e9c8154
Update warnIfPropertyAttributeNotExported to compare value with deful…
ehennestad Feb 1, 2025
1475d77
Add value for required property in VectorData
ehennestad Feb 1, 2025
6d829e3
Add unit tests
ehennestad Feb 1, 2025
6dd99f1
Supress warning in test
ehennestad Feb 1, 2025
b775dcc
Update tests.util.getPythonPath and remove similar code from +tests/…
ehennestad Feb 1, 2025
db1b043
Update GenerationTest.m
ehennestad Feb 1, 2025
ff4bc14
Suppress warnings in DataPipeTest
ehennestad Feb 1, 2025
5e644ec
Suppress output
ehennestad Feb 1, 2025
f9889ba
Improve performance of if block
ehennestad Feb 1, 2025
4ef6e60
Remove try/catch
ehennestad Feb 1, 2025
10034ec
Use verifyWarning instead of custom warning manipulation
ehennestad Feb 1, 2025
ff53f04
Updated neurodata type classes
ehennestad Feb 1, 2025
cf990d2
Merge branch 'fix-required-attribute-properties' into fix-warn-if-pro…
ehennestad Feb 1, 2025
e5cf322
Add unit test
ehennestad Feb 1, 2025
d5913e3
Merge branch 'fix-warn-if-property-attribute-not-exported' into updat…
ehennestad Feb 1, 2025
a97d7d7
Add shared fixture
ehennestad Feb 1, 2025
c179919
Chnage name part 1/2
ehennestad Feb 1, 2025
ecefc59
Change name part2/2
ehennestad Feb 1, 2025
a15884b
Suppress output
ehennestad Feb 1, 2025
5727e88
Merge branch 'ehennestad-patch-improve-fill-constructor-docstring' in…
ehennestad Feb 1, 2025
4e60286
Add shared test fixture to tutorialtest
ehennestad Feb 1, 2025
c667451
Update nwbtest.m
ehennestad Feb 1, 2025
9f46975
Update nwbtest.m
ehennestad Feb 2, 2025
6097e47
Refactor unit tests for test-schemas for better performance (#659)
ehennestad Feb 2, 2025
e51864e
Add Extension fixture
ehennestad Feb 2, 2025
f0b2a4b
Refactor - slide suite sorting
ehennestad Feb 2, 2025
fe8adfa
Refactor misc unittests in "tests.unit" namespace (#660)
ehennestad Feb 2, 2025
8a6aa19
Move tutorial tests from tests.unit to tests.system.tutorial (#661)
ehennestad Feb 2, 2025
7c14abd
Update nwbtest.m
ehennestad Feb 2, 2025
8e826b5
Fix bug with clearing and regenerating types
ehennestad Feb 2, 2025
2b152ae
Ignore generated types from test coverage
ehennestad Feb 2, 2025
0905cf6
Rename ExtensionFixture to ExtensionGenerationFixture
ehennestad Feb 3, 2025
5c40f8c
Add docstring to ExtensionGenerationFixture
ehennestad Feb 3, 2025
dd33f2e
Rename ResetGeneratedTypesFixture to NwbClearGeneratedFixture
ehennestad Feb 3, 2025
0f5d3c9
Rename NwbTypeGeneratorFixture to GenerateCoreFixture
ehennestad Feb 3, 2025
201f172
Fix - add default input to NwbClearGeneratedFixture
ehennestad Feb 3, 2025
733cf93
Update nwbtest - Save generated reports to fixed directory
ehennestad Feb 3, 2025
ca73659
Add docs/reports to gitignore
ehennestad Feb 3, 2025
d850041
Add .coverageignore file and local function for collecting list of fi…
ehennestad Feb 3, 2025
46d6d8d
Fix workflow for running tests (report output directory)
ehennestad Feb 3, 2025
bb5a65b
Merge branch 'master' into update-tests-suppress-expected-warnings
ehennestad Feb 3, 2025
b14b9b8
Merge branch 'master' into 607-fix-namespace-embedding-in-file
ehennestad Feb 3, 2025
4d7c5b7
Update nwbExportTest.m
ehennestad Feb 3, 2025
604e22c
Merge branch 'main' into 607-fix-namespace-embedding-in-file
ehennestad Feb 3, 2025
6322412
Update branch name references from master to main
ehennestad Feb 4, 2025
999ff12
Change branch name from master to main in md and workflow files
ehennestad Feb 4, 2025
ce8335f
Fix typo
ehennestad Feb 4, 2025
23489a7
Merge remote-tracking branch 'origin/main' into update-tests-suppress…
ehennestad Feb 4, 2025
2eb94c0
Merge branch 'ehennestad-update-default-branch-name' into update-test…
ehennestad Feb 4, 2025
a27d4b9
Merge branch 'main' into update-tests-suppress-expected-warnings
ehennestad Feb 4, 2025
0e5af2b
Merge branch 'main' into 607-fix-namespace-embedding-in-file
ehennestad Feb 4, 2025
40f5de3
Fix failing tests
ehennestad Feb 4, 2025
2505a98
Merge branch 'main' into update-tests-suppress-expected-warnings
ehennestad Feb 4, 2025
0d1128e
Merge branch 'main' into 607-fix-namespace-embedding-in-file
ehennestad Feb 4, 2025
225ebc0
Merge branch 'main' into 595-use-empty-indices-for-datastub
ehennestad Feb 4, 2025
c8572f9
Suppress more expected warnings and outputs
ehennestad Feb 4, 2025
ef5e8e5
Merge branch 'main' into update-tests-suppress-expected-warnings
ehennestad Feb 5, 2025
dc18c57
Merge branch 'main' into 607-fix-namespace-embedding-in-file
ehennestad Feb 5, 2025
47a3733
Add test
ehennestad Feb 10, 2025
ea8a408
Update test to test different data types
ehennestad Feb 10, 2025
d40a8b3
Make local function getEmptyRepresentation more explicit
ehennestad Feb 10, 2025
59a13c7
Remove unused code from test
ehennestad Feb 10, 2025
27bdaef
Merge branch 'main' into 595-use-empty-indices-for-datastub
ehennestad Feb 10, 2025
99c975b
Merge branch 'main' into 595-use-empty-indices-for-datastub
ehennestad Feb 10, 2025
c90df68
Merge branch 'main' into update-tests-suppress-expected-warnings
ehennestad Feb 10, 2025
8aac12b
Merge branch 'main' into 607-fix-namespace-embedding-in-file
ehennestad Feb 10, 2025
b477af8
Use shared fixture in WarningsTest
ehennestad Feb 11, 2025
78553bb
Merge branch '595-use-empty-indices-for-datastub' into update-tests-s…
ehennestad Feb 11, 2025
9613c9c
Update dataStubTest, include new test in test methods block
ehennestad Feb 11, 2025
d81564c
Merge branch '607-fix-namespace-embedding-in-file' into update-tests-…
ehennestad Feb 11, 2025
1f852f4
Add shared fixture to new test MustBeH5FileTest
ehennestad Feb 11, 2025
302a25d
Add abstract NwbTestCase class with utility methods that can be reused
ehennestad Feb 11, 2025
593ad63
Suppress output from various tests
ehennestad Feb 11, 2025
b901755
Fix failing test
ehennestad Feb 11, 2025
26ab33c
Merge branch 'main' into update-tests-suppress-expected-warnings
ehennestad Feb 11, 2025
0f78abd
Merge branch 'main' into update-tests-suppress-expected-warnings
ehennestad Feb 11, 2025
be18268
Merge branch 'main' into update-tests-suppress-expected-warnings
ehennestad Feb 12, 2025
b369205
Remove commented code block from ObjectView class
ehennestad Feb 12, 2025
45bdbb1
Merge branch 'update-tests-suppress-expected-warnings' of https://git…
ehennestad Feb 12, 2025
f35fe9d
Add utility method to NwbTestCase class
ehennestad Feb 12, 2025
a0baa19
Fix bug and add test
ehennestad Feb 15, 2025
9f66274
Add "version" as property to Namespace class
ehennestad Feb 16, 2025
ccfd763
Add routine for writing a function for retrieving version of generate…
ehennestad Feb 16, 2025
156e36e
Regenerate core with version numbers
ehennestad Feb 16, 2025
6282f4a
Update generateRstForNeurodataTypeClasses.m
ehennestad Feb 16, 2025
7e87d4c
Add version specificity to cache containing map of required properties
ehennestad Feb 16, 2025
ffac64d
Merge branch '668-bug-nwb-to-table' into update-tests-suppress-expect…
ehennestad Feb 16, 2025
2977a2a
Merge branch 'fix/required-property-cache-must-be-version-specific' i…
ehennestad Feb 16, 2025
cb3571d
Delete GenerateSpecificationMixin.m
ehennestad Feb 16, 2025
257743a
Split test class setup into methods with single responsibilities
ehennestad Feb 16, 2025
9433cb8
Add factory function to create NwbFile for unit testing
ehennestad Feb 16, 2025
72ccff3
Merge branch 'main' into update-tests-suppress-expected-warnings
ehennestad Feb 16, 2025
9387541
Merge branch 'main' into update-tests-suppress-expected-warnings
ehennestad Feb 17, 2025
923949d
Clean up nwbExport test
ehennestad Feb 18, 2025
68be31c
Clean up a few more test classes
ehennestad Feb 18, 2025
e095d4a
Add fixture for setting environment variables used in test suite and …
ehennestad Feb 19, 2025
bf8f937
Update PyNWBIOTest.m
ehennestad Feb 19, 2025
1ea9afc
Fix wrong shape of data in PhotonSeriesIOTest
ehennestad Feb 19, 2025
c72aada
Update PyNWBIOTest.py
ehennestad Feb 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions +tests/+abstract/NwbTestCase.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
classdef (Abstract, SharedTestFixtures = {tests.fixtures.GenerateCoreFixture}) ...
NwbTestCase < matlab.unittest.TestCase
% NwbTestCase - Abstract class providing a shared fixture, and utility
% methods for running tests dependent on generating neurodata type classes

methods (Access = protected)
function typesOutputFolder = getTypesOutputFolder(testCase)
F = testCase.getSharedTestFixtures();
isMatch = arrayfun(@(x) isa(x, 'tests.fixtures.GenerateCoreFixture'), F);
F = F(isMatch);

typesOutputFolder = F.TypesOutputFolder;
end

function installExtension(testCase, extensionName)
typesOutputFolder = testCase.getTypesOutputFolder();

% Use evalc to suppress output while running tests.
matlabExpression = sprintf(...
'nwbInstallExtension("%s", "savedir", "%s")', ...
extensionName, typesOutputFolder);
evalc(matlabExpression);
end

function clearExtension(testCase, extensionName)
extensionName = char(extensionName);
namespaceFolderName = strrep(extensionName, '-', '_');
typesOutputFolder = testCase.getTypesOutputFolder();
rmdir(fullfile(typesOutputFolder, '+types', ['+', namespaceFolderName]), 's')
delete(fullfile(typesOutputFolder, 'namespaces', [extensionName '.mat']))
end
end

methods (Static, Access = protected)
function [nwbFile, nwbFileCleanup] = readNwbFileWithPynwb(nwbFilename)
try
io = py.pynwb.NWBHDF5IO(nwbFilename);
nwbFile = io.read();
nwbFileCleanup = onCleanup(@(x) closePyNwbObject(io));
catch ME
error(ME.message)
end

function closePyNwbObject(io)
io.close()
end
end

function nwbFilename = getRandomFilename()
% Assumes that this method is called from a test method
functionCallStackTrace = dbstack();
testName = regexp(functionCallStackTrace(2).name, '\w*$', 'match', 'once');
nwbFilename = sprintf('%s_%05d.nwb', testName, randi(9999));
end
end
end
11 changes: 11 additions & 0 deletions +tests/+factory/ImagingPlane.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function imaging_plane = ImagingPlane(device)
% ImagingPlane - Create imaging plane with values for all required properties
arguments
device (1,1) types.core.Device % A device is required
end
imaging_plane = types.core.ImagingPlane( ...
'device', types.untyped.SoftLink(device), ...
'excitation_lambda', 600., ...
'indicator', 'GFP', ...
'location', 'my favorite brain location');
end
9 changes: 9 additions & 0 deletions +tests/+factory/NWBFile.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function nwb = NWBFile()
currentTime = datetime("now", 'TimeZone', 'local');

nwb = NwbFile( ...
'session_description', 'NWB File with required properties for unit testing', ...
'identifier', 'test_file', ...
'session_start_time', currentTime, ...
'timestamps_reference_time', currentTime);
end
6 changes: 6 additions & 0 deletions +tests/+factory/TimeSeriesWithTimestamps.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function timeSeries = TimeSeriesWithTimestamps()
timeSeries = types.core.TimeSeries(...
'data', rand(1,10), ...
'timestamps', 1:10, ...
'data_unit', 'test');
end
55 changes: 55 additions & 0 deletions +tests/+fixtures/ExtensionGenerationFixture.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
classdef ExtensionGenerationFixture < matlab.unittest.fixtures.Fixture
%EXTENSIONGENERATIONFIXTURE - Fixture for generating an NWB extension.
%
% EXTENSIONGENERATIONFIXTURE provides a fixture for generating extension code
% from an NWB specification's namespace file. When the testing framework
% sets up the fixture, it calls the generateExtension function to produce the
% necessary code in the specified output folder. When the framework tears down
% the fixture, it removes the generated files and associated cache data,
% ensuring that no artifacts remain from the test generation process.
%
% See also matlab.unittest.fixtures.Fixture generateExtension nwbClearGenerated

properties
% TypesOutputFolder - Folder to output generated types for test
% classes that share this fixture
TypesOutputFolder (1,1) string

% NamespaceFilepath - Path name for extension's namespace file
NamespaceFilepath (1,1) string
end

methods
function fixture = ExtensionGenerationFixture(namespaceFilepath, outputFolder)
fixture.NamespaceFilepath = namespaceFilepath;
fixture.TypesOutputFolder = outputFolder;
end
end

methods
function setup(fixture)
generateExtension(fixture.NamespaceFilepath, 'savedir', fixture.TypesOutputFolder);
fixture.addTeardown(@fixture.clearGenerated)
end
end

methods (Access = protected)
function tf = isCompatible(fixtureA, fixtureB)
tf = strcmp(fixtureA.NamespaceFilepath, fixtureB.NamespaceFilepath) ...
&& strcmp(fixtureA.TypesOutputFolder, fixtureB.TypesOutputFolder);
end
end

methods (Access = private)
function clearGenerated(fixture)
[~, namespaceFilename] = fileparts(fixture.NamespaceFilepath);
namespaceName = extractBefore(namespaceFilename, '.');

generatedTypesDirectory = fullfile(fixture.TypesOutputFolder, "+types", "+"+namespaceName);
rmdir(generatedTypesDirectory, 's');

cacheFile = fullfile(fixture.TypesOutputFolder, "namespaces", namespaceName+".mat");
delete(cacheFile)
end
end
end
44 changes: 44 additions & 0 deletions +tests/+fixtures/GenerateCoreFixture.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
classdef GenerateCoreFixture < matlab.unittest.fixtures.Fixture
% GENERATECOREFIXTURE - Fixture for creating classes for NWB types in a temporary folder.
%
% GENERATECOREFIXTURE provides a fixture for generating classes for neurodata
% types from the from the core NWB specifications. When the testing framework
% sets up the fixture, it calls the generateCore function to produce the
% necessary code in a temporary output folder and add it to MATLAB's path. When
% the framework tears down the fixture, it clears all the classes and deletes
% the temporary folder, ensuring that no artifacts remain from the test process.
%
% See also matlab.unittest.fixtures.Fixture generateCore
properties
% TypesOutputFolder - Folder to output generated types for test
% classes that share this fixture
TypesOutputFolder (1,1) string
end

methods
function setup(fixture)
import matlab.unittest.fixtures.PathFixture
import matlab.unittest.fixtures.TemporaryFolderFixture
import tests.fixtures.NwbClearGeneratedFixture

% Use the NwbClearGeneratedFixture to clear all generated types
% from the MatNWB root directory in order to preventing path
% conflicts when generating new types in a temporary directory
fixture.applyFixture( NwbClearGeneratedFixture )

% Use a fixture to add the MatNWB folder to the search path
fixture.applyFixture( PathFixture( misc.getMatnwbDir() ) );

% Use a fixture to create a temporary working directory
F = fixture.applyFixture( TemporaryFolderFixture );

% Generate core types in the temporary folder and add to path
generateCore('savedir', F.Folder)
fixture.applyFixture( PathFixture(F.Folder) );

% Save the folder containing cached namespaces and NWB type classes
% on the fixture object
fixture.TypesOutputFolder = F.Folder;
end
end
end
38 changes: 38 additions & 0 deletions +tests/+fixtures/NwbClearGeneratedFixture.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
classdef NwbClearGeneratedFixture < matlab.unittest.fixtures.Fixture
% NwbClearGeneratedFixture - Fixture for clearing generated NWB classes.
%
% NwbClearGeneratedFixture provides a fixture for clearing all the
% generated classes for NWB types from the matnwb folder. When the fixture is
% set up, all generated class files for NWB types are deleted. When the
% fixture is torn down, generateCore is called to regenerate the classes for
% NWB types of the latest NWB version
%
% See also matlab.unittest.fixtures.Fixture generateCore nwbClearGenerated

properties
TypesOutputFolder (1,1) string {mustBeFolder} = misc.getMatnwbDir
end

methods
function fixture = NwbClearGeneratedFixture(outputFolder)
arguments
outputFolder (1,1) string {mustBeFolder} = misc.getMatnwbDir
end
fixture.TypesOutputFolder = outputFolder;
end
end

methods
function setup(fixture)
fixture.addTeardown( ...
@() generateCore('savedir', fixture.TypesOutputFolder) )
nwbClearGenerated(fixture.TypesOutputFolder)
end
end

methods (Access = protected)
function tf = isCompatible(fixtureA, fixtureB)
tf = strcmp(fixtureA.TypesOutputFolder, fixtureB.TypesOutputFolder);
end
end
end
16 changes: 0 additions & 16 deletions +tests/+fixtures/ResetGeneratedTypesFixture.m

This file was deleted.

83 changes: 83 additions & 0 deletions +tests/+fixtures/SetEnvironmentVariableFixture.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
classdef SetEnvironmentVariableFixture < matlab.unittest.fixtures.Fixture
% UsesEnvironmentVariable Fixture for setting environment variables in tests.
%
% This fixture reads an environment file containing key-value pairs and
% sets the corresponding system environment variables prior to executing
% tests. The expected format for the environment file is:
%
% VARIABLE_NAME=VALUE
%
% Lines that are empty or start with '#' (comments) are ignored.
%
% The fixture first attempts to load environment variables from the file
% "nwbtest.env" located in the "+tests" folder. If "nwbtest.env" is not
% found, it falls back to "nwbtest.default.env". When using the default file,
% the fixture only applies environment variables if they are not present
% in the current list of environment variables.

methods
function setup(fixture) %#ok<MANU>

applyFromFile = true;
envFilePath = fullfile(misc.getMatnwbDir, '+tests', 'nwbtest.env');

if ~isfile(envFilePath)
envFilePath = fullfile(misc.getMatnwbDir, '+tests', 'nwbtest.default.env');
applyFromFile = false;
end

if exist("loadenv", "file") == 2
envVariables = loadenv(envFilePath);
else
envVariables = readEnvFile(envFilePath);
end

envVariableNames = string( envVariables.keys() );
if ~isrow(envVariableNames); envVariableNames = envVariableNames'; end

for varName = envVariableNames
varValue = envVariables(varName);
if ~isenv(varName)
setenv(varName, varValue)
elseif applyFromFile && ~isempty(char(varValue))
setenv(varName, varValue)
end
end
end
end
end

function envMap = readEnvFile(filename)
% readEnvFile Reads an environment file into a containers.Map.
%
% envMap = readEnvFile(filename) reads the file specified by 'filename'
% and returns a containers.Map where each key is a variable name and each
% value is the corresponding value from the file.
%
% Lines starting with '#' or empty lines are ignored.

envMap = containers.Map;

fileContent = fileread(filename);
lines = strsplit(fileContent, newline);

for i = 1:numel(lines)
line = lines{i};
if isempty(line) || startsWith(line, '#')
continue;
end

% Find the first occurrence of '='
idx = strfind(line, '=');
if isempty(idx)
continue; % ignore line
end

% Use the first '=' as the delimiter
key = strtrim(line(1:idx(1)-1));
value = strtrim(line(idx(1)+1:end));

% Insert the key-value pair into the map
envMap(key) = value;
end
end
16 changes: 10 additions & 6 deletions +tests/+sanity/GenerationTest.m
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
classdef GenerationTest < matlab.unittest.TestCase
% Note: Sometimes this test does not work for the first two schema versions.
% Restarting MATLAB can fix this.

properties (MethodSetupParameter)
schemaVersion = listSchemaVersions()
end

methods (TestClassSetup)
function setupClass(testCase)
function setupMatNWBPathFixture(testCase)
import matlab.unittest.fixtures.PathFixture
import tests.fixtures.ResetGeneratedTypesFixture

rootPath = tests.util.getProjectDirectory();
testCase.applyFixture( PathFixture(rootPath) );
matNwbRootPath = tests.util.getProjectDirectory();
testCase.applyFixture( PathFixture(matNwbRootPath) );
end

testCase.applyFixture( ResetGeneratedTypesFixture );
function setupNwbClearGeneratedFixture(testCase)
import tests.fixtures.NwbClearGeneratedFixture
testCase.applyFixture( NwbClearGeneratedFixture );
end
end

Expand Down
Loading