-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from chris-delg/testing
Testing
- Loading branch information
Showing
12 changed files
with
326 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.DS_Store | ||
__pycache__/ | ||
.pytest_cache | ||
.vscode/ | ||
example_data/ | ||
build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# needed so that pytest can identify this layer as the root layer of the project (will throw errors if deleted) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ dependencies: | |
- ome-zarr | ||
- zarr=2.15* | ||
- pip: | ||
- pytest | ||
- cmake | ||
- ml-dtypes | ||
- tensorstore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from benchmark import Benchmark | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def benchmark() -> Benchmark: | ||
shape = [256, 256, 256] | ||
chunks = [64, 64, 64] | ||
benchmark = Benchmark(shape=shape, chunks=chunks) | ||
|
||
return benchmark | ||
|
||
|
||
def test_benchmark_get_shape(benchmark: Benchmark): | ||
assert benchmark.shape == [256, 256, 256] | ||
|
||
|
||
def test_benchmark_get_chunks(benchmark: Benchmark): | ||
assert benchmark.chunks == [64, 64, 64] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("lib_name"), | ||
[ | ||
(""), | ||
("."), | ||
(" ") | ||
] | ||
) | ||
def test_if_incorrect_lib_name_in_write_tests_fails(benchmark: Benchmark, lib_name: str): | ||
with pytest.raises(ValueError): | ||
benchmark.run_write_tests(num_of_gigabytes=1, show_results=False, choose_lib=lib_name) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("lib_name"), | ||
[ | ||
(""), | ||
("."), | ||
(" ") | ||
] | ||
) | ||
def test_if_incorrect_lib_name_in_append_tests_fails(benchmark: Benchmark, lib_name: str): | ||
with pytest.raises(ValueError): | ||
benchmark.run_append_tests(num_of_gigabytes=1, show_results=False, choose_lib=lib_name) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("lib_name"), | ||
[ | ||
(""), | ||
("."), | ||
(" ") | ||
] | ||
) | ||
def test_if_incorrect_lib_name_in_run_all_tests_fails(benchmark: Benchmark, lib_name: str): | ||
with pytest.raises(ValueError): | ||
benchmark.run_all_tests(append_test_gigabytes=1, write_test_gigabytes=1, choose_lib=lib_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from zarr_libraries.common import folder_size_in_bytes, formatted_folder_size | ||
import os | ||
import pytest | ||
from tempfile import TemporaryDirectory | ||
|
||
|
||
@pytest.fixture | ||
def temp_dir(): | ||
with TemporaryDirectory() as temp_dir: | ||
yield temp_dir | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("num_mb"), | ||
[ | ||
(1), | ||
(10), | ||
(50), | ||
(100), | ||
(500), | ||
(750) | ||
] | ||
) | ||
def test_folder_size_in_bytes(temp_dir, num_mb: int): | ||
mb_in_bytes = 1048576 | ||
MBs = num_mb * mb_in_bytes | ||
|
||
# creating a test file of size variable size | ||
with open(temp_dir + "/test.bin", "wb") as f: | ||
f.write(os.urandom(MBs)) | ||
|
||
# custom tolerance of 4096 bytes which is about 0.00390625 MB's | ||
assert abs(folder_size_in_bytes(temp_dir) - MBs) <= 4096 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("num_mb"), | ||
[ | ||
(1), | ||
(10), | ||
(50), | ||
(100), | ||
(500), | ||
(750) | ||
] | ||
) | ||
def test_formatted_folder_size(temp_dir, num_mb: int): | ||
mb_in_bytes = 1048576 | ||
MBs = num_mb * mb_in_bytes | ||
|
||
# creating a test file of size variable size | ||
with open(temp_dir + "/test.bin", "wb") as f: | ||
f.write(os.urandom(MBs)) | ||
|
||
# checking if the formatted size w/o the decimal values is equal to expected | ||
assert formatted_folder_size(temp_dir).split(".")[0] == str(num_mb) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from zarr_libraries.cpp_zarr.cpp_zarr import * | ||
from zarr_libraries.common import folder_size_in_bytes | ||
from pathlib import Path | ||
import shutil | ||
import numpy as np | ||
import pytest | ||
|
||
|
||
def test_getting_data_path_from_cpp_zarr(): | ||
cpp_zarr = Cpp_Zarr() | ||
|
||
expected_path = str((Path(__file__).parent / "../zarr_libraries/example_data/cpp_zarr_data/test.zarr").resolve()) | ||
assert cpp_zarr.data_path == expected_path | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("shape", "chunks"), | ||
[ | ||
([256, 256, 256], [64, 64, 64]), | ||
([64, 128, 256], [32, 64, 64]), | ||
] | ||
) | ||
def test_cpp_zarr_writes_correct_amount_of_data(shape: list, chunks: list): | ||
cpp_zarr = Cpp_Zarr() | ||
|
||
cpp_zarr.write_zarr(shape=shape, chunks=chunks) | ||
expected_size = np.prod(shape) | ||
|
||
# the actual size can be larger but can never be smaller that expected size | ||
assert folder_size_in_bytes(cpp_zarr.data_path) >= expected_size | ||
shutil.rmtree(cpp_zarr.data_path) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from zarr_libraries.ome_ngff.ome_zarr import Ome_Zarr | ||
from zarr_libraries.common import folder_size_in_bytes | ||
from pathlib import Path | ||
import numpy as np | ||
import shutil | ||
import pytest | ||
|
||
|
||
def test_getting_data_path_from_ome_zarr(): | ||
ome_zarr = Ome_Zarr() | ||
|
||
expected_path = str((Path(__file__).parent / "../zarr_libraries/example_data/ome_zarr_data/test.zarr").resolve()) | ||
assert ome_zarr.data_path == expected_path | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("shape", "chunks"), | ||
[ | ||
([256, 256, 256], [64, 64, 64]), | ||
([64, 128, 256], [32, 64, 64]), | ||
] | ||
) | ||
def test_ome_zarr_writes_correct_amount_of_data(shape: list, chunks: list): | ||
ome_zarr = Ome_Zarr() | ||
|
||
zarr_data = np.random.randint(low=0, high=256, size=shape, dtype=np.uint8) | ||
ome_zarr.write_zarr(chunks=chunks, zarr_data=zarr_data) | ||
expected_size = np.prod(shape) | ||
|
||
# the actual size can be larger but can never be smaller that expected size | ||
assert folder_size_in_bytes(ome_zarr.data_path) >= expected_size | ||
shutil.rmtree(ome_zarr.data_path) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from zarr_libraries.tensorstore.tensorstore_zarr import Tensorstore | ||
from zarr_libraries.common import folder_size_in_bytes | ||
from pathlib import Path | ||
import shutil | ||
import numpy as np | ||
import pytest | ||
|
||
|
||
def test_getting_data_path_from_tensorstore(): | ||
tensorstore = Tensorstore() | ||
|
||
expected_path = str((Path(__file__).parent / "../zarr_libraries/example_data/tensorstore_data/test.zarr").resolve()) | ||
assert tensorstore.data_path == expected_path | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("shape", "chunks"), | ||
[ | ||
([256, 256, 256], [64, 64, 64]), | ||
([64, 128, 256], [32, 64, 64]), | ||
] | ||
) | ||
def test_tensorstore_writes_correct_amount_of_data(shape: list, chunks: list): | ||
tensorstore = Tensorstore() | ||
|
||
zarr_data = np.random.randint(low=0, high=256, size=shape, dtype=np.uint8) | ||
tensorstore.write_zarr(shape=shape, chunks=chunks, zarr_data=zarr_data) | ||
expected_size = np.prod(shape) | ||
|
||
# the actual size can be larger but can never be smaller that expected size | ||
assert folder_size_in_bytes(tensorstore.data_path) >= expected_size | ||
shutil.rmtree(tensorstore.data_path) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("shape", "chunks"), | ||
[ | ||
([256, 256, 256], [64, 64, 64]), | ||
([64, 128, 256], [32, 64, 64]), | ||
] | ||
) | ||
def test_zarr_python_append_writes_correct_amount_of_data(shape: list, chunks: list): | ||
tensorstore = Tensorstore() | ||
|
||
zarr_data = np.random.randint(low=0, high=256, size=shape, dtype=np.uint8) | ||
tensorstore.append_zarr(shape=shape, chunks=chunks, new_shape=shape, zarr_data=zarr_data, multiplier=1) | ||
expected_size = np.prod(shape) | ||
|
||
# checking the size of the first append | ||
assert folder_size_in_bytes(tensorstore.data_path) >= expected_size | ||
|
||
new_shape = [shape[0] * (2), *shape[1:]] | ||
new_data = np.random.randint(low=0, high=256, size=shape, dtype=np.uint8) | ||
tensorstore.append_zarr(shape=shape, chunks=chunks, new_shape=new_shape, zarr_data=new_data, multiplier=2) | ||
expected_size = np.prod(new_shape) | ||
|
||
# changing the shape and comparing the expected size after the second append | ||
assert folder_size_in_bytes(tensorstore.data_path) >= expected_size | ||
shutil.rmtree(tensorstore.data_path) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from zarr_libraries.zarr_python.zarr_python import Zarr_Python | ||
from zarr_libraries.common import folder_size_in_bytes | ||
from pathlib import Path | ||
import shutil | ||
import numpy as np | ||
import pytest | ||
|
||
|
||
def test_getting_data_path_from_zarr_python(): | ||
zarr_python = Zarr_Python() | ||
|
||
expected_path = str((Path(__file__).parent / "../zarr_libraries/example_data/zarr_python_data/test.zarr").resolve()) | ||
assert zarr_python.data_path == expected_path | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("shape", "chunks"), | ||
[ | ||
([256, 256, 256], [64, 64, 64]), | ||
([64, 128, 256], [32, 64, 64]), | ||
] | ||
) | ||
def test_zarr_python_writes_correct_amount_of_data(shape: list, chunks: list): | ||
zarr_python = Zarr_Python() | ||
|
||
zarr_data = np.random.randint(low=0, high=256, size=shape, dtype=np.uint8) | ||
zarr_python.write_zarr(shape=shape, chunks=chunks, zarr_data=zarr_data) | ||
expected_size = np.prod(shape) | ||
|
||
# the actual size can be larger but can never be smaller that expected size | ||
assert folder_size_in_bytes(zarr_python.data_path) >= expected_size | ||
shutil.rmtree(zarr_python.data_path) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("shape", "chunks"), | ||
[ | ||
([256, 256, 256], [64, 64, 64]), | ||
([64, 128, 256], [32, 64, 64]), | ||
] | ||
) | ||
def test_zarr_python_append_writes_correct_amount_of_data(shape: list, chunks: list): | ||
zarr_python = Zarr_Python() | ||
|
||
zarr_data = np.random.randint(low=0, high=256, size=shape, dtype=np.uint8) | ||
zarr_python.append_zarr(shape=shape, chunks=chunks, zarr_data=zarr_data) | ||
expected_size = np.prod(shape) | ||
|
||
# checking the size of the first append | ||
assert folder_size_in_bytes(zarr_python.data_path) >= expected_size | ||
|
||
new_shape = [shape[0] * (2), *shape[1:]] | ||
new_data = np.random.randint(low=0, high=256, size=shape, dtype=np.uint8) | ||
zarr_python.append_zarr(shape=shape, chunks=chunks, zarr_data=new_data) | ||
expected_size = np.prod(new_shape) | ||
|
||
# changing the shape and comparing the expected size after the second append | ||
assert folder_size_in_bytes(zarr_python.data_path) >= expected_size | ||
shutil.rmtree(zarr_python.data_path) |
Oops, something went wrong.