-
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
10 changed files
with
94 additions
and
62 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,5 +1,5 @@ | ||
artify.egg-info | ||
src/__pycache__ | ||
__pycache__/ | ||
test | ||
.pytest_cache | ||
images/content/ | ||
|
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from fastapi.testclient import TestClient | ||
from api.FastAPIHandler import app | ||
|
||
client = TestClient(app) | ||
|
||
def test_root_endpoint(): | ||
response = client.get("/") | ||
assert response.status_code == 200 | ||
assert response.json() == {"message": "Welcome to Artify! Use /apply_style to stylize your images."} | ||
|
||
def test_apply_style_endpoint(): | ||
with open("images/content/sample_content.jpg", "rb") as content, open("images/style/impressionism/sample_style.jpg", "rb") as style: | ||
response = client.post( | ||
"/apply_style/", | ||
files={"content": ("sample_content.jpg", content, "image/jpeg")}, | ||
data={"style_category": "impressionism"} | ||
) | ||
assert response.status_code == 200 | ||
assert "output_path" in response.json(), "API should return the output path." |
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
import pytest | ||
from core.StyleTransferModel import StyleTransferModel | ||
from core.ImageProcessor import ImageProcessor | ||
from PIL import Image | ||
from io import BytesIO | ||
|
||
def test_style_transfer_model_load(): | ||
model = StyleTransferModel() | ||
assert model.model is not None, "Model should be loaded successfully." | ||
|
||
def test_image_preprocessor_preprocess(): | ||
processor = ImageProcessor() | ||
image = Image.new("RGB", (800, 600), color="red") | ||
image_data = BytesIO() | ||
image.save(image_data, format="JPEG") | ||
image_data.seek(0) | ||
|
||
processed_image = processor.preprocess_image(image_data) | ||
assert processed_image.size == (512, 512), "Image should be resized to 512x512." | ||
|
||
def test_image_preprocessor_save(tmp_path): | ||
processor = ImageProcessor() | ||
image = Image.new("RGB", (512, 512), color="blue") | ||
save_path = tmp_path / "test_image.jpg" | ||
processor.save_image(image, save_path) | ||
assert save_path.exists(), "Image should be saved successfully." |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
import subprocess | ||
|
||
def test_cli_handler(): | ||
command = [ | ||
"python", | ||
"interface/CLIHandler.py", | ||
"--content", | ||
"images/content/sample_content.jpg", | ||
"--style_category", | ||
"impressionism", | ||
"--output", | ||
"images/output/test_output.jpg" | ||
] | ||
result = subprocess.run(command, capture_output=True, text=True) | ||
assert result.returncode == 0, "CLI should execute without errors." | ||
assert "Styled image saved to:" in result.stdout, "CLI should output success message." |
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
import pytest | ||
from utilities.StyleRegistry import StyleRegistry | ||
from utilities.ConfigManager import ConfigManager | ||
from utilities.Logger import Logger | ||
import os | ||
|
||
def test_style_registry_random_selection(): | ||
registry = StyleRegistry() | ||
random_style = registry.get_random_style_image("impressionism") | ||
assert random_style is not None, "Random style image should be selected." | ||
assert "impressionism" in random_style, "Selected image should belong to the requested category." | ||
|
||
def test_config_manager(tmp_path): | ||
config_path = tmp_path / "config.json" | ||
config_data = {"output_dir": "images/output", "default_style": "impressionism"} | ||
ConfigManager.save_config(config_data, config_path) | ||
loaded_config = ConfigManager.load_config(config_path) | ||
assert loaded_config == config_data, "Config should be saved and loaded correctly." | ||
|
||
def test_logger(): | ||
logger = Logger.setup_logger() | ||
assert logger is not None, "Logger should be set up successfully." |