Scale / test_geometry.py
gokaygokay's picture
Replace captioner with Tile Upscaler v3
5cc434d verified
Raw History Blame Contribute Delete
1.32 kB
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import numpy as np
import pytest
from geometry import output_size, padded_size, tile_coordinates
@pytest.mark.parametrize('width,height', [(2048,2048),(2048,1365),(1024,683),(128,8),(1,1),(1,4096),(4096,1),(4096,4096)])
def test_tiles_cover_every_pixel_without_stretching(width, height):
pw, ph = padded_size(width, height)
coverage = np.zeros((ph // 8, pw // 8), dtype=np.uint8)
coords = tile_coordinates(ph // 8, pw // 8, 64, 64, 8)
assert coords
for y,x in coords:
assert x % 2 == y % 2 == 0
assert coverage[y:y+64,x:x+64].shape == (64,64)
coverage[y:y+64,x:x+64] += 1
assert coverage.min() > 0
@pytest.mark.parametrize('width,height,size,expected', [(683,1024,'2×',(1366,2048)),(1,2048,'2048 px long edge',(1,2048)),(100,75,'4096 px long edge',(4096,3072)),(128,8,'4×',(512,32))])
def test_exact_output_dimensions(width,height,size,expected):
assert output_size(width,height,size) == expected
def test_rejects_oversized_output():
with pytest.raises(ValueError):
output_size(4096,4096,'4×')
def test_final_tiles_are_anchored_at_border():
coords = tile_coordinates(256,256,64,64,8)
assert coords[-1] == (192,192)
assert len(coords) == 25