|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import os |
| 4 | +import platform |
4 | 5 | import shutil |
5 | 6 | import string |
6 | 7 | from contextlib import contextmanager |
|
22 | 23 |
|
23 | 24 | from iohub.ngff.nodes import ( |
24 | 25 | TO_DICT_SETTINGS, |
| 26 | + NGFFNode, |
25 | 27 | Plate, |
26 | 28 | TransformationMeta, |
| 29 | + _case_insensitive_local_fs, |
27 | 30 | _open_store, |
28 | 31 | _pad_shape, |
29 | 32 | open_ome_zarr, |
@@ -150,6 +153,19 @@ def test_open_store_read_nonexist(): |
150 | 153 | _ = _open_store(store_path, mode=mode, version="0.4") |
151 | 154 |
|
152 | 155 |
|
| 156 | +def test_case_insensitive_local_fs(): |
| 157 | + """Test `iohub.ngff._case_insensitive_local_fs()`""" |
| 158 | + match platform.system(): |
| 159 | + case "Windows": |
| 160 | + assert _case_insensitive_local_fs() is True |
| 161 | + case "Darwin": |
| 162 | + assert _case_insensitive_local_fs() is True |
| 163 | + case "Linux": |
| 164 | + assert _case_insensitive_local_fs() is False |
| 165 | + case _: |
| 166 | + _ = _case_insensitive_local_fs() |
| 167 | + |
| 168 | + |
153 | 169 | @given(channel_names=channel_names_st) |
154 | 170 | @settings(max_examples=16) |
155 | 171 | def test_init_ome_zarr(channel_names): |
@@ -920,6 +936,20 @@ def test_get_axis_index(): |
920 | 936 | _ = position.get_axis_index("DOG") |
921 | 937 |
|
922 | 938 |
|
| 939 | +def test_ngff_node_contains_cross_platform(caplog): |
| 940 | + """Test `iohub.ngff.NGFFNode.__contains__()` on multiple platforms.""" |
| 941 | + with open_ome_zarr(hcs_ref, layout="hcs", mode="r") as dataset: |
| 942 | + assert "B" in dataset |
| 943 | + match platform.system(): |
| 944 | + case "Linux": |
| 945 | + assert "b" not in dataset |
| 946 | + case "Windows" | "Darwin": |
| 947 | + assert "b" in dataset |
| 948 | + assert any( |
| 949 | + "Key 'b' matched" in r.message for r in caplog.records |
| 950 | + ) |
| 951 | + |
| 952 | + |
923 | 953 | @given( |
924 | 954 | row=short_alpha_numeric, col=short_alpha_numeric, pos=short_alpha_numeric |
925 | 955 | ) |
@@ -963,6 +993,34 @@ def test_create_well(row_names: list[str], col_names: list[str]): |
963 | 993 | ] == row_names |
964 | 994 |
|
965 | 995 |
|
| 996 | +def test_create_case_sensitive_well(tmp_path): |
| 997 | + """Test `iohub.ngff.Plate.create_well()` with case-sensitive names.""" |
| 998 | + store_path = tmp_path / "hcs.zarr" |
| 999 | + with open_ome_zarr( |
| 1000 | + store_path, layout="hcs", mode="w-", channel_names=["1", "2"] |
| 1001 | + ) as dataset: |
| 1002 | + well = dataset.create_well("A", "B") |
| 1003 | + fov = well.create_position("0") |
| 1004 | + fov.create_zeros("0", shape=(1, 2, 3, 4, 5), dtype=int) |
| 1005 | + match platform.system(): |
| 1006 | + case "Windows" | "Darwin": |
| 1007 | + with pytest.raises(FileExistsError): |
| 1008 | + dataset.create_well("a", "B") |
| 1009 | + with pytest.raises(FileExistsError): |
| 1010 | + dataset.create_well("A", "b") |
| 1011 | + new_well = dataset.create_well("a", "1") |
| 1012 | + expected_rows = 1 |
| 1013 | + case "Linux": |
| 1014 | + new_well = dataset.create_well("a", "b") |
| 1015 | + expected_rows = 2 |
| 1016 | + new_fov = new_well.create_position("0") |
| 1017 | + new_fov.create_zeros("0", shape=(1, 2, 3, 4, 5), dtype=int) |
| 1018 | + with open_ome_zarr(store_path) as dataset: |
| 1019 | + assert len(dataset.metadata.rows) == expected_rows |
| 1020 | + assert len(list(dataset.rows())) == expected_rows |
| 1021 | + assert len(dataset.metadata.columns) == 2 |
| 1022 | + |
| 1023 | + |
966 | 1024 | @given( |
967 | 1025 | row=short_alpha_numeric, col=short_alpha_numeric, pos=short_alpha_numeric |
968 | 1026 | ) |
|
0 commit comments