Skip to content

Commit

Permalink
Tests for ndpi one frame image
Browse files Browse the repository at this point in the history
  • Loading branch information
erikogabrielsson committed Oct 10, 2024
1 parent 4386f93 commit 8030def
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pytests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion tests/test_ndpi_tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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"],
[
Expand Down
10 changes: 7 additions & 3 deletions tests/test_turbojpeg_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8030def

Please sign in to comment.