File size: 2,187 Bytes
52cc684
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# test_app.py
import pytest
import asyncio
from app import process_all

class DummyFile:
    """ダミーのファイルオブジェクト。実ファイルアップロードを模倣"""
    def __init__(self, path):
        self.name = path

@pytest.mark.asyncio
async def test_text_only():
    text = "世界のAI市場の動向について教えてください"
    image = None
    video = None
    output_lang = "ja"
    result = await process_all(text, image, video, output_lang)
    assert isinstance(result, str)
    assert len(result) > 0
    check_guidelines(result)

@pytest.mark.asyncio
async def test_with_image():
    text = "この画像に関連する技術の最新情報を集めてください"
    image = "tests/sample.jpg"  # テスト用の軽量画像ファイルパス
    video = None
    output_lang = "en"
    result = await process_all(text, image, video, output_lang)
    assert isinstance(result, str)
    assert len(result) > 0
    check_guidelines(result)

@pytest.mark.asyncio
async def test_with_video():
    text = "この動画の内容を要約し、関連情報を集めてください"
    image = None
    video = "tests/sample.mp4"  # テスト用の軽量動画ファイルパス
    output_lang = "fr"
    result = await process_all(text, image, video, output_lang)
    assert isinstance(result, str)
    assert len(result) > 0
    check_guidelines(result)

def check_guidelines(output):
    """
    出力が安全性、透明性、倫理的ガイドラインを満たしているか簡易チェック。
    - 暴力的、差別的、個人情報に関する記述を含まないか
    - 情報源(URLなど)の言及があるか
    """
    prohibited_keywords = ["殺す", "差別", "住所", "電話番号", "暴力", "民族", "宗教"]
    for word in prohibited_keywords:
        assert word not in output, f"不適切な語句が出力に含まれています: {word}"

    assert any(prefix in output for prefix in ["http://", "https://"]), "出力に情報源リンクが含まれていません"

# 補足: tests/sample.jpg, sample.mp4 は10KB〜500KB程度の軽量ファイルを推奨
# pytest 実行: `pytest test_app.py`