29
29
30
30
31
31
class TestImageWithoutOpening (unittest .TestCase ):
32
- def test_detect_format (self ):
32
+ def test_detect_format (self ) -> None :
33
33
self .assertTrue (ImageSlide .detect_format (file_path ('__missing_file' )) is None )
34
34
self .assertTrue (ImageSlide .detect_format (file_path ('../setup.py' )) is None )
35
35
self .assertEqual (ImageSlide .detect_format (file_path ('boxes.png' )), 'PNG' )
36
36
37
- def test_open (self ):
37
+ def test_open (self ) -> None :
38
38
self .assertRaises (OSError , lambda : ImageSlide (file_path ('__does_not_exist' )))
39
39
self .assertRaises (OSError , lambda : ImageSlide (file_path ('../setup.py' )))
40
40
41
- def test_open_image (self ):
41
+ def test_open_image (self ) -> None :
42
42
# passing PIL.Image to ImageSlide
43
43
with Image .open (file_path ('boxes.png' )) as img :
44
44
with ImageSlide (img ) as osr :
@@ -49,18 +49,18 @@ def test_open_image(self):
49
49
sys .getfilesystemencoding () == 'utf-8' ,
50
50
'Python filesystem encoding is not UTF-8' ,
51
51
)
52
- def test_unicode_path (self ):
52
+ def test_unicode_path (self ) -> None :
53
53
path = file_path ('😐.png' )
54
54
for arg in path , str (path ):
55
55
self .assertEqual (ImageSlide .detect_format (arg ), 'PNG' )
56
56
self .assertEqual (ImageSlide (arg ).dimensions , (300 , 250 ))
57
57
58
- def test_unicode_path_bytes (self ):
58
+ def test_unicode_path_bytes (self ) -> None :
59
59
arg = str (file_path ('😐.png' )).encode ('UTF-8' )
60
60
self .assertEqual (ImageSlide .detect_format (arg ), 'PNG' )
61
61
self .assertEqual (ImageSlide (arg ).dimensions , (300 , 250 ))
62
62
63
- def test_operations_on_closed_handle (self ):
63
+ def test_operations_on_closed_handle (self ) -> None :
64
64
with Image .open (file_path ('boxes.png' )) as img :
65
65
osr = ImageSlide (img )
66
66
osr .close ()
@@ -72,7 +72,7 @@ def test_operations_on_closed_handle(self):
72
72
# shouldn't close it
73
73
self .assertEqual (img .getpixel ((0 , 0 )), 3 )
74
74
75
- def test_context_manager (self ):
75
+ def test_context_manager (self ) -> None :
76
76
osr = ImageSlide (file_path ('boxes.png' ))
77
77
with osr :
78
78
pass
@@ -83,20 +83,23 @@ def test_context_manager(self):
83
83
class _Abstract :
84
84
# nested class to prevent the test runner from finding it
85
85
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
87
90
self .osr = ImageSlide (file_path (self .FILENAME ))
88
91
89
- def tearDown (self ):
92
+ def tearDown (self ) -> None :
90
93
self .osr .close ()
91
94
92
95
93
96
class TestImage (_Abstract .SlideTest ):
94
97
FILENAME = 'boxes.png'
95
98
96
- def test_repr (self ):
99
+ def test_repr (self ) -> None :
97
100
self .assertEqual (repr (self .osr ), 'ImageSlide(%r)' % file_path ('boxes.png' ))
98
101
99
- def test_metadata (self ):
102
+ def test_metadata (self ) -> None :
100
103
self .assertEqual (self .osr .level_count , 1 )
101
104
self .assertEqual (self .osr .level_dimensions , ((300 , 250 ),))
102
105
self .assertEqual (self .osr .dimensions , (300 , 250 ))
@@ -108,7 +111,8 @@ def test_metadata(self):
108
111
self .assertEqual (self .osr .properties , {})
109
112
self .assertEqual (self .osr .associated_images , {})
110
113
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
112
116
self .assertEqual (self .osr .color_profile .profile .device_class , 'mntr' )
113
117
self .assertEqual (
114
118
len (self .osr .read_region ((0 , 0 ), 0 , (100 , 100 )).info ['icc_profile' ]), 588
@@ -117,37 +121,37 @@ def test_color_profile(self):
117
121
len (self .osr .get_thumbnail ((100 , 100 )).info ['icc_profile' ]), 588
118
122
)
119
123
120
- def test_read_region (self ):
124
+ def test_read_region (self ) -> None :
121
125
self .assertEqual (
122
126
self .osr .read_region ((- 10 , - 10 ), 0 , (400 , 400 )).size , (400 , 400 )
123
127
)
124
128
125
- def test_read_region_size_dimension_zero (self ):
129
+ def test_read_region_size_dimension_zero (self ) -> None :
126
130
self .assertEqual (self .osr .read_region ((0 , 0 ), 0 , (400 , 0 )).size , (400 , 0 ))
127
131
128
- def test_read_region_bad_level (self ):
132
+ def test_read_region_bad_level (self ) -> None :
129
133
self .assertRaises (
130
134
OpenSlideError , lambda : self .osr .read_region ((0 , 0 ), 1 , (100 , 100 ))
131
135
)
132
136
133
- def test_read_region_bad_size (self ):
137
+ def test_read_region_bad_size (self ) -> None :
134
138
self .assertRaises (
135
139
OpenSlideError , lambda : self .osr .read_region ((0 , 0 ), 0 , (400 , - 5 ))
136
140
)
137
141
138
- def test_thumbnail (self ):
142
+ def test_thumbnail (self ) -> None :
139
143
self .assertEqual (self .osr .get_thumbnail ((100 , 100 )).size , (100 , 83 ))
140
144
141
145
@unittest .skipUnless (lowlevel .cache_create .available , "requires OpenSlide 4.0.0" )
142
- def test_set_cache (self ):
146
+ def test_set_cache (self ) -> None :
143
147
self .osr .set_cache (OpenSlideCache (64 << 10 ))
144
148
self .assertEqual (self .osr .read_region ((0 , 0 ), 0 , (400 , 400 )).size , (400 , 400 ))
145
149
146
150
147
151
class TestNoIccImage (_Abstract .SlideTest ):
148
152
FILENAME = 'boxes-no-icc.png'
149
153
150
- def test_color_profile (self ):
154
+ def test_color_profile (self ) -> None :
151
155
self .assertIsNone (self .osr .color_profile )
152
156
self .assertNotIn (
153
157
'icc_profile' , self .osr .read_region ((0 , 0 ), 0 , (100 , 100 )).info
0 commit comments