55import json
66import shutil
77from pathlib import Path
8+ from types import SimpleNamespace
89from typing import TYPE_CHECKING , Any , Final
910from unittest .mock import MagicMock
1011
@@ -1029,7 +1030,6 @@ def test_get_tile_info_small_image_triggers_early_return(
10291030
10301031 """
10311032 # --- Arrange ---
1032- # Make image smaller than tile_shape
10331033 image_shape = [100 , 100 ]
10341034
10351035 # Configure tile_shape so that tile_shape >= image_shape
@@ -1041,25 +1041,35 @@ def test_get_tile_info_small_image_triggers_early_return(
10411041 patch_input_shape = (200 , 200 ),
10421042 )
10431043
1044- # Patch PatchExtractor.get_coordinates to return predictable boxes
1044+ # Fake return from PatchExtractor.get_coordinates
10451045 fake_boxes = np .array ([[0 , 0 , 100 , 100 ]])
10461046 monkeypatch .setattr (
10471047 "tiatoolbox.tools.patchextraction.PatchExtractor.get_coordinates" ,
1048- lambda ** kwargs : (None , fake_boxes ), # noqa: ARG005
1048+ lambda ** _ : (None , fake_boxes ),
10491049 )
10501050
1051+ # Create a dummy dataset with required attributes
1052+ dummy_dataset = SimpleNamespace (mask_reader = None )
1053+
1054+ # Dummy dataloader-like container
1055+ dummy_dataloader = SimpleNamespace (dataset = dummy_dataset )
1056+
1057+ # Create a real instance and inject required fields
1058+ m = MultiTaskSegmentor (model = "hovernet_fast-pannuke" )
1059+ m ._ioconfig = ioconfig
1060+ m .mask_padding = (0 , 0 , 0 , 0 )
1061+ m .dataloader = dummy_dataloader
1062+
10511063 # --- Act ---
1052- result = MultiTaskSegmentor ._get_tile_info (image_shape , ioconfig )
1064+ result = m ._get_tile_info (image_shape = image_shape , wsi_proc_shape = image_shape )
10531065
10541066 # --- Assert ---
10551067 assert isinstance (result , list )
1056- assert len (result ) == 1 # early return path
1068+ assert len (result ) == 1
1069+
10571070 boxes , flag = result [0 ]
10581071
1059- # boxes should be exactly what we patched
10601072 assert np .array_equal (boxes , fake_boxes )
1061-
1062- # flag should be zeros with shape (N, 4)
10631073 assert flag .shape == (1 , 4 )
10641074 assert np .all (flag == 0 )
10651075
0 commit comments