Skip to content

Commit 6af000e

Browse files
authored
Add Python tests (#35)
1 parent 5987b80 commit 6af000e

File tree

6 files changed

+92
-18
lines changed

6 files changed

+92
-18
lines changed

.github/workflows/test-python.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Test Python
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
lint-test:
11+
name: Lint and Test
12+
runs-on: ubuntu-latest
13+
defaults:
14+
run:
15+
working-directory: python
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Install Rust
20+
uses: dtolnay/rust-toolchain@stable
21+
with:
22+
components: rustfmt, clippy
23+
24+
- uses: Swatinem/rust-cache@v2
25+
26+
- name: Cargo fmt
27+
run: cargo fmt --all -- --check
28+
29+
- name: "clippy --all"
30+
run: cargo clippy --all --all-features --tests -- -D warnings
31+
32+
- name: "cargo check"
33+
run: cargo check --all --all-features
34+
35+
- name: "cargo test"
36+
run: |
37+
cargo test --all
38+
cargo test --all --all-features
39+
40+
pytest:
41+
name: Pytest
42+
runs-on: ubuntu-latest
43+
strategy:
44+
matrix:
45+
python-version: ["3.9", "3.10", "3.11", "3.12"]
46+
steps:
47+
- uses: actions/checkout@v4
48+
- name: Install Rust
49+
uses: dtolnay/rust-toolchain@stable
50+
with:
51+
components: rustfmt
52+
53+
- uses: Swatinem/rust-cache@v2
54+
- uses: actions/setup-python@v5
55+
with:
56+
python-version: ${{ matrix.python-version }}
57+
58+
- name: Install a specific version of uv
59+
uses: astral-sh/setup-uv@v3
60+
with:
61+
enable-cache: true
62+
version: "0.5.x"
63+
64+
- name: uv sync
65+
working-directory: python
66+
run: uv sync --no-install-package geoindex-rs
67+
68+
- name: maturin venv Build
69+
working-directory: python
70+
run: uv run --no-project maturin develop
71+
72+
# - name: Run pytest
73+
# working-directory: python
74+
# run: uv run --no-project pytest

python/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pyo3-async-runtimes = "0.23"
2626
pyo3-bytes = "0.1.2"
2727
pyo3-object_store = { git = "https://github.com/developmentseed/obstore", rev = "28ba07a621c1c104f084fb47ae7f8d08b1eae3ea" }
2828
thiserror = "1"
29-
tiff = "0.9.1"
3029

3130
# We opt-in to using rustls as the TLS provider for reqwest, which is the HTTP
3231
# library used by object_store.

python/python/async_tiff/_ifd.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ class ImageFileDirectory:
7575
@property
7676
def predictor(self) -> Predictor | None: ...
7777
@property
78-
def tile_width(self) -> int: ...
78+
def tile_width(self) -> int | None: ...
7979
@property
80-
def tile_height(self) -> int: ...
80+
def tile_height(self) -> int | None: ...
8181
@property
82-
def tile_offsets(self) -> list[int]: ...
82+
def tile_offsets(self) -> list[int] | None: ...
8383
@property
84-
def tile_byte_counts(self) -> list[int]: ...
84+
def tile_byte_counts(self) -> list[int] | None: ...
8585
@property
86-
def extra_samples(self) -> bytes | None: ...
86+
def extra_samples(self) -> list[int] | None: ...
8787
@property
8888
def sample_format(self) -> list[SampleFormat]: ...
8989
@property

python/src/decoder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use async_tiff::decoder::{Decoder, DecoderRegistry};
22
use async_tiff::error::AiocogeoError;
3+
use async_tiff::tiff::tags::PhotometricInterpretation;
34
use bytes::Bytes;
45
use pyo3::exceptions::PyTypeError;
56
use pyo3::intern;
@@ -53,7 +54,7 @@ impl Decoder for PyDecoder {
5354
fn decode_tile(
5455
&self,
5556
buffer: bytes::Bytes,
56-
_photometric_interpretation: tiff::tags::PhotometricInterpretation,
57+
_photometric_interpretation: PhotometricInterpretation,
5758
_jpeg_tables: Option<&[u8]>,
5859
) -> async_tiff::error::Result<bytes::Bytes> {
5960
let decoded_buffer = Python::with_gil(|py| self.call(py, buffer))

python/src/enums.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use pyo3::intern;
2-
use pyo3::prelude::*;
3-
use pyo3::types::{PyString, PyTuple};
4-
use tiff::tags::{
1+
use async_tiff::tiff::tags::{
52
CompressionMethod, PhotometricInterpretation, PlanarConfiguration, Predictor, ResolutionUnit,
63
SampleFormat,
74
};
5+
use pyo3::intern;
6+
use pyo3::prelude::*;
7+
use pyo3::types::{PyString, PyTuple};
88

99
pub(crate) struct PyCompressionMethod(CompressionMethod);
1010

python/src/ifd.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl PyImageFileDirectory {
5555
}
5656

5757
#[getter]
58-
pub fn strip_offsets(&self) -> Option<&[u32]> {
58+
pub fn strip_offsets(&self) -> Option<&[u64]> {
5959
self.0.strip_offsets()
6060
}
6161

@@ -80,7 +80,7 @@ impl PyImageFileDirectory {
8080
}
8181

8282
#[getter]
83-
pub fn strip_byte_counts(&self) -> Option<&[u32]> {
83+
pub fn strip_byte_counts(&self) -> Option<&[u64]> {
8484
self.0.strip_byte_counts()
8585
}
8686

@@ -162,25 +162,25 @@ impl PyImageFileDirectory {
162162
}
163163

164164
#[getter]
165-
pub fn tile_width(&self) -> u32 {
165+
pub fn tile_width(&self) -> Option<u32> {
166166
self.0.tile_width()
167167
}
168168
#[getter]
169-
pub fn tile_height(&self) -> u32 {
169+
pub fn tile_height(&self) -> Option<u32> {
170170
self.0.tile_height()
171171
}
172172

173173
#[getter]
174-
pub fn tile_offsets(&self) -> &[u32] {
174+
pub fn tile_offsets(&self) -> Option<&[u64]> {
175175
self.0.tile_offsets()
176176
}
177177
#[getter]
178-
pub fn tile_byte_counts(&self) -> &[u32] {
178+
pub fn tile_byte_counts(&self) -> Option<&[u64]> {
179179
self.0.tile_byte_counts()
180180
}
181181

182182
#[getter]
183-
pub fn extra_samples(&self) -> Option<&[u8]> {
183+
pub fn extra_samples(&self) -> Option<&[u16]> {
184184
self.0.extra_samples()
185185
}
186186

0 commit comments

Comments
 (0)