Skip to content

Commit 93d7641

Browse files
authored
Merge pull request #98 from mathworks/add_tests
Adding tests to address task #92
2 parents 367ecfb + 5fb09b1 commit 93d7641

File tree

5 files changed

+58
-12
lines changed

5 files changed

+58
-12
lines changed

.github/workflows/test_setup.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- main
77
- fix_tests
88
- krisfed-patch-1
9+
- add_tests
910

1011
jobs:
1112
test:
3.54 KB
Binary file not shown.

test/tZarrCreate.m

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
% Copyright 2025 The MathWorks, Inc.
55

66
methods(Test)
7-
87
function createIntermediateZgroups(testcase)
98
% Verify that zarrcreate creates zarr groups when given a
109
% nested path
11-
1210
arrayPath = fullfile(testcase.ArrPathWrite, "A", "B");
1311
zarrcreate(arrayPath, testcase.ArrSize);
1412
[groupPath, ~, ~] = fileparts(arrayPath);
@@ -19,12 +17,27 @@ function createIntermediateZgroups(testcase)
1917
grpInfo = zarrinfo(groupPath);
2018
expFormat = '2';
2119
expType = 'group';
22-
20+
2321
testcase.verifyEqual(grpInfo.zarr_format, expFormat,...
2422
"Unexpected Zarr group format");
2523
testcase.verifyEqual(grpInfo.node_type, expType,...
2624
"Unexpected Zarr group node type");
25+
end
2726

27+
function createArrayRelativePath(testcase)
28+
% Verify that the array is successfully created if a relative
29+
% path is used.
30+
newDir = 'myFolder';
31+
currDir = pwd;
32+
mkdir(newDir);
33+
testcase.addTeardown(@()cd(currDir));
34+
35+
cd(newDir);
36+
inpPath = fullfile('..','myGrp','myArr');
37+
zarrcreate(inpPath,[10 10]);
38+
arrInfo = zarrinfo(inpPath);
39+
testcase.verifyEqual(arrInfo.zarr_format,2,'Failed to Zarr array format');
40+
testcase.verifyEqual(arrInfo.node_type,'array','Unexpected Zarr array node type');
2841
end
2942

3043
function invalidFilePath(testcase)
@@ -42,6 +55,14 @@ function invalidFilePath(testcase)
4255

4356
% Non-text input
4457
testcase.verifyError(@()zarrcreate([],testcase.ArrSize),errID);
58+
59+
% Invalid bucket path
60+
errID = 'MATLAB:Zarr:invalidS3URL';
61+
inpPath = 'https://invalid/arr/path';
62+
testcase.verifyError(@()zarrcreate(inpPath,[10 10]),errID);
63+
64+
inpPath = 'http://invalid/arr/path';
65+
testcase.verifyError(@()zarrcreate(inpPath,[10 10]),errID);
4566
end
4667

4768
function pathContainingInvalidChars(testcase)
@@ -60,7 +81,7 @@ function chunkSizeGreaterThanArraySize(testcase)
6081
testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,testcase.ArrSize, ...
6182
'ChunkSize',chunkSize),errID);
6283
end
63-
84+
6485
function chunkSizeMismatch(testcase)
6586
% Verify error when there is a mismatch between Array size and
6687
% Chunk size.
@@ -72,7 +93,7 @@ function chunkSizeMismatch(testcase)
7293
end
7394

7495
function invalidClevelBlosc(testcase)
75-
% Verify error when an invalid clevel value is used with blosc
96+
% Verify error when an invalid clevel value is used with blosc
7697
% compression. Valid values are [0 9], where 0 is for no compression.
7798
comp.id = 'blosc';
7899
level = {-1,10,NaN};
@@ -87,7 +108,7 @@ function invalidClevelBlosc(testcase)
87108
end
88109

89110
function invalidBlockSizeBlosc(testcase)
90-
% Verify error when an invalid blocksize value is used with blosc
111+
% Verify error when an invalid blocksize value is used with blosc
91112
% compression. Valid values for blocksize are [0 inf].
92113
comp.id = 'blosc';
93114
comp.level = 5;
@@ -103,7 +124,7 @@ function invalidBlockSizeBlosc(testcase)
103124
end
104125

105126
function invalidCnameBlosc(testcase)
106-
% Verify error when an invalid cname value is used with blosc
127+
% Verify error when an invalid cname value is used with blosc
107128
% compression.
108129
comp.id = 'blosc';
109130
comp.level = 5;
@@ -161,7 +182,6 @@ function invalidSizeInput(testcase)
161182
% testcase.PyException);
162183
end
163184

164-
165185
function invalidDatatype(testcase)
166186
% Verify the error when an usupported datatype is used.
167187
testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,...
@@ -184,8 +204,8 @@ function invalidCompressionInputType(testcase)
184204
end
185205

186206
function invalidCompressionMember(testcase)
187-
% Verify error when additional compression members (cname, blocksize,
188-
% and shuffle) are used. These members are not supported for
207+
% Verify error when additional compression members (cname, blocksize,
208+
% and shuffle) are used. These members are not supported for
189209
% compression other than blosc.
190210
compType = {'gzip','zlib','bz2','zstd'};
191211
comp.level = 5;
@@ -206,7 +226,7 @@ function zlibInvalidCompressionLevel(testcase)
206226
errID = 'MATLAB:Zarr:missingCompressionID';
207227
testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,testcase.ArrSize, ...
208228
'Compression',comp),errID);
209-
229+
210230
comp.id = 'zlib';
211231
comp.level = -1;
212232
testcase.verifyError(@()zarrcreate(testcase.ArrPathWrite,testcase.ArrSize, ...
@@ -273,7 +293,7 @@ function zstdInvalidCompressionLevel(testcase)
273293
end
274294

275295
function tooFewInputs(testcase)
276-
% Verify error when too few inputs are passed to the zarrcreate
296+
% Verify error when too few inputs are passed to the zarrcreate
277297
% function.
278298
errID = 'MATLAB:minrhs';
279299
testcase.verifyError(@()zarrcreate(),errID);

test/tZarrInfo.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ function verifyGroupInfoV2(testcase)
3434
testcase.verifyEqual(actInfo,expInfo,'Failed to verify group info.');
3535
end
3636

37+
function getArrayInfoRelativePath(testcase)
38+
% Verify array info if the input is using relative path to the
39+
% array.
40+
inpPath = fullfile('..','test',testcase.ArrPathV2);
41+
actInfo = zarrinfo(inpPath);
42+
expInfo = testcase.ExpInfo.zarrV2ArrInfo;
43+
testcase.verifyEqual(actInfo, expInfo, ['Failed to verify array info ' ...
44+
'with relative path.']);
45+
end
46+
3747
function verifyArrayInfoV3(testcase)
3848
% Verify array info created with Zarr v3 format.
3949
actInfo = zarrinfo(testcase.ArrPathV3);

test/tZarrRead.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ function verifyArrayData(testcase)
2828
testcase.verifyEqual(actArrData,expArrData,'Failed to verify array data.');
2929
end
3030

31+
function verifyArrayDataRelativePath(testcase)
32+
% Verify array data if the input is using relative path to the
33+
% array.
34+
inpPath = fullfile('..','test',testcase.ArrPathRead);
35+
actArrData = zarrread(inpPath);
36+
expArrData = testcase.ExpData.arr_v2;
37+
testcase.verifyEqual(actArrData,expArrData,['Failed to verify array ' ...
38+
'data with relative path.']);
39+
end
40+
3141
function verifyGroupInpError(testcase)
3242
% Verify error if a user tries to pass the group as input to
3343
% zarrread function.
@@ -67,6 +77,11 @@ function invalidFilePath(testcase)
6777
% Empty char
6878
errID = 'MATLAB:validators:mustBeNonzeroLengthText';
6979
testcase.verifyError(@()zarrread(''),errID);
80+
81+
% Non-existent bucket
82+
inpPath = 's3://invalid/bucket/path';
83+
errID = 'MATLAB:Zarr:invalidZarrObject';
84+
testcase.verifyError(@()zarrread(inpPath),errID);
7085
end
7186
end
7287
end

0 commit comments

Comments
 (0)