Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

test(io): generate PNG/JPEG fixtures locally instead of downloading (#4843)

Harsh Raj Singhania9c39a1096aa2
diff --git a/tests/io/test_io_image.py b/tests/io/test_io_image.py
index 253551ff9..24c02b35f 100644
--- a/tests/io/test_io_image.py
+++ b/tests/io/test_io_image.py
@@ -17,7 +17,6 @@
import io
from pathlib import Path
-from urllib.request import urlopen
import kornia_rs
import numpy as np
@@ -35,26 +34,13 @@ def create_random_img8_torch(height: int, width: int, channels: int, device=None
return (torch.rand(channels, height, width, device=device) * 255).to(torch.uint8)
-def _download_image(url: str, filename: str = "") -> Path:
- # TODO: move this to testing
-
- filename = url.rsplit("/", maxsplit=1)[-1] if len(filename) == 0 else filename
- # Download
- # url is a fixed https:// literal defined by each fixture above.
- with urlopen(url, timeout=60) as resp: # noqa: S310
- bytesio = io.BytesIO(resp.read())
- # Save file
- with open(filename, "wb") as outfile:
- outfile.write(bytesio.getbuffer())
-
- return Path(filename)
-
-
@pytest.fixture(scope="session")
def png_image(tmp_path_factory):
- url = "https://github.com/kornia/data/raw/main/simba.png"
+ """RGB PNG written locally so load tests do not depend on the network."""
filename = tmp_path_factory.mktemp("data") / "image.png"
- return _download_image(url, str(filename))
+ img_rgb = np.random.randint(0, 255, (32, 32, 3), dtype=np.uint8) # noqa: NPY002
+ kornia_rs.io.write_image_png_u8(str(filename), img_rgb, mode="rgb")
+ return filename
@pytest.fixture(scope="session")
@@ -68,9 +54,10 @@ def rgba_png_image(tmp_path_factory):
@pytest.fixture(scope="session")
def jpg_image(tmp_path_factory):
- url = "https://github.com/kornia/data/raw/main/crowd.jpg"
+ """RGB JPEG written locally so load tests do not depend on the network."""
filename = tmp_path_factory.mktemp("data") / "image.jpg"
- return _download_image(url, str(filename))
+ write_image(str(filename), create_random_img8_torch(32, 32, 3))
+ return filename
@pytest.fixture(scope="session")