From 52031a463fa0897e4727dc69cac7712b9c4e43d7 Mon Sep 17 00:00:00 2001 From: Shubhdildeep Singh Sohal Date: Thu, 1 May 2025 12:00:06 -0400 Subject: [PATCH] Updated tests with new error IDs --- .github/workflows/test_setup.yml | 1 + test/SharedZarrTestSetup.m | 5 ++++ test/tZarrAttributes.m | 33 +++++++++++++++++++++----- test/tZarrCreate.m | 40 +++++++++++++++++++------------- test/tZarrInfo.m | 4 +--- test/tZarrWrite.m | 40 ++++++++++++++++++++++++++++---- 6 files changed, 94 insertions(+), 29 deletions(-) diff --git a/.github/workflows/test_setup.yml b/.github/workflows/test_setup.yml index 68ce784..c883bbb 100644 --- a/.github/workflows/test_setup.yml +++ b/.github/workflows/test_setup.yml @@ -5,6 +5,7 @@ on: branches: - main - branch-bug + - update-test-branch jobs: test: diff --git a/test/SharedZarrTestSetup.m b/test/SharedZarrTestSetup.m index 6b9f9be..594a604 100644 --- a/test/SharedZarrTestSetup.m +++ b/test/SharedZarrTestSetup.m @@ -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); end end end \ No newline at end of file diff --git a/test/tZarrAttributes.m b/test/tZarrAttributes.m index b8e1941..7d022a2 100644 --- a/test/tZarrAttributes.m +++ b/test/tZarrAttributes.m @@ -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) @@ -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. diff --git a/test/tZarrCreate.m b/test/tZarrCreate.m index 7ad14e6..93f14a8 100644 --- a/test/tZarrCreate.m +++ b/test/tZarrCreate.m @@ -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) @@ -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, ... @@ -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'; + errID = 'MATLAB:zarrcreate:invalidCompression'; + testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,testcase.ArrSize, ... + 'Compression',comp),errID); end function invalidCompressionMember(testcase) @@ -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, ... diff --git a/test/tZarrInfo.m b/test/tZarrInfo.m index 3ec6684..7a2c94b 100644 --- a/test/tZarrInfo.m +++ b/test/tZarrInfo.m @@ -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 diff --git a/test/tZarrWrite.m b/test/tZarrWrite.m index 6428207..ef484bd 100644 --- a/test/tZarrWrite.m +++ b/test/tZarrWrite.m @@ -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.'); + 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'}; @@ -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.'); + end + end + + function tooFewInputs(testcase) % Verify error when too few inputs to zarrwrite are passed. errID = 'MATLAB:minrhs'; @@ -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);