2929
3030
3131class TestImageWithoutOpening (unittest .TestCase ):
32- def test_detect_format (self ):
32+ def test_detect_format (self ) -> None :
3333 self .assertTrue (ImageSlide .detect_format (file_path ('__missing_file' )) is None )
3434 self .assertTrue (ImageSlide .detect_format (file_path ('../setup.py' )) is None )
3535 self .assertEqual (ImageSlide .detect_format (file_path ('boxes.png' )), 'PNG' )
3636
37- def test_open (self ):
37+ def test_open (self ) -> None :
3838 self .assertRaises (OSError , lambda : ImageSlide (file_path ('__does_not_exist' )))
3939 self .assertRaises (OSError , lambda : ImageSlide (file_path ('../setup.py' )))
4040
41- def test_open_image (self ):
41+ def test_open_image (self ) -> None :
4242 # passing PIL.Image to ImageSlide
4343 with Image .open (file_path ('boxes.png' )) as img :
4444 with ImageSlide (img ) as osr :
@@ -49,18 +49,18 @@ def test_open_image(self):
4949 sys .getfilesystemencoding () == 'utf-8' ,
5050 'Python filesystem encoding is not UTF-8' ,
5151 )
52- def test_unicode_path (self ):
52+ def test_unicode_path (self ) -> None :
5353 path = file_path ('😐.png' )
5454 for arg in path , str (path ):
5555 self .assertEqual (ImageSlide .detect_format (arg ), 'PNG' )
5656 self .assertEqual (ImageSlide (arg ).dimensions , (300 , 250 ))
5757
58- def test_unicode_path_bytes (self ):
58+ def test_unicode_path_bytes (self ) -> None :
5959 arg = str (file_path ('😐.png' )).encode ('UTF-8' )
6060 self .assertEqual (ImageSlide .detect_format (arg ), 'PNG' )
6161 self .assertEqual (ImageSlide (arg ).dimensions , (300 , 250 ))
6262
63- def test_operations_on_closed_handle (self ):
63+ def test_operations_on_closed_handle (self ) -> None :
6464 with Image .open (file_path ('boxes.png' )) as img :
6565 osr = ImageSlide (img )
6666 osr .close ()
@@ -72,7 +72,7 @@ def test_operations_on_closed_handle(self):
7272 # shouldn't close it
7373 self .assertEqual (img .getpixel ((0 , 0 )), 3 )
7474
75- def test_context_manager (self ):
75+ def test_context_manager (self ) -> None :
7676 osr = ImageSlide (file_path ('boxes.png' ))
7777 with osr :
7878 pass
@@ -83,20 +83,23 @@ def test_context_manager(self):
8383class _Abstract :
8484 # nested class to prevent the test runner from finding it
8585 class SlideTest (unittest .TestCase ):
86- def setUp (self ):
86+ FILENAME : str | None = None
87+
88+ def setUp (self ) -> None :
89+ assert self .FILENAME is not None
8790 self .osr = ImageSlide (file_path (self .FILENAME ))
8891
89- def tearDown (self ):
92+ def tearDown (self ) -> None :
9093 self .osr .close ()
9194
9295
9396class TestImage (_Abstract .SlideTest ):
9497 FILENAME = 'boxes.png'
9598
96- def test_repr (self ):
99+ def test_repr (self ) -> None :
97100 self .assertEqual (repr (self .osr ), 'ImageSlide(%r)' % file_path ('boxes.png' ))
98101
99- def test_metadata (self ):
102+ def test_metadata (self ) -> None :
100103 self .assertEqual (self .osr .level_count , 1 )
101104 self .assertEqual (self .osr .level_dimensions , ((300 , 250 ),))
102105 self .assertEqual (self .osr .dimensions , (300 , 250 ))
@@ -108,7 +111,8 @@ def test_metadata(self):
108111 self .assertEqual (self .osr .properties , {})
109112 self .assertEqual (self .osr .associated_images , {})
110113
111- def test_color_profile (self ):
114+ def test_color_profile (self ) -> None :
115+ assert self .osr .color_profile is not None # for type inference
112116 self .assertEqual (self .osr .color_profile .profile .device_class , 'mntr' )
113117 self .assertEqual (
114118 len (self .osr .read_region ((0 , 0 ), 0 , (100 , 100 )).info ['icc_profile' ]), 588
@@ -117,37 +121,37 @@ def test_color_profile(self):
117121 len (self .osr .get_thumbnail ((100 , 100 )).info ['icc_profile' ]), 588
118122 )
119123
120- def test_read_region (self ):
124+ def test_read_region (self ) -> None :
121125 self .assertEqual (
122126 self .osr .read_region ((- 10 , - 10 ), 0 , (400 , 400 )).size , (400 , 400 )
123127 )
124128
125- def test_read_region_size_dimension_zero (self ):
129+ def test_read_region_size_dimension_zero (self ) -> None :
126130 self .assertEqual (self .osr .read_region ((0 , 0 ), 0 , (400 , 0 )).size , (400 , 0 ))
127131
128- def test_read_region_bad_level (self ):
132+ def test_read_region_bad_level (self ) -> None :
129133 self .assertRaises (
130134 OpenSlideError , lambda : self .osr .read_region ((0 , 0 ), 1 , (100 , 100 ))
131135 )
132136
133- def test_read_region_bad_size (self ):
137+ def test_read_region_bad_size (self ) -> None :
134138 self .assertRaises (
135139 OpenSlideError , lambda : self .osr .read_region ((0 , 0 ), 0 , (400 , - 5 ))
136140 )
137141
138- def test_thumbnail (self ):
142+ def test_thumbnail (self ) -> None :
139143 self .assertEqual (self .osr .get_thumbnail ((100 , 100 )).size , (100 , 83 ))
140144
141145 @unittest .skipUnless (lowlevel .cache_create .available , "requires OpenSlide 4.0.0" )
142- def test_set_cache (self ):
146+ def test_set_cache (self ) -> None :
143147 self .osr .set_cache (OpenSlideCache (64 << 10 ))
144148 self .assertEqual (self .osr .read_region ((0 , 0 ), 0 , (400 , 400 )).size , (400 , 400 ))
145149
146150
147151class TestNoIccImage (_Abstract .SlideTest ):
148152 FILENAME = 'boxes-no-icc.png'
149153
150- def test_color_profile (self ):
154+ def test_color_profile (self ) -> None :
151155 self .assertIsNone (self .osr .color_profile )
152156 self .assertNotIn (
153157 'icc_profile' , self .osr .read_region ((0 , 0 ), 0 , (100 , 100 )).info
0 commit comments