Spaces:
Running
Running
Update intent_test_runner.py
Browse files- intent_test_runner.py +75 -69
intent_test_runner.py
CHANGED
@@ -1,70 +1,76 @@
|
|
1 |
-
import os
|
2 |
-
import requests
|
3 |
-
from log import log
|
4 |
-
|
5 |
-
BASE_URL = "http://localhost:7860"
|
6 |
-
|
7 |
-
|
8 |
-
test_results = []
|
9 |
-
|
10 |
-
def assert_test(name, actual, expected_substring, explanation=None):
|
11 |
-
if explanation:
|
12 |
-
log(f"🧪 TEST: {name} → {explanation}")
|
13 |
-
actual_str = str(actual)
|
14 |
-
if expected_substring in actual_str:
|
15 |
-
log(f"[TEST] {name:<45} ✅")
|
16 |
-
test_results.append((name, True))
|
17 |
-
else:
|
18 |
-
log(f"[TEST] {name:<45} ❌ — Beklenen: {expected_substring}, Gelen: {actual_str[:100]}...")
|
19 |
-
test_results.append((name, False))
|
20 |
-
|
21 |
-
def summarize_tests():
|
22 |
-
total = len(test_results)
|
23 |
-
success = sum(1 for _, ok in test_results if ok)
|
24 |
-
fail = total - success
|
25 |
-
log("🧾 TEST SONUCU ÖZETİ")
|
26 |
-
log(f"🔢 Toplam Test : {total}")
|
27 |
-
log(f"✅ Başarılı : {success}")
|
28 |
-
log(f"❌ Başarısız : {fail}")
|
29 |
-
|
30 |
-
def run_all_tests():
|
31 |
-
try:
|
32 |
-
log("🚀 Test süreci başlatıldı.")
|
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 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "
|
65 |
-
assert_test("
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
log(f"❌ run_all_tests sırasında hata oluştu: {e}")
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
from log import log
|
4 |
+
|
5 |
+
BASE_URL = "http://localhost:7860"
|
6 |
+
PROJECT_NAME = "project1"
|
7 |
+
|
8 |
+
test_results = []
|
9 |
+
|
10 |
+
def assert_test(name, actual, expected_substring, explanation=None):
|
11 |
+
if explanation:
|
12 |
+
log(f"🧪 TEST: {name} → {explanation}")
|
13 |
+
actual_str = str(actual)
|
14 |
+
if expected_substring in actual_str:
|
15 |
+
log(f"[TEST] {name:<45} ✅")
|
16 |
+
test_results.append((name, True))
|
17 |
+
else:
|
18 |
+
log(f"[TEST] {name:<45} ❌ — Beklenen: {expected_substring}, Gelen: {actual_str[:100]}...")
|
19 |
+
test_results.append((name, False))
|
20 |
+
|
21 |
+
def summarize_tests():
|
22 |
+
total = len(test_results)
|
23 |
+
success = sum(1 for _, ok in test_results if ok)
|
24 |
+
fail = total - success
|
25 |
+
log("🧾 TEST SONUCU ÖZETİ")
|
26 |
+
log(f"🔢 Toplam Test : {total}")
|
27 |
+
log(f"✅ Başarılı : {success}")
|
28 |
+
log(f"❌ Başarısız : {fail}")
|
29 |
+
|
30 |
+
def run_all_tests():
|
31 |
+
try:
|
32 |
+
log("🚀 Test süreci başlatıldı.")
|
33 |
+
|
34 |
+
# ✅ Yeni session başlatırken project_name gönderiyoruz
|
35 |
+
response = requests.post(f"{BASE_URL}/start_chat?project_name={PROJECT_NAME}")
|
36 |
+
response.raise_for_status()
|
37 |
+
session_id = response.json().get("session_id")
|
38 |
+
if not session_id:
|
39 |
+
raise Exception("Session ID alınamadı.")
|
40 |
+
|
41 |
+
headers = {"X-Session-ID": session_id}
|
42 |
+
|
43 |
+
# 1️⃣ LLM fallback testi
|
44 |
+
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "bilinmeyen bir soru"}, headers=headers)
|
45 |
+
assert_test("LLM fallback", r.json(), "maalesef")
|
46 |
+
|
47 |
+
# 2️⃣ Eksik parametre testi (döviz kuru)
|
48 |
+
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "döviz kuru nedir"}, headers=headers)
|
49 |
+
assert_test("Eksik parametre — currency", r.json(), "Lütfen currency")
|
50 |
+
|
51 |
+
# 3️⃣ Eksik parametre tamamlanınca tekrar deneme
|
52 |
+
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "dolar"}, headers=headers)
|
53 |
+
assert_test("Parametre tamamlandı — dolar", r.json(), "dolar kuru şu an")
|
54 |
+
|
55 |
+
# 4️⃣ Geçersiz parametre validasyonu
|
56 |
+
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "yenidolar kuru nedir"}, headers=headers)
|
57 |
+
assert_test("Geçersiz parametre — currency", r.json(), "Geçerli bir döviz")
|
58 |
+
|
59 |
+
# 5️⃣ Konu değişikliği → awaiting reset
|
60 |
+
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "hava nasıl"}, headers=headers)
|
61 |
+
assert_test("Konu değişikliği sonrası fallback", r.json(), "maalesef")
|
62 |
+
|
63 |
+
# 6️⃣ Yol durumu testi (eksik from_location)
|
64 |
+
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "yol durumu"}, headers=headers)
|
65 |
+
assert_test("Eksik parametre — from_location", r.json(), "Lütfen from_location")
|
66 |
+
|
67 |
+
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "Ankara"}, headers=headers)
|
68 |
+
assert_test("Eksik parametre — to_location", r.json(), "Lütfen to_location")
|
69 |
+
|
70 |
+
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "İstanbul"}, headers=headers)
|
71 |
+
assert_test("Parametre tamamlandı — yol durumu", r.json(), "trafik açık")
|
72 |
+
|
73 |
+
summarize_tests()
|
74 |
+
|
75 |
+
except Exception as e:
|
76 |
log(f"❌ run_all_tests sırasında hata oluştu: {e}")
|