Skip to content

Adding tests v1 #50

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 11 commits into from
Apr 21, 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
46 changes: 46 additions & 0 deletions .github/workflows/test_setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test setup and measure coverage

on:
push:
branches:
- main
- add-test-branch

jobs:
test:
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-14]

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up MATLAB R2024a
uses: matlab-actions/setup-matlab@v2
with:
release: R2024a

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11.9'

- name: Install additional 3p dependencies
run: |
python -m pip install --upgrade pip
pip install numpy==1.26.4 tensorstore==0.1.73

- name: Run tests
uses: matlab-actions/run-tests@v2
with:
select-by-folder: 'test'
code-coverage-cobertura: cobertura.xml

- name: Upload codecov
uses: codecov/codecov-action@v4
with:
token: ${{secrets.CODECOV_TOKEN}}
files: ./target/site/cobertura/coverage.xml
name: codecov-umbrella.xml
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coverage:
status:
project:
default:
target: 85%
threshold: 5%
ignore:
- "test/*"
28 changes: 28 additions & 0 deletions test/SharedZarrTestSetup.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
classdef SharedZarrTestSetup < matlab.unittest.TestCase
% Shared test set up for Zarr tests.

% Copyright 2025 The MathWorks, Inc.

properties
PyException = "MATLAB:Python:PyException"
ArrSize = [20 25]
ChunkSize = [4 5]

% Path for write tests
ArrPathWrite = "prt_grp_write/arr1"
end

methods(TestClassSetup)
function addSrcCodePath(testcase)
% Add source code path before running the tests
import matlab.unittest.fixtures.PathFixture
testcase.applyFixture(PathFixture(fullfile('..'),'IncludeSubfolders',true))
end

function setupWorkingFolderToCreateArr(testcase)
% Use working folder fixture to create Zarr array.
import matlab.unittest.fixtures.WorkingFolderFixture;
testcase.applyFixture(WorkingFolderFixture);
end
end
end
13 changes: 13 additions & 0 deletions test/dataFiles/create_zarr_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Create Zarr v2 array

import zarr
import numpy as np
store = zarr.DirectoryStore('grp_v2')
group = zarr.group(store=store,overwrite=True)
group.attrs['group_description'] = 'This is a sample Zarr group'
group.attrs['group_level'] = 1
array = group.create_dataset('arr_v2',shape=(20,25),dtype=np.float32,chunks=(2,5),fillvalue=-9)
array.attrs['array_description'] = 'This is a sample Zarr array'
array.attrs['array_type'] = 'double'
array.attrs['array_level'] = 1
array[:] = np.random.rand(20,25)
13 changes: 13 additions & 0 deletions test/dataFiles/create_zarr_v3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Create Zarr v3 array

import zarr
import numpy as np
store = zarr.storage.LocalStore('grp_v3')
group = zarr.group(store=store,overwrite=True)
group.attrs['group_description'] = 'This is a sample Zarr group'
group.attrs['group_level'] = 1
array = group.create_array('arr_v3',shape=(20,25),dtype=np.float32,chunks=(2,5),fill_value=-9)
array.attrs['array_description'] = 'This is a sample Zarr array'
array.attrs['array_type'] = 'double'
array.attrs['array_level'] = 1
array[:] = np.random.rand(20,25)
Binary file added test/dataFiles/expZarrArrData.mat
Binary file not shown.
Binary file added test/dataFiles/expZarrArrInfo.mat
Binary file not shown.
4 changes: 4 additions & 0 deletions test/dataFiles/grp_v2/.zattrs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"group_description": "This is a sample Zarr group",
"group_level": 1
}
3 changes: 3 additions & 0 deletions test/dataFiles/grp_v2/.zgroup
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"zarr_format": 2
}
1 change: 1 addition & 0 deletions test/dataFiles/grp_v2/arr_v2/.zarray
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"chunks":[2,5],"compressor":{"blocksize":0,"clevel":5,"cname":"lz4","id":"blosc","shuffle":1},"dtype":"<f4","fill_value":-9,"filters":[],"order":"C","shape":[20,25],"zarr_format":2,"Attr1":"var"}
5 changes: 5 additions & 0 deletions test/dataFiles/grp_v2/arr_v2/.zattrs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"array_description": "This is a sample Zarr array",
"array_level": 1,
"array_type": "double"
}
Binary file added test/dataFiles/grp_v2/arr_v2/0.0
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/0.1
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/0.2
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/0.3
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/0.4
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/1.0
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/1.1
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/1.2
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/1.3
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/1.4
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/2.0
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/2.1
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/2.2
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/2.3
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/2.4
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/3.0
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/3.1
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/3.2
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/3.3
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/3.4
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/4.0
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/4.1
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/4.2
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/4.3
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/4.4
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/5.0
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/5.1
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/5.2
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/5.3
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/5.4
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/6.0
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/6.1
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/6.2
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/6.3
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/6.4
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/7.0
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/7.1
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/7.2
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/7.3
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/7.4
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/8.0
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/8.1
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/8.2
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/8.3
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/8.4
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/9.0
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/9.1
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/9.2
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/9.3
Binary file not shown.
Binary file added test/dataFiles/grp_v2/arr_v2/9.4
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/0/0
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/0/1
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/0/2
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/0/3
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/0/4
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/1/0
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/1/1
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/1/2
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/1/3
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/1/4
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/2/0
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/2/1
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/2/2
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/2/3
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/2/4
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/3/0
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/3/1
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/3/2
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/3/3
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/3/4
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/4/0
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/4/1
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/4/2
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/4/3
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/4/4
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/5/0
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/5/1
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/5/2
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/5/3
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/5/4
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/6/0
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/6/1
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/6/2
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/6/3
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/6/4
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/7/0
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/7/1
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/7/2
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/7/3
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/7/4
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/8/0
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/8/1
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/8/2
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/8/3
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/8/4
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/9/0
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/9/1
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/9/2
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/9/3
Binary file not shown.
Binary file added test/dataFiles/grp_v3/arr_v3/c/9/4
Binary file not shown.
46 changes: 46 additions & 0 deletions test/dataFiles/grp_v3/arr_v3/zarr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"shape": [
20,
25
],
"data_type": "float32",
"chunk_grid": {
"name": "regular",
"configuration": {
"chunk_shape": [
2,
5
]
}
},
"chunk_key_encoding": {
"name": "default",
"configuration": {
"separator": "/"
}
},
"fill_value": -9.0,
"codecs": [
{
"name": "bytes",
"configuration": {
"endian": "little"
}
},
{
"name": "zstd",
"configuration": {
"level": 0,
"checksum": false
}
}
],
"attributes": {
"array_description": "This is a sample Zarr array",
"array_type": "double",
"array_level": 1
},
"zarr_format": 3,
"node_type": "array",
"storage_transformers": []
}
9 changes: 9 additions & 0 deletions test/dataFiles/grp_v3/zarr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"attributes": {
"group_description": "This is a sample Zarr group",
"group_level": 1
},
"zarr_format": 3,
"consolidated_metadata": null,
"node_type": "group"
}
108 changes: 108 additions & 0 deletions test/tZarrAttributes.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
classdef tZarrAttributes < SharedZarrTestSetup
% Tests for zarrwriteatt function to get attribute info of the Zarr file in MATLAB.

% Copyright 2025 The MathWorks, Inc.

methods(TestClassSetup)
function createZarrArrayWithAttrs(testcase)
% Create Zarr array and add some attributes.
zarrcreate(testcase.ArrPathWrite,testcase.ArrSize);
zarrwriteatt(testcase.ArrPathWrite,'attr1','This is an array attribute.');
zarrwriteatt(testcase.ArrPathWrite,'attr2',{1,2,3});
attr3.numVal = 10;
attr3.strArr = ["array","attribute"];
zarrwriteatt(testcase.ArrPathWrite,'attr3',attr3);
end
end

methods(Test)
function verifyArrayAttributeInfo(testcase)
% Write attribute info using zarrwriteatt function to an array.

arrInfo = zarrinfo(testcase.ArrPathWrite);
actAttr.attr1 = arrInfo.attr1;

% TODO: Enable code once Issue-34 is fixed.
%actAttr.attr2 = arrInfo.attr2;
%actAttr.attr3 = arrInfo.attr3;

expAttr.attr1 = 'This is an array attribute.';
%expAttr.attr2 = {1,2,3};
%expAttr.attr3.numVal = 10;
%expAttr.attr4.strArr = ["array","attribute"];

testcase.verifyEqual(actAttr,expAttr,'Failed to verify attribute info.');
end

function verifyAttrOverwrite(testcase)
% Verify attribute value after overwrite.
%testcase.assumeTrue(false,'Filtered until the attributes display is fixed.');
expAttrStr = ["new","attribute","value"];
zarrwriteatt(testcase.ArrPathWrite,'attr1',expAttrStr);
expAttrDbl = 10;
zarrwriteatt(testcase.ArrPathWrite,'attr2',expAttrDbl);

arrInfo = zarrinfo(testcase.ArrPathWrite);

% TODO: Enable code once Issue-34 is fixed.
%actAttrStr = arrInfo.attr1;
actAttrDbl = arrInfo.attr2;

%testcase.verifyEqual(actAttrStr,expAttrStr,'Failed to verify string attribute info');
testcase.verifyEqual(actAttrDbl,expAttrDbl,'Failed to verify double attribute info');
end

function verifyGroupAttributeInfo(testcase)
% Write attribute info using zarrwriteatt function to a group.
testcase.assumeTrue(false,'Filtered until Issue-35 is fixed.');

% Unable to read attribute data from a group/array created
% using Python.
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);
end

function nonExistentFile(testcase)
% Verify error when using a non-existent file with zarrwriteatt
% function.
testcase.verifyError(@()zarrwriteatt('testFile/nonExistentArr','myAttr','attrVal'), ...
'MATLAB:validators:mustBeFolder');
end

function tooManyInputs(testcase)
% Verify error when too many inputs are used with zarrwrite
% function.
testcase.verifyError(@()zarrwriteatt(testcase.ArrPathWrite,'myAttr','attrVal','extra'), ...
'MATLAB:TooManyInputs');
end

function tooFewInputs(testcase)
% Verify error when too few inputs with zarrwriteatt function
% are used.
testcase.verifyError(@()zarrwriteatt(testcase.ArrPathWrite,'myAttr'), ...
'MATLAB:minrhs');
end

function invalidInput(testcase)
% Verify error when invalid input is used for zarrwriteatt
% function.
errID = 'MATLAB:validators:mustBeFolder';

% Invalid file path type
testcase.verifyError(@()zarrwriteatt('nonexistent','myAttr',10),errID);

% Invalid attribute name
errID = 'MATLAB:validators:mustBeNonzeroLengthText';
testcase.verifyError(@()zarrwriteatt(testcase.ArrPathWrite,'',10),errID);
errID = 'MATLAB:validators:mustBeTextScalar';
testcase.verifyError(@()zarrwriteatt(testcase.ArrPathWrite,10,10),errID);
end
end
end
Loading
Loading