Skip to content

Commit e3b8dc8

Browse files
Merge pull request #13 from LLMSQL/8-add-basic-tests
basic tests added with codecov action and .yml
2 parents 852fdac + f5762d0 commit e3b8dc8

File tree

11 files changed

+497
-178
lines changed

11 files changed

+497
-178
lines changed

.github/workflows/tests.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.11"
20+
21+
- name: Install PDM
22+
run: pip install pdm
23+
24+
- name: Cache PDM packages
25+
uses: actions/cache@v4
26+
with:
27+
path: ~/.cache/pdm
28+
key: ${{ runner.os }}-pdm-${{ hashFiles('pdm.lock') }}
29+
restore-keys: |
30+
${{ runner.os }}-pdm-
31+
32+
- name: Install dependencies (with dev)
33+
run: pdm install --with dev
34+
35+
- name: Run tests with coverage
36+
run: PYTHONPATH=. pdm run pytest --cov=llmsql --cov-report=xml --maxfail=1 --disable-warnings -v
37+
38+
- name: Upload coverage to Codecov
39+
uses: codecov/codecov-action@v4
40+
with:
41+
token: ${{ secrets.CODECOV_TOKEN }}
42+
files: ./coverage.xml
43+
flags: unittests
44+
fail_ci_if_error: true

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ dataset/sqlite_tables.db
55
dist/
66

77
*.egg-info/
8-
.pdm-python
8+
.pdm-python
9+
.vscode

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[![codecov](https://codecov.io/gh/LLMSQL/llmsql-benchmark/branch/main/graph/badge.svg)](https://codecov.io/gh/LLMSQL/llmsql-benchmark)
2+
3+
14
# LLMSQL
25

36
Patched and improved version of the original large crowd-sourced dataset for developing natural language interfaces for relational databases, [WikiSQL](https://github.com/salesforce/WikiSQL).

llmsql/inference/inference.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def __init__(
9696
self.workdir_path.mkdir(parents=True, exist_ok=True)
9797
self.repo_id = "llmsql-bench/llmsql-benchmark"
9898

99+
if "device" not in llm_kwargs:
100+
llm_kwargs["device"] = "cuda" if torch.cuda.is_available() else "cpu"
101+
self.device = llm_kwargs["device"]
102+
99103
log.info(
100104
f"Loading vLLM model {model_name} with tensor_parallel_size={tensor_parallel_size}..."
101105
)

pdm.lock

Lines changed: 29 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ dev = [
5757
"pre-commit>=4.3.0",
5858
"types-tqdm>=4.67.0.20250809",
5959
"types-PyYAML>=6.0.12.20250915",
60+
"pytest-asyncio>=1.2.0",
6061
]
6162

6263
[tool.pdm]

requirements.txt

Lines changed: 0 additions & 176 deletions
This file was deleted.

tests/conftest.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import json
2+
import os
3+
import sqlite3
4+
5+
import pytest
6+
7+
import llmsql.inference.inference as inference
8+
9+
10+
@pytest.fixture
11+
def temp_dir(tmp_path):
12+
return tmp_path
13+
14+
15+
@pytest.fixture
16+
def dummy_db_file(tmp_path):
17+
"""Create a temporary SQLite DB file for testing, cleanup afterwards."""
18+
db_path = tmp_path / "test.db"
19+
conn = sqlite3.connect(db_path)
20+
conn.execute("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)")
21+
conn.execute("INSERT INTO test (name) VALUES ('Alice'), ('Bob')")
22+
conn.commit()
23+
conn.close()
24+
25+
yield str(db_path)
26+
27+
# cleanup
28+
if os.path.exists(db_path):
29+
os.remove(db_path)
30+
31+
32+
@pytest.fixture
33+
def mock_llm(monkeypatch):
34+
"""Mock vLLM LLM to avoid GPU/model loading."""
35+
36+
class DummyOutput:
37+
def __init__(self, text="SELECT 1"):
38+
self.outputs = [type("Obj", (), {"text": text})()]
39+
40+
class DummyLLM:
41+
def generate(self, prompts, sampling_params):
42+
return [DummyOutput(f"-- SQL for: {p}") for p in prompts]
43+
44+
monkeypatch.setattr(inference, "LLM", lambda **_: DummyLLM())
45+
return DummyLLM()
46+
47+
48+
@pytest.fixture
49+
def fake_jsonl_files(tmp_path):
50+
"""Create fake questions.jsonl and tables.jsonl."""
51+
qpath = tmp_path / "questions.jsonl"
52+
tpath = tmp_path / "tables.jsonl"
53+
54+
questions = [
55+
{"question_id": "q1", "question": "How many users?", "table_id": "t1"},
56+
{"question_id": "q2", "question": "List names", "table_id": "t1"},
57+
]
58+
tables = [
59+
{
60+
"table_id": "t1",
61+
"header": ["id", "name"],
62+
"types": ["int", "text"],
63+
"rows": [[1, "Alice"], [2, "Bob"]],
64+
}
65+
]
66+
67+
qpath.write_text("\n".join(json.dumps(q) for q in questions))
68+
tpath.write_text("\n".join(json.dumps(t) for t in tables))
69+
70+
return str(qpath), str(tpath)

0 commit comments

Comments
 (0)