Skip to content

Commit bedd63e

Browse files
committed
feat: refactor image captioning tests and add ESLint configuration
1 parent 7dfaec1 commit bedd63e

File tree

4 files changed

+69
-23
lines changed

4 files changed

+69
-23
lines changed

.eslintrc.json

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit ebf414ea497a020da0f82df3913e5b6cb8e9663a

backend/tests/test_image_captioning.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
import pytest
22
from unittest.mock import MagicMock, patch
3-
from service.image_captioning import ImageCaptioning
3+
from pathlib import Path
4+
from service.image_captioning import ImageCaptioningService
45

56
@pytest.fixture
6-
def dummy_captioner():
7+
def dummy_captioner(tmp_path):
78
with patch('service.image_captioning.LlavaForConditionalGeneration.from_pretrained') as mock_model, \
89
patch('service.image_captioning.AutoProcessor.from_pretrained') as mock_processor:
910
mock_model.return_value = MagicMock()
1011
processor_instance = MagicMock()
11-
# Set the processor mock to return our processor_instance
1212
mock_processor.return_value = processor_instance
13-
captioner = ImageCaptioning("dummy-model")
13+
14+
load_path = tmp_path / "load"
15+
save_path = tmp_path / "save"
16+
load_path.mkdir()
17+
save_path.mkdir()
18+
19+
captioner = ImageCaptioningService(
20+
model=Path("dummy-model"),
21+
load_path=load_path,
22+
save_path=save_path,
23+
prompt="Describe this image."
24+
)
25+
1426
# Mock methods used in the pipeline
1527
captioner._model.generate = MagicMock(return_value=[[1, 2, 3, 4]])
1628
processor_instance.apply_chat_template = MagicMock(return_value="prompt")
@@ -19,7 +31,6 @@ def dummy_captioner():
1931
"pixel_values": MagicMock()
2032
}
2133
processor_instance.tokenizer.decode = MagicMock(return_value="A cat on a mat.")
22-
# Make sure the processor mock is used for __call__
2334
captioner._processor = processor_instance
2435
return captioner
2536

@@ -28,7 +39,7 @@ def test_image_inputs(dummy_captioner, tmp_path):
2839
img_path = tmp_path / "test.jpg"
2940
from PIL import Image
3041
Image.new("RGB", (10, 10)).save(img_path)
31-
inputs = dummy_captioner._image_inputs(img_path, "Describe this image.")
42+
inputs = dummy_captioner._image_inputs(img_path)
3243
assert "input_ids" in inputs
3344

3445
def test_generate_caption(dummy_captioner):
@@ -44,7 +55,7 @@ def test_save_caption(dummy_captioner, tmp_path):
4455
img_path = tmp_path / "test.jpg"
4556
img_path.touch()
4657
caption = "A cat on a mat."
47-
output_file = dummy_captioner.save_caption(caption, img_path)
58+
output_file = dummy_captioner.save_caption(caption, img_path, tmp_path)
4859
assert output_file.exists()
4960
with open(output_file, "r", encoding="utf-8") as f:
5061
assert f.read() == caption

eslint.config.mjs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import eslint from "@eslint/js";
2+
import tseslint from "@typescript-eslint/eslint-plugin";
3+
import tsparser from "@typescript-eslint/parser";
4+
import importPlugin from "eslint-plugin-import";
5+
6+
export default [
7+
{
8+
ignores: [
9+
"node_modules/**",
10+
".vite/**",
11+
"out/**",
12+
"dist/**",
13+
"backend/**",
14+
"*.js",
15+
],
16+
},
17+
eslint.configs.recommended,
18+
{
19+
files: ["**/*.ts", "**/*.tsx"],
20+
languageOptions: {
21+
parser: tsparser,
22+
parserOptions: {
23+
ecmaVersion: "latest",
24+
sourceType: "module",
25+
},
26+
globals: {
27+
console: "readonly",
28+
process: "readonly",
29+
__dirname: "readonly",
30+
Buffer: "readonly",
31+
setTimeout: "readonly",
32+
clearTimeout: "readonly",
33+
fetch: "readonly",
34+
window: "readonly",
35+
document: "readonly",
36+
MAIN_WINDOW_VITE_DEV_SERVER_URL: "readonly",
37+
MAIN_WINDOW_VITE_NAME: "readonly",
38+
},
39+
},
40+
plugins: {
41+
"@typescript-eslint": tseslint,
42+
import: importPlugin,
43+
},
44+
rules: {
45+
...tseslint.configs.recommended.rules,
46+
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
47+
"@typescript-eslint/no-explicit-any": "warn",
48+
},
49+
},
50+
];

0 commit comments

Comments
 (0)