Skip to content

Commit

Permalink
✅ Add unit test for CogReader's data method
Browse files Browse the repository at this point in the history
Ensure that the `.data()` method returns a numpy.ndarray output with the correct shape and values.
  • Loading branch information
weiji14 committed Mar 16, 2024
1 parent 2f43422 commit ec6d07a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/cog3pio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from importlib.metadata import version

from .cog3pio import read_geotiff, CogReader # noqa: F401
from .cog3pio import CogReader, read_geotiff # noqa: F401

__doc__ = cog3pio.__doc__
__version__ = version("cog3pio") # e.g. 0.1.2.dev3+g0ab3cd78
Expand Down
20 changes: 19 additions & 1 deletion python/tests/test_io_geotiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import tempfile
import urllib.request

import numpy as np
import pytest

from cog3pio import read_geotiff
from cog3pio import CogReader, read_geotiff


# %%
Expand Down Expand Up @@ -86,3 +87,20 @@ def test_read_geotiff_unsupported_dtype():
read_geotiff(
path="https://github.com/corteva/rioxarray/raw/0.15.1/test/test_data/input/cint16.tif"
)


def test_CogReader_data():
"""
Ensure that the CogReader class's `data` method produces a numpy.ndarray output.
"""
reader = CogReader(
path="https://github.com/rasterio/rasterio/raw/1.3.9/tests/data/float32.tif"
)
array = reader.data()
assert array.shape == (1, 2, 3) # band, height, width
np.testing.assert_equal(
actual=array,
desired=np.array(
[[[1.41, 1.23, 0.78], [0.32, -0.23, -1.88]]], dtype=np.float32
),
)

0 comments on commit ec6d07a

Please sign in to comment.