Skip to content

Commit 2c53ffd

Browse files
committed
add more tests for accessor
1 parent f63b6d8 commit 2c53ffd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/unit/test_accessor.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from mdio import MDIOReader
1111
from mdio.core.exceptions import MDIOAlreadyExistsError
1212
from mdio.core.exceptions import MDIONotFoundError
13+
from mdio.exceptions import ShapeError
1314
from mdio.segy.helpers_segy import create_zarr_hierarchy
1415

1516

@@ -21,6 +22,13 @@ def test_basic_attrs(self, mock_reader, mock_data):
2122
assert mock_reader.n_dim == mock_data.ndim
2223
assert mock_reader.trace_count == np.prod(mock_data.shape[:-1])
2324

25+
def test_basic_stats(self, mock_reader, mock_data):
26+
"""Ensure access to stats work properly."""
27+
assert mock_reader.stats["mean"] == mock_data.mean()
28+
assert mock_reader.stats["std"] == mock_data.std()
29+
assert mock_reader.stats["min"] == mock_data.min()
30+
assert mock_reader.stats["max"] == mock_data.max()
31+
2432
def test_text_hdr(self, mock_reader, mock_text):
2533
"""Compare ingested text header to original."""
2634
assert mock_reader.text_header == mock_text
@@ -65,6 +73,16 @@ def test_coord_slicing(
6573
xl_indices = mock_reader.coord_to_index(xl_coord, dimensions="crossline")
6674
z_indices = mock_reader.coord_to_index(z_coord, dimensions="sample")
6775

76+
# 2-D should work too
77+
_ = mock_reader.coord_to_index(
78+
il_coord,
79+
xl_coord,
80+
dimensions=["inline", "crossline"],
81+
)
82+
83+
# All dims should also work without specifying
84+
_ = mock_reader.coord_to_index(il_coord, xl_coord, z_coord)
85+
6886
il_indices = np.atleast_1d(il_indices)
6987
il_index = np.atleast_1d(il_index)
7088
xl_indices = np.atleast_1d(xl_indices)
@@ -102,6 +120,16 @@ def test_mdio_not_found(self) -> None:
102120
with pytest.raises(MDIONotFoundError):
103121
MDIOReader("prefix/file_that_doesnt_exist.mdio")
104122

123+
def test_wrong_size_index(self, mock_reader: MDIOReader) -> None:
124+
"""If user asks for N dimensions but didn't specify all."""
125+
with pytest.raises(ShapeError):
126+
mock_reader.coord_to_index(0, 0, dimensions="inline")
127+
128+
def test_wrong_index(self, mock_reader: MDIOReader) -> None:
129+
"""If user asks for an index that doesn't exist."""
130+
with pytest.raises(ValueError):
131+
mock_reader.coord_to_index(0, dimensions="non_existent")
132+
105133
def test_mdio_exists(self, mock_reader: MDIOReader) -> None:
106134
"""MDIO doesn't exist or corrupt."""
107135
mock_store = mock_reader.store

0 commit comments

Comments
 (0)