diff --git a/.github/workflows/test_setup.yml b/.github/workflows/test_setup.yml new file mode 100644 index 0000000..50d7b05 --- /dev/null +++ b/.github/workflows/test_setup.yml @@ -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 \ No newline at end of file diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..23a0e90 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,8 @@ +coverage: + status: + project: + default: + target: 85% + threshold: 5% +ignore: + - "test/*" \ No newline at end of file diff --git a/test/SharedZarrTestSetup.m b/test/SharedZarrTestSetup.m new file mode 100644 index 0000000..6b9f9be --- /dev/null +++ b/test/SharedZarrTestSetup.m @@ -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 \ No newline at end of file diff --git a/test/dataFiles/create_zarr_v2.py b/test/dataFiles/create_zarr_v2.py new file mode 100644 index 0000000..e460db0 --- /dev/null +++ b/test/dataFiles/create_zarr_v2.py @@ -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) diff --git a/test/dataFiles/create_zarr_v3.py b/test/dataFiles/create_zarr_v3.py new file mode 100644 index 0000000..b6de349 --- /dev/null +++ b/test/dataFiles/create_zarr_v3.py @@ -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) diff --git a/test/dataFiles/expZarrArrData.mat b/test/dataFiles/expZarrArrData.mat new file mode 100644 index 0000000..c0f81f8 Binary files /dev/null and b/test/dataFiles/expZarrArrData.mat differ diff --git a/test/dataFiles/expZarrArrInfo.mat b/test/dataFiles/expZarrArrInfo.mat new file mode 100644 index 0000000..3c091fc Binary files /dev/null and b/test/dataFiles/expZarrArrInfo.mat differ diff --git a/test/dataFiles/grp_v2/.zattrs b/test/dataFiles/grp_v2/.zattrs new file mode 100644 index 0000000..a87fc66 --- /dev/null +++ b/test/dataFiles/grp_v2/.zattrs @@ -0,0 +1,4 @@ +{ + "group_description": "This is a sample Zarr group", + "group_level": 1 +} \ No newline at end of file diff --git a/test/dataFiles/grp_v2/.zgroup b/test/dataFiles/grp_v2/.zgroup new file mode 100644 index 0000000..3b7daf2 --- /dev/null +++ b/test/dataFiles/grp_v2/.zgroup @@ -0,0 +1,3 @@ +{ + "zarr_format": 2 +} \ No newline at end of file diff --git a/test/dataFiles/grp_v2/arr_v2/.zarray b/test/dataFiles/grp_v2/arr_v2/.zarray new file mode 100644 index 0000000..7f5004e --- /dev/null +++ b/test/dataFiles/grp_v2/arr_v2/.zarray @@ -0,0 +1 @@ +{"chunks":[2,5],"compressor":{"blocksize":0,"clevel":5,"cname":"lz4","id":"blosc","shuffle":1},"dtype":"