43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
import os
|
|
import sys
|
|
import pathlib
|
|
from PIL import Image
|
|
# ensure package path is importable when running tests directly
|
|
pkg_root = pathlib.Path(__file__).resolve().parents[1]
|
|
if str(pkg_root) not in sys.path:
|
|
sys.path.insert(0, str(pkg_root))
|
|
|
|
from map_manager.services import OpenStreetMapService
|
|
from map_manager.tile_manager import MapTileManager
|
|
|
|
|
|
def test_stitch_progress_callback(tmp_path):
|
|
service = OpenStreetMapService()
|
|
cache_dir = tmp_path / 'cache'
|
|
mgr = MapTileManager(service, cache_root_directory=str(cache_dir), enable_online_tile_fetching=False)
|
|
|
|
# monkeypatch get_tile_image to avoid network and make it quick
|
|
def fake_get_tile_image(z, x, y, force_online_refresh=False):
|
|
return Image.new('RGB', (mgr.tile_size, mgr.tile_size), (100, 100, 100))
|
|
|
|
mgr.get_tile_image = fake_get_tile_image
|
|
|
|
calls = []
|
|
|
|
def progress_cb(done, total, last_dur, from_cache, tile_coords):
|
|
calls.append((done, total, last_dur, from_cache, tile_coords))
|
|
|
|
# stitch a small range (2x1 tiles => 2 tiles)
|
|
result = mgr.stitch_map_image(1, (0, 1), (0, 0), progress_callback=progress_cb)
|
|
assert result is not None
|
|
# ensure callback called for each tile
|
|
assert len(calls) == 2
|
|
# check that totals are consistent
|
|
for idx, call in enumerate(calls, start=1):
|
|
done, total, last_dur, from_cache, tile_coords = call
|
|
assert total == 2
|
|
assert done == idx
|
|
assert isinstance(last_dur, float)
|
|
assert isinstance(from_cache, bool)
|
|
assert isinstance(tile_coords, tuple) and len(tile_coords) == 3
|