Skip to content

Commit 2c4edd3

Browse files
committed
Updated test_main.py
1 parent a6b6117 commit 2c4edd3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

tests/test_main.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ def test_sanitise_filename():
4141

4242

4343
def test_find_images_without_alt_text(mock_image_folder):
44+
"""Make no assumption on order: check membership, not index."""
4445
images = find_images_without_alt_text(str(mock_image_folder))
4546
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)
4850

4951
empty_folder = os.path.join(str(mock_image_folder), "empty")
5052
os.mkdir(empty_folder)
@@ -62,7 +64,7 @@ def test_find_images_without_alt_text(mock_image_folder):
6264
open(non_img2, 'a').close()
6365
images = find_images_without_alt_text(mixed_folder)
6466
assert len(images) == 1
65-
assert images[0].endswith("image3.jpeg")
67+
assert any(img.endswith("image3.jpeg") for img in images)
6668

6769

6870
@patch("main.Image.open")
@@ -150,8 +152,13 @@ def test_load_blip2_model_cuda(mock_cuda_available):
150152
assert device.type == "cuda"
151153

152154

155+
@pytest.mark.skipif(
156+
not torch.backends.mps.is_available(),
157+
reason="MPS not available on this machine."
158+
)
153159
@patch("torch.backends.mps.is_available", return_value=True)
154160
def test_load_blip2_model_mps(mock_mps_available):
161+
"""Skip on GitHub because no MPS support is actually available."""
155162
processor, model, device = load_blip2_model()
156163
mock_mps_available.assert_called_once()
157164
assert device.type == "mps"
@@ -168,7 +175,12 @@ def test_load_blip2_model_cpu(mock_mps_available, mock_cuda_available):
168175

169176
@patch("os.path.exists", return_value=True)
170177
@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+
"""
172184
main()
173185
captured = capsys.readouterr()
174186
assert "No images found without alt text in that folder." in captured.out

0 commit comments

Comments
 (0)