Skip to content

Updated tests with new error IDs #74

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

Merged
merged 1 commit into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/test_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
- branch-bug
- update-test-branch

jobs:
test:
Expand Down
5 changes: 5 additions & 0 deletions test/SharedZarrTestSetup.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ function addSrcCodePath(testcase)

function setupWorkingFolderToCreateArr(testcase)
% Use working folder fixture to create Zarr array.
currDir = pwd;

import matlab.unittest.fixtures.WorkingFolderFixture;
testcase.applyFixture(WorkingFolderFixture);

% Add the existing files to the current folder
copyfile(fullfile(currDir,'dataFiles'),pwd);
Copy link
Member

Choose a reason for hiding this comment

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

Where does this get get cleaned?

Copy link
Member Author

Choose a reason for hiding this comment

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

end
end
end
33 changes: 27 additions & 6 deletions test/tZarrAttributes.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ function verifyGroupAttributeInfo(testcase)
end

function verifyZarrV3WriteError(testcase)
% Verify error when a user tries to write attribute to zarr v3
% file.
testcase.assumeTrue(false,'Filtered until the right error message is thrown.');
filePath = 'dataFiles/grp_v3/arr_v3';
testcase.verifyError(@()zarrwriteatt(filePath,'myAttr','attrVal'), ...
testcase.PyException);
% Verify error when a user tries to write attribute to zarr v3 file.
filePath = 'grp_v3/arr_v3';
errID = 'MATLAB:zarrwriteatt:writeAttV3';
testcase.verifyError(@()zarrwriteatt(filePath,'myAttr','attrVal'),errID);
end

function nonExistentFile(testcase)
Expand All @@ -76,6 +74,29 @@ function nonExistentFile(testcase)
'MATLAB:validators:mustBeFolder');
end

function notZarrObject(testcase)
% Verify error when a user tries to write attributes to an
% invalid Zarr object.
errID = 'MATLAB:zarrwriteatt:invalidZarrObject';
folderPath = fullfile('my_grp','my_arr');
mkdir(folderPath);
testcase.verifyError(@()zarrwriteatt(folderPath,'myAttr','attrVal'), ...
errID);
end

function noWritePermissions(testcase)
% Verify error if there are no write permissions to the Zarr array.
testcase.assumeTrue(false,'Filtered until the error syntax is fixed.');

% Make the folder read-only.
fileattrib(testcase.ArrPathWrite,'-w','','s');
testcase.addTeardown(@()fileattrib(testcase.ArrPathWrite,'+w','','s'));

errID = 'MATLAB:zarrwriteatt:fileOpenFailure';
testcase.verifyError(@()zarrwriteatt(testcase.ArrPathWrite,'myAttr','attrVal'), ...
errID);
end

function tooManyInputs(testcase)
% Verify error when too many inputs are used with zarrwrite
% function.
Expand Down
40 changes: 24 additions & 16 deletions test/tZarrCreate.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@ function invalidFilePath(testcase)
testcase.verifyError(@()zarrcreate([],testcase.ArrSize),errID);
end

% function pathContainingInvalidChars(testcase)
% % Verify error when the array or group name contains
% % unsupported characters.
% TOCHECK: Failure on Linux
% testcase.verifyError(@()zarrcreate('grp*/arr',testcase.ArrSize),testcase.PyException);
% testcase.verifyError(@()zarrcreate('grp/arr*',testcase.ArrSize),testcase.PyException);
% end
function pathContainingInvalidChars(testcase)
% Verify error when the array or group name contains
% unsupported characters.
testcase.assumeTrue(ispc,'Filtered on other platforms');
testcase.verifyError(@()zarrcreate('grp*/arr',testcase.ArrSize),testcase.PyException);
testcase.verifyError(@()zarrcreate('grp/arr*',testcase.ArrSize),testcase.PyException);
end

function chunkSizeGreaterThanArraySize(testcase)
% Verify error when the chunk size is greater than the array
% size.
testcase.assumeTrue(false,'Filtered until the issue is fixed.');
errID = 'MATLAB:zarrcreate:chunkSizeGreater';
chunkSize = [30 35];
testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,testcase.ArrSize, ...
'ChunkSize',chunkSize),testcase.PyException);
'ChunkSize',chunkSize),errID);
end

function chunkSizeMismatch(testcase)
% Verify error when there is a mismatch between Array size and
% Chunk size.
testcase.assumeTrue(false,'Filtered until issue 25 is fixed.');
arrSize = [10 12 5];
chunkSize = [4 5];
errID = 'MATLAB:zarrcreate:chunkDimsMismatch';
testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,arrSize, ...
'ChunkSize',chunkSize),testcase.PyException);
'ChunkSize',chunkSize),errID);
end

function invalidClevelBlosc(testcase)
Expand Down Expand Up @@ -124,8 +124,6 @@ function invalidChunkSize(testcase)

function invalidFillValue(testcase)
% Verify error when an invalid type for the fill value is used.
% testcase.verifyError(@()zarrcreate(testcase.FilePath,testcase.ArrSize, ...
% "FillValue",[]),testcase.PyException);
testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,testcase.ArrSize, ...
"FillValue",[-9 -9]),testcase.PyException);
% testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,testcase.ArrSize, ...
Expand All @@ -138,15 +136,20 @@ function invalidSizeInput(testcase)
% Verify error when an invalid size input is used.
% testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,[]), ...
% testcase.PyException);

end

function invalidCompressionInputType(testcase)
% Verify error when an invalid compression value is used.
testcase.assumeTrue(false,'Filtered until the issue is fixed.');
%testcase.assumeTrue(false,'Filtered until the issue is fixed.');
comp.id = 'random';
errID = 'MATLAB:Zarr:invalidCompressionID';
testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,testcase.ArrSize, ...
'Compression',comp),testcase.PyException);
'Compression',comp),errID);

comp = 'zlib';
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment here for this test?

errID = 'MATLAB:zarrcreate:invalidCompression';
testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,testcase.ArrSize, ...
'Compression',comp),errID);
end

function invalidCompressionMember(testcase)
Expand All @@ -168,6 +171,11 @@ function invalidCompressionMember(testcase)
function zlibInvalidCompressionLevel(testcase)
% Verify error when an invalid compression level is used.
% For zlib, valid values are [0 9]
comp.level = 5;
errID = 'MATLAB:Zarr:missingCompressionID';
testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,testcase.ArrSize, ...
'Compression',comp),errID);

comp.id = 'zlib';
comp.level = -1;
testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,testcase.ArrSize, ...
Expand Down
4 changes: 1 addition & 3 deletions test/tZarrInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ function verifyGroupInfoV3(testcase)
function missingZgroupFile(testcase)
% Verify error when using zarrinfo function on a group not
% containing .zgroup file.
testcase.assumeTrue(false,'Filtered until error ID is added.');

import matlab.unittest.fixtures.WorkingFolderFixture;
testcase.applyFixture(WorkingFolderFixture);

zarrcreate('prt_grp_write/arr1',[10 10]);
grpPath = 'prt_grp_write/';
errID = '';
errID = 'MATLAB:zarrinfo:invalidZarrObject';
testcase.verifyError(@()zarrinfo(grpPath),errID);
end

Expand Down
40 changes: 36 additions & 4 deletions test/tZarrWrite.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,23 @@ function createArrayRemoteUserDefinedSyntax(testcase)
% Move to a separate file
end

function createArrayWithBlosc(testcase)
function createArrayWithDefaultBloscConfig(testcase)
% Verify data when creating and writing to a Zarr array using
% blosc compression.
% a default blosc compression configuration.
comp.id = 'blosc';
expData = randn(testcase.ArrSize);

zarrcreate(testcase.ArrPathWrite,testcase.ArrSize,'ChunkSize', ...
testcase.ChunkSize,'Compression',comp);
zarrwrite(testcase.ArrPathWrite,expData);

actData = zarrread(testcase.ArrPathWrite);
testcase.verifyEqual(actData,expData,'Failed to verify data.');
Copy link
Member

Choose a reason for hiding this comment

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

Should we also test if the correct compression was used (using zarrinfo)?

end

function createArrayWithCustomBloscConfig(testcase)
% Verify data when creating and writing to a Zarr array using
% custom blosc compression configuration.
comp.id = 'blosc';
comp.clevel = 5;
cname = {'blosclz','lz4','lz4hc','zlib','zstd','snappy'};
Expand All @@ -79,6 +93,25 @@ function createArrayWithBlosc(testcase)
end
end

function createArrayWithDefaultCompConfig(testcase)
% Verify data when creating and writing to a Zarr array using
% a default compression (other than Blosc) configuration.
compType = {'zlib','gzip','bz2','zstd'};
expData = randn(testcase.ArrSize);

for i = 1:length(compType)
comp.id = compType{i};

zarrcreate(testcase.ArrPathWrite,testcase.ArrSize,'ChunkSize', ...
testcase.ChunkSize,'Compression',comp);
zarrwrite(testcase.ArrPathWrite,expData);

actData = zarrread(testcase.ArrPathWrite);
testcase.verifyEqual(actData,expData,'Failed to verify data.');
Copy link
Member

Choose a reason for hiding this comment

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

Should we also test if the correct compression was used (using zarrinfo)?

end
end


function tooFewInputs(testcase)
% Verify error when too few inputs to zarrwrite are passed.
errID = 'MATLAB:minrhs';
Expand All @@ -105,8 +138,7 @@ function invalidFilePath(testcase)
function dataDimensionMismatch(testcase)
% Verify error when there is a dimension mismatch at the time of
% writing to the array.
testcase.assumeTrue(false,'Filtered until error ID is added.');
errID = '';
errID = 'MATLAB:Zarr:sizeMismatch';
zarrcreate(testcase.ArrPathWrite,testcase.ArrSize);
data = ones(30,30);
testcase.verifyError(@()zarrwrite(testcase.ArrPathWrite,data),errID);
Expand Down