From 8030def67f90b59b226d60e251968362912a13cd Mon Sep 17 00:00:00 2001 From: Erik O Gabrielsson Date: Thu, 10 Oct 2024 16:24:27 +0200 Subject: [PATCH] Tests for ndpi one frame image --- .github/workflows/pytests.yaml | 6 +++--- tests/test_ndpi_tiler.py | 25 ++++++++++++++++++++++++- tests/test_turbojpeg_patch.py | 10 +++++++--- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pytests.yaml b/.github/workflows/pytests.yaml index dd4e067..eb945c6 100644 --- a/.github/workflows/pytests.yaml +++ b/.github/workflows/pytests.yaml @@ -62,13 +62,13 @@ jobs: run: sudo apt-get install -y libturbojpeg - name: Set up libjpegturbo OSX if: matrix.os == 'macos-latest' - run: brew install jpeg-turbo + run: brew unlink jpeg-turbo && brew install jpeg-turbo --HEAD - name: Set up libjpegturbo Windows shell: pwsh if: matrix.os == 'windows-latest' run: | - Invoke-WebRequest -Uri https://sourceforge.net/projects/libjpeg-turbo/files/2.1.4/libjpeg-turbo-2.1.4-vc64.exe/download -OutFile libjpeg-turbo-2.1.4-vc64.exe -UserAgent "NativeHost" - 7z e libjpeg-turbo-2.1.4-vc64.exe -oC:\turbojpeg bin/turbojpeg.dll + Invoke-WebRequest -Uri https://github.com/libjpeg-turbo/libjpeg-turbo/releases/download/3.0.90/libjpeg-turbo-3.0.90-vc64.exe -OutFile libjpeg-turbo-3.0.90-vc64.exe -UserAgent "NativeHost" + 7z e libjpeg-turbo-3.0.90-vc64.exe -oC:\turbojpeg bin/turbojpeg.dll - name: Set up paths in windows if: matrix.os == 'windows-latest' uses: actions/github-script@v7 diff --git a/tests/test_ndpi_tiler.py b/tests/test_ndpi_tiler.py index e1afd9f..7423c45 100644 --- a/tests/test_ndpi_tiler.py +++ b/tests/test_ndpi_tiler.py @@ -20,7 +20,7 @@ from tifffile import PHOTOMETRIC from opentile.formats import NdpiTiler -from opentile.formats.ndpi.ndpi_image import NdpiStripedImage +from opentile.formats.ndpi.ndpi_image import NdpiStripedImage, NdpiOneFrameImage from opentile.formats.ndpi.ndpi_tile import NdpiFrameJob, NdpiTile from opentile.geometry import Point, Size from opentile.tiff_image import TiffImage @@ -46,6 +46,11 @@ def level(tiler: NdpiTiler): yield tiler.get_level(0) +@pytest.fixture() +def one_frame_level(tiler: NdpiTiler): + yield tiler.get_level(3) + + @pytest.mark.unittest class TestNdpiTiler: @pytest.mark.parametrize( @@ -117,6 +122,24 @@ def test_get_tile( # Assert assert md5(tile).hexdigest() == hash + @pytest.mark.parametrize( + ["tile_point", "hash"], + [ + ((0, 0), "170165575a3e9cc564e7ac18d5520f1b"), + ((1, 1), "4a48dc3f72584170497e793d44a2372d"), + ], + ) + def test_get_tile_one_frame_level( + self, one_frame_level: NdpiOneFrameImage, tile_point: Tuple[int, int], hash: str + ): + # Arrange + + # Act + tile = one_frame_level.get_tile(tile_point) + + # Assert + assert md5(tile).hexdigest() == hash + @pytest.mark.parametrize( ["tile_points", "hashes"], [ diff --git a/tests/test_turbojpeg_patch.py b/tests/test_turbojpeg_patch.py index fa7339f..9f9da31 100644 --- a/tests/test_turbojpeg_patch.py +++ b/tests/test_turbojpeg_patch.py @@ -14,6 +14,7 @@ from ctypes import c_short, pointer from io import BufferedReader +from typing import Tuple import numpy as np import pytest from turbojpeg import ( @@ -117,16 +118,19 @@ def test_crop_multiple_compare(self, jpeg: TurboJPEG_patch, buffer: bytes): # Assert assert single_crops == multiple_crops - def test_crop_multiple_extend(self, jpeg: TurboJPEG_patch, buffer: bytes): + @pytest.mark.parametrize("size", [(1024, 512), (1024, 1024)]) + def test_crop_multiple_extend( + self, jpeg: TurboJPEG_patch, buffer: bytes, size: Tuple[int, int] + ): # Arrange - crop_parameters = [(0, 0, 1024, 1024)] + crop_parameters = [(0, 0, size[0], size[1])] # Act crop = jpeg.crop_multiple(buffer, crop_parameters)[0] # Assert width, height, _, _ = jpeg.decode_header(crop) - assert (1024, 1024) == (width, height) + assert size == (width, height) def test_fill_background(self): # Arrange