-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconftest.py
More file actions
70 lines (52 loc) · 1.78 KB
/
conftest.py
File metadata and controls
70 lines (52 loc) · 1.78 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
import json
import os
import sqlite3
import pytest
import llmsql.inference.inference as inference
@pytest.fixture
def temp_dir(tmp_path):
return tmp_path
@pytest.fixture
def dummy_db_file(tmp_path):
"""Create a temporary SQLite DB file for testing, cleanup afterwards."""
db_path = tmp_path / "test.db"
conn = sqlite3.connect(db_path)
conn.execute("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)")
conn.execute("INSERT INTO test (name) VALUES ('Alice'), ('Bob')")
conn.commit()
conn.close()
yield str(db_path)
# cleanup
if os.path.exists(db_path):
os.remove(db_path)
@pytest.fixture
def mock_llm(monkeypatch):
"""Mock vLLM LLM to avoid GPU/model loading."""
class DummyOutput:
def __init__(self, text="SELECT 1"):
self.outputs = [type("Obj", (), {"text": text})()]
class DummyLLM:
def generate(self, prompts, sampling_params):
return [DummyOutput(f"-- SQL for: {p}") for p in prompts]
monkeypatch.setattr(inference, "LLM", lambda **_: DummyLLM())
return DummyLLM()
@pytest.fixture
def fake_jsonl_files(tmp_path):
"""Create fake questions.jsonl and tables.jsonl."""
qpath = tmp_path / "questions.jsonl"
tpath = tmp_path / "tables.jsonl"
questions = [
{"question_id": "q1", "question": "How many users?", "table_id": "t1"},
{"question_id": "q2", "question": "List names", "table_id": "t1"},
]
tables = [
{
"table_id": "t1",
"header": ["id", "name"],
"types": ["int", "text"],
"rows": [[1, "Alice"], [2, "Bob"]],
}
]
qpath.write_text("\n".join(json.dumps(q) for q in questions))
tpath.write_text("\n".join(json.dumps(t) for t in tables))
return str(qpath), str(tpath)