Skip to content

Commit 5daebd9

Browse files
authored
Enable pytest-asyncio tests in CI (#92)
* Set asyncio_mode="auto" in pytest.ini config Xref https://pytest-asyncio.readthedocs.io/en/latest/reference/configuration.html#asyncio-mode * Refactor contents of test_cog.py into a proper unit test Put everything in an `async def test_cog_s3` function, with assertions checking different metadata attributes. * Uncomment `uv run pytest` in .github/workflows/test-python.yml * Add `--color=yes`flag to force GitHub Actions logs to have color Xref pytest-dev/pytest#7443 * Ruff format * Remove timing assertions * Bump astral-sh/setup-uv from 3 to 6 Bumps [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv) from 3 to 6. - [Release notes](https://github.com/astral-sh/setup-uv/releases) - [Commits](astral-sh/setup-uv@v3...v6) * Remove `uv sync` part * Bump pytest-asyncio from 0.24.0 to 0.26.0 Bumps [pytest-asyncio](https://github.com/pytest-dev/pytest-asyncio) from 0.24.0 to 0.26.0. - [Release notes](https://github.com/pytest-dev/pytest-asyncio/releases) - [Commits](pytest-dev/pytest-asyncio@v0.24.0...v0.26.0) Also set asyncio_default_fixture_loop_scope="function" following pytest-dev/pytest-asyncio#924 (comment) * Revert "Remove `uv sync` part" This reverts commit 638d602. * Typo geoindex-rs -> async-tiff * Add back `--no-project` flag to `uv run` commands Partially undo bfb3a43
1 parent c720f01 commit 5daebd9

File tree

4 files changed

+37
-33
lines changed

4 files changed

+37
-33
lines changed

.github/workflows/test-python.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,18 @@ jobs:
5656
python-version: ${{ matrix.python-version }}
5757

5858
- name: Install a specific version of uv
59-
uses: astral-sh/setup-uv@v3
59+
uses: astral-sh/setup-uv@v6
6060
with:
61-
enable-cache: true
62-
version: "0.5.x"
61+
version: "latest"
6362

6463
- name: uv sync
6564
working-directory: python
66-
run: uv sync --no-install-package geoindex-rs
65+
run: uv sync --no-install-package async-tiff
6766

6867
- name: maturin venv Build
6968
working-directory: python
7069
run: uv run --no-project maturin develop
7170

72-
# - name: Run pytest
73-
# working-directory: python
74-
# run: uv run --no-project pytest
71+
- name: Run pytest
72+
working-directory: python
73+
run: uv run --no-project pytest --verbose

python/pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ dev-dependencies = [
3333
"numpy>=1",
3434
"obstore>=0.5.1",
3535
"pip>=24.2",
36-
"pytest-asyncio>=0.24.0",
36+
"pytest-asyncio>=0.26.0",
3737
"pytest>=8.3.3",
3838
"ruff>=0.8.4",
3939
]
40+
41+
[tool.pytest.ini_options]
42+
addopts = "--color=yes"
43+
asyncio_default_fixture_loop_scope="function"
44+
asyncio_mode = "auto"

python/tests/test_cog.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
import async_tiff
2-
from time import time
3-
from async_tiff import TIFF
1+
from async_tiff import TIFF, enums
42
from async_tiff.store import S3Store
53

6-
store = S3Store("sentinel-cogs", region="us-west-2", skip_signature=True)
7-
path = "sentinel-s2-l2a-cogs/12/S/UF/2022/6/S2B_12SUF_20220609_0_L2A/B04.tif"
84

9-
tiff = await TIFF.open(path, store=store, prefetch=32768)
5+
async def test_cog_s3():
6+
"""
7+
Ensure that TIFF.open can open a Sentinel-2 Cloud-Optimized GeoTIFF file from an
8+
s3 bucket, read IFDs and GeoKeyDirectory metadata.
9+
"""
10+
path = "sentinel-s2-l2a-cogs/12/S/UF/2022/6/S2B_12SUF_20220609_0_L2A/B04.tif"
11+
store = S3Store("sentinel-cogs", region="us-west-2", skip_signature=True)
12+
tiff = await TIFF.open(path=path, store=store, prefetch=32768)
1013

11-
start = time()
12-
tiff = await TIFF.open(path, store=store, prefetch=32768)
13-
end = time()
14-
end - start
14+
ifds = tiff.ifds
15+
assert len(ifds) == 5
1516

16-
ifds = tiff.ifds
17-
ifd = ifds[0]
18-
ifd.compression
19-
ifd.tile_height
20-
ifd.tile_width
21-
ifd.photometric_interpretation
22-
gkd = ifd.geo_key_directory
23-
gkd.citation
24-
gkd.projected_type
25-
gkd.citation
17+
ifd = ifds[0]
18+
assert ifd.compression == enums.CompressionMethod.Deflate
19+
assert ifd.tile_height == 1024
20+
assert ifd.tile_width == 1024
21+
assert ifd.photometric_interpretation == enums.PhotometricInterpretation.BlackIsZero
2622

27-
dir(gkd)
23+
gkd = ifd.geo_key_directory
24+
assert gkd.citation == "WGS 84 / UTM zone 12N"
25+
assert gkd.projected_type == 32612

python/uv.lock

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)