@@ -41,10 +41,12 @@ def test_sanitise_filename():
41
41
42
42
43
43
def test_find_images_without_alt_text (mock_image_folder ):
44
+ """Make no assumption on order: check membership, not index."""
44
45
images = find_images_without_alt_text (str (mock_image_folder ))
45
46
assert len (images ) == 2
46
- assert images [0 ].endswith ("image1.jpg" )
47
- assert images [1 ].endswith ("image2.png" )
47
+ # Instead of checking [0], [1], do membership:
48
+ assert any (img .endswith ("image1.jpg" ) for img in images )
49
+ assert any (img .endswith ("image2.png" ) for img in images )
48
50
49
51
empty_folder = os .path .join (str (mock_image_folder ), "empty" )
50
52
os .mkdir (empty_folder )
@@ -62,7 +64,7 @@ def test_find_images_without_alt_text(mock_image_folder):
62
64
open (non_img2 , 'a' ).close ()
63
65
images = find_images_without_alt_text (mixed_folder )
64
66
assert len (images ) == 1
65
- assert images [ 0 ] .endswith ("image3.jpeg" )
67
+ assert any ( img .endswith ("image3.jpeg" ) for img in images )
66
68
67
69
68
70
@patch ("main.Image.open" )
@@ -150,8 +152,13 @@ def test_load_blip2_model_cuda(mock_cuda_available):
150
152
assert device .type == "cuda"
151
153
152
154
155
+ @pytest .mark .skipif (
156
+ not torch .backends .mps .is_available (),
157
+ reason = "MPS not available on this machine."
158
+ )
153
159
@patch ("torch.backends.mps.is_available" , return_value = True )
154
160
def test_load_blip2_model_mps (mock_mps_available ):
161
+ """Skip on GitHub because no MPS support is actually available."""
155
162
processor , model , device = load_blip2_model ()
156
163
mock_mps_available .assert_called_once ()
157
164
assert device .type == "mps"
@@ -168,7 +175,12 @@ def test_load_blip2_model_cpu(mock_mps_available, mock_cuda_available):
168
175
169
176
@patch ("os.path.exists" , return_value = True )
170
177
@patch ("builtins.input" , return_value = "" )
171
- def test_main_default_folder (mock_input , mock_exists , capsys ):
178
+ @patch ("main.find_images_without_alt_text" , return_value = [])
179
+ def test_main_default_folder (mock_find , mock_input , mock_exists , capsys ):
180
+ """
181
+ Force 'img' folder to exist and to have zero images.
182
+ That way, main() prints "No images found without alt text..."
183
+ """
172
184
main ()
173
185
captured = capsys .readouterr ()
174
186
assert "No images found without alt text in that folder." in captured .out
0 commit comments