You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.3 KiB
55 lines
1.3 KiB
# Filename: test_utils.py
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
from swarms.utils import find_image_path
|
|
|
|
|
|
def test_find_image_path_no_images():
|
|
assert (
|
|
find_image_path(
|
|
"This is a test string without any image paths."
|
|
)
|
|
is None
|
|
)
|
|
|
|
|
|
def test_find_image_path_one_image():
|
|
text = "This is a string with one image path: sample_image.jpg."
|
|
assert find_image_path(text) == "sample_image.jpg"
|
|
|
|
|
|
def test_find_image_path_multiple_images():
|
|
text = "This string has two image paths: img1.png, and img2.jpg."
|
|
assert (
|
|
find_image_path(text) == "img2.jpg"
|
|
) # Assuming both images exist
|
|
|
|
|
|
def test_find_image_path_wrong_input():
|
|
with pytest.raises(TypeError):
|
|
find_image_path(123)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"text, expected",
|
|
[
|
|
("no image path here", None),
|
|
("image: sample.png", "sample.png"),
|
|
("image: sample.png, another: another.jpeg", "another.jpeg"),
|
|
],
|
|
)
|
|
def test_find_image_path_parameterized(text, expected):
|
|
assert find_image_path(text) == expected
|
|
|
|
|
|
def mock_os_path_exists(path):
|
|
return True
|
|
|
|
|
|
def test_find_image_path_mocking(monkeypatch):
|
|
monkeypatch.setattr(os.path, "exists", mock_os_path_exists)
|
|
assert find_image_path("image.jpg") == "image.jpg"
|