forked from neonwatty/meme-search
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
243 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: rails tests for meme search app | ||
name: rails tests for meme search pro app | ||
|
||
on: | ||
workflow_dispatch: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
numpy | ||
matplotlib | ||
accelerate==0.25.0 | ||
huggingface-hub==0.20.1 | ||
Pillow==10.1.0 | ||
torch==2.1.2 | ||
torchvision==0.16.2 | ||
transformers==4.36.2 | ||
einops==0.7.0 | ||
sentence-transformers==2.2.2 | ||
accelerate | ||
huggingface-hub | ||
Pillow | ||
torch | ||
torchvision | ||
transformers | ||
einops | ||
sentence-transformers | ||
faiss-cpu | ||
streamlit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import os | ||
|
||
cwd = os.getcwd() | ||
base_test_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
CONTAINER_NAME = "meme_search" | ||
STREAMLIT_APP_FILE = "meme_search_app/app.py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import subprocess | ||
import pytest | ||
import time | ||
from tests import STREAMLIT_APP_FILE | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def start_streamlit_app(): | ||
cmd = f"python -m streamlit run {STREAMLIT_APP_FILE} --server.headless true" | ||
print(f"here here HERE --> {cmd}") | ||
process = subprocess.Popen( | ||
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE | ||
) | ||
time.sleep(5) | ||
yield process | ||
process.terminate() | ||
process.wait() | ||
|
||
|
||
def test_streamlit(subtests, start_streamlit_app): | ||
with subtests.test(msg="streamlit up"): | ||
assert start_streamlit_app.poll() is None, "Streamlit app failed to start" | ||
|
||
with subtests.test(msg="streamlit down"): | ||
start_streamlit_app.terminate() | ||
time.sleep(2) | ||
assert start_streamlit_app.poll() is not None, "Streamlit app failed to stop" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import subprocess | ||
from tests import cwd, CONTAINER_NAME | ||
|
||
|
||
def terminal_process(command: list) -> int: | ||
output = subprocess.Popen( | ||
command, | ||
cwd=cwd, | ||
stdin=None, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
) | ||
return output.wait() | ||
|
||
|
||
def test_compose(subtests): | ||
up_cmd = ["docker", "compose", "up", "-d"] | ||
ps_cmd = "docker-compose ps" | ||
down_cmd = ["docker", "compose", "down"] | ||
|
||
with subtests.test(msg="compose down"): | ||
code = terminal_process(down_cmd) | ||
assert code == 0, "compose down failed" | ||
|
||
with subtests.test(msg="compose up"): | ||
code = terminal_process(up_cmd) | ||
assert code == 0, "compose up failed" | ||
|
||
with subtests.test(msg="docker ps"): | ||
result = subprocess.run(ps_cmd, shell=True, check=True, capture_output=True) | ||
assert result.returncode == 0, "Failed to run docker-compose ps" | ||
assert ( | ||
bytes(CONTAINER_NAME, "utf-8") in result.stdout | ||
), f"{CONTAINER_NAME} container not running" | ||
|
||
with subtests.test(msg="compose down"): | ||
code = terminal_process(down_cmd) | ||
assert code == 0, "compose down failed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
test_input_img_names = [ | ||
"data/input/test_meme_1.jpg", | ||
"data/input/test_meme_2.jpg", | ||
"data/input/test_meme_3.jpg", | ||
"data/input/test_meme_4.jpg", | ||
"data/input/test_meme_5.jpg", | ||
"data/input/test_meme_6.jpg", | ||
"data/input/test_meme_7.jpg", | ||
"data/input/test_meme_8.jpg", | ||
"data/input/test_meme_9.jpg", | ||
] | ||
|
||
test_db_names = [ | ||
"data/dbs/memes.db", | ||
"data/dbs/memes.faiss", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import os | ||
import shutil | ||
import time | ||
from meme_search.utilities.status import get_input_directory_status | ||
from meme_search.utilities.add import add | ||
from meme_search.utilities.remove import remove | ||
from tests import base_test_dir | ||
|
||
utilities_dir = base_test_dir + "/utilities" | ||
default_test_img_dir = utilities_dir + "/test_images/" | ||
alt_test_img_dir = utilities_dir + "/test_images_alternate/" | ||
db_test_dir = utilities_dir + "/test_dbs/" | ||
sqlite_db_path = db_test_dir + "memes.db" | ||
vector_db_path = db_test_dir + "memes.faiss" | ||
test_img_default_location = default_test_img_dir + "test_meme_2.jpg" | ||
test_img_alt_location = alt_test_img_dir + "test_meme_2.jpg" | ||
|
||
|
||
def test_normalize(subtests): | ||
with subtests.test(msg="reset image directories"): | ||
try: | ||
shutil.move(test_img_alt_location, default_test_img_dir) | ||
except: | ||
pass | ||
|
||
time.sleep(2) | ||
|
||
old_imgs_to_be_removed, new_imgs_to_be_indexed = get_input_directory_status(default_test_img_dir, sqlite_db_path) | ||
if len(old_imgs_to_be_removed) > 0: | ||
assert remove(old_imgs_to_be_removed, sqlite_db_path, vector_db_path) is None | ||
|
||
if len(new_imgs_to_be_indexed) > 0: | ||
assert add(new_imgs_to_be_indexed, sqlite_db_path, vector_db_path) is None | ||
|
||
with subtests.test(msg="normalize final check"): | ||
old_imgs_to_be_removed, new_imgs_to_be_indexed = get_input_directory_status(default_test_img_dir, sqlite_db_path) | ||
assert len(old_imgs_to_be_removed) == 0 | ||
assert len(new_imgs_to_be_indexed) == 0 | ||
|
||
|
||
def test_remove(subtests): | ||
|
||
with subtests.test(msg="move from default to alt"): | ||
shutil.move(test_img_default_location, alt_test_img_dir) | ||
time.sleep(5) | ||
assert os.path.exists(test_img_alt_location), "FAILURE: image could not be moved from default to alt location" | ||
|
||
with subtests.test(msg="remove old imgs"): | ||
old_imgs_to_be_removed, new_imgs_to_be_indexed = get_input_directory_status(default_test_img_dir, sqlite_db_path) | ||
assert len(old_imgs_to_be_removed) > 0 | ||
assert len(new_imgs_to_be_indexed) == 0 | ||
assert remove(old_imgs_to_be_removed, sqlite_db_path, vector_db_path) is None, "FAILURE: removing moving image" | ||
|
||
with subtests.test(msg="remove final check"): | ||
old_imgs_to_be_removed, new_imgs_to_be_indexed = get_input_directory_status(default_test_img_dir, sqlite_db_path) | ||
assert len(old_imgs_to_be_removed) == 0 | ||
assert len(new_imgs_to_be_indexed) == 0 | ||
|
||
|
||
def test_add(subtests): | ||
with subtests.test(msg="move from alt to default"): | ||
shutil.move(test_img_alt_location, default_test_img_dir) | ||
time.sleep(5) | ||
assert os.path.exists(test_img_default_location), "FAILURE: image could not be moved from alt to default location" | ||
|
||
with subtests.test(msg="add new img"): | ||
old_imgs_to_be_removed, new_imgs_to_be_indexed = get_input_directory_status(default_test_img_dir, sqlite_db_path) | ||
assert len(new_imgs_to_be_indexed) > 0 | ||
assert len(old_imgs_to_be_removed) == 0 | ||
assert add(new_imgs_to_be_indexed, sqlite_db_path, vector_db_path) is None, "FAILURE: adding image" | ||
|
||
with subtests.test(msg="add final check"): | ||
old_imgs_to_be_removed, new_imgs_to_be_indexed = get_input_directory_status(default_test_img_dir, sqlite_db_path) | ||
assert len(old_imgs_to_be_removed) == 0 | ||
assert len(new_imgs_to_be_indexed) == 0 |
Binary file not shown.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
from meme_search import meme_search_root_dir | ||
from meme_search.utilities.imgs import collect_img_paths, allowable_extensions | ||
|
||
|
||
def list_files_in_directory(directory_path): | ||
try: | ||
files = [f for f in os.listdir(directory_path) if (os.path.isfile(os.path.join(directory_path, f)) and f.split(".")[-1] in allowable_extensions)] | ||
return files | ||
except OSError as error: | ||
print(f"Error accessing directory '{directory_path}': {error}") | ||
return [] | ||
|
||
|
||
def test_collect_img_paths(): | ||
img_data_path = meme_search_root_dir + "/data/input" | ||
actual_files = list_files_in_directory(img_data_path) | ||
output_files = collect_img_paths(img_data_path) | ||
output_files = [v.split("/")[-1] for v in output_files] | ||
assert len(set(actual_files) - set(output_files)) == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from meme_search.utilities.query import complete_query | ||
import pytest | ||
|
||
|
||
test_queries = [ | ||
("two capsules", "test_meme_5.jpg"), | ||
("no", "test_meme_9.jpg") | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("query, top_result", test_queries) | ||
def test_complete_query(query, top_result): | ||
unique_img_entries = complete_query(query) | ||
assert unique_img_entries[0]["img_path"].split("/")[-1] == top_result |