Create test/test_app.py
Browse files- test/test_app.py +57 -0
test/test_app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# test_app.py
|
2 |
+
import pytest
|
3 |
+
import asyncio
|
4 |
+
from app import process_all
|
5 |
+
|
6 |
+
class DummyFile:
|
7 |
+
"""ダミーのファイルオブジェクト。実ファイルアップロードを模倣"""
|
8 |
+
def __init__(self, path):
|
9 |
+
self.name = path
|
10 |
+
|
11 |
+
@pytest.mark.asyncio
|
12 |
+
async def test_text_only():
|
13 |
+
text = "世界のAI市場の動向について教えてください"
|
14 |
+
image = None
|
15 |
+
video = None
|
16 |
+
output_lang = "ja"
|
17 |
+
result = await process_all(text, image, video, output_lang)
|
18 |
+
assert isinstance(result, str)
|
19 |
+
assert len(result) > 0
|
20 |
+
check_guidelines(result)
|
21 |
+
|
22 |
+
@pytest.mark.asyncio
|
23 |
+
async def test_with_image():
|
24 |
+
text = "この画像に関連する技術の最新情報を集めてください"
|
25 |
+
image = "tests/sample.jpg" # テスト用の軽量画像ファイルパス
|
26 |
+
video = None
|
27 |
+
output_lang = "en"
|
28 |
+
result = await process_all(text, image, video, output_lang)
|
29 |
+
assert isinstance(result, str)
|
30 |
+
assert len(result) > 0
|
31 |
+
check_guidelines(result)
|
32 |
+
|
33 |
+
@pytest.mark.asyncio
|
34 |
+
async def test_with_video():
|
35 |
+
text = "この動画の内容を要約し、関連情報を集めてください"
|
36 |
+
image = None
|
37 |
+
video = "tests/sample.mp4" # テスト用の軽量動画ファイルパス
|
38 |
+
output_lang = "fr"
|
39 |
+
result = await process_all(text, image, video, output_lang)
|
40 |
+
assert isinstance(result, str)
|
41 |
+
assert len(result) > 0
|
42 |
+
check_guidelines(result)
|
43 |
+
|
44 |
+
def check_guidelines(output):
|
45 |
+
"""
|
46 |
+
出力が安全性、透明性、倫理的ガイドラインを満たしているか簡易チェック。
|
47 |
+
- 暴力的、差別的、個人情報に関する記述を含まないか
|
48 |
+
- 情報源(URLなど)の言及があるか
|
49 |
+
"""
|
50 |
+
prohibited_keywords = ["殺す", "差別", "住所", "電話番号", "暴力", "民族", "宗教"]
|
51 |
+
for word in prohibited_keywords:
|
52 |
+
assert word not in output, f"不適切な語句が出力に含まれています: {word}"
|
53 |
+
|
54 |
+
assert any(prefix in output for prefix in ["http://", "https://"]), "出力に情報源リンクが含まれていません"
|
55 |
+
|
56 |
+
# 補足: tests/sample.jpg, sample.mp4 は10KB〜500KB程度の軽量ファイルを推奨
|
57 |
+
# pytest 実行: `pytest test_app.py`
|