Skip to content

Commit

Permalink
fix: mock sqlite3 fn completer
Browse files Browse the repository at this point in the history
  • Loading branch information
tconbeer committed Dec 19, 2024
1 parent 9ef02eb commit 2ddd55f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/harlequin_sqlite/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

from harlequin.autocomplete.completion import HarlequinCompletion

def _get_functions(conn: sqlite3.Connection) -> list[tuple[str, str]]:
return conn.execute(
"""
select distinct
name as label,
case when type = 'w' then 'agg' else 'fn' end as type_label
from pragma_function_list
order by name asc
"""
).fetchall()

def get_completion_data(conn: sqlite3.Connection) -> list[HarlequinCompletion]:
KEYWORDS = [
Expand Down Expand Up @@ -217,15 +227,7 @@ def get_completion_data(conn: sqlite3.Connection) -> list[HarlequinCompletion]:
"wal_checkpoint",
]

function_data = conn.execute(
"""
select distinct
name as label,
case when type = 'w' then 'agg' else 'fn' end as type_label
from pragma_function_list
order by name asc
"""
).fetchall()
function_data = _get_functions(conn)

keyword_completions = [
HarlequinCompletion(
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sqlite3
import sys
from pathlib import Path
from unittest.mock import MagicMock

import duckdb
import pytest
Expand Down
12 changes: 12 additions & 0 deletions tests/functional_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ def mock_config_loader(monkeypatch: pytest.MonkeyPatch) -> None:
"harlequin.cli.get_config_for_profile", lambda **_: (dict(), [])
)

@pytest.fixture(autouse=True)
def mock_sqlite_completions(monkeypatch: pytest.MonkeyPatch) -> None:
functions = [
("sum", "agg"),
("count", "agg"),
("least", "fn"),
("greatest", "fn"),
]
monkeypatch.setattr(
"harlequin_sqlite.completions._get_functions", lambda *_: functions
)


@pytest.fixture
def mock_pyperclip(monkeypatch: pytest.MonkeyPatch) -> MagicMock:
Expand Down

0 comments on commit 2ddd55f

Please sign in to comment.