Skip to content

Commit

Permalink
chore: update snapshots to new format (#707)
Browse files Browse the repository at this point in the history
* chore: update snapshots to new format

* fix: take 2

* fix: new lock file

* chore: update snapshots

* chore: update 3.12 snapshots

* fix: mock sqlite3 fn completer

* fix #706: mock completers

* fix: lint

* fix: wait for data_catalog snap; focus on editor when switched

* fix: refactor node expansion in member autocomplete test
  • Loading branch information
tconbeer authored Dec 19, 2024
1 parent 434775d commit 4b107c7
Show file tree
Hide file tree
Showing 16 changed files with 10,215 additions and 10,091 deletions.
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ boto3-stubs = "^1.34.23"
[tool.poetry.group.test.dependencies]
pytest = ">=7.3.1,<9.0.0"
pytest-asyncio = "^0.21.0"
pytest-textual-snapshot = { git = "https://github.com/tconbeer/pytest-textual-snapshot.git", branch = "main" }
pytest-textual-snapshot = { git = "https://github.com/tconbeer/pytest-textual-snapshot.git" }
# extension tests require consistent version of duckdb.
duckdb = "1.0.0"

Expand Down
1 change: 1 addition & 0 deletions src/harlequin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ def update_internal_editor_state(
self.editor = message.active_editor
else:
self.editor = self.editor_collection.current_editor
self.editor.focus()

def on_text_area_selection_changed(self) -> None:
if self._validate_selection():
Expand Down
5,154 changes: 2,577 additions & 2,577 deletions tests/functional_tests/__snapshots__/test_app.ambr

Large diffs are not rendered by default.

2,688 changes: 1,344 additions & 1,344 deletions tests/functional_tests/__snapshots__/test_data_catalog.ambr

Large diffs are not rendered by default.

2,836 changes: 1,418 additions & 1,418 deletions tests/functional_tests/__snapshots__/test_export.ambr

Large diffs are not rendered by default.

194 changes: 97 additions & 97 deletions tests/functional_tests/__snapshots__/test_help_screen.ambr

Large diffs are not rendered by default.

370 changes: 185 additions & 185 deletions tests/functional_tests/__snapshots__/test_history_screen.ambr

Large diffs are not rendered by default.

1,530 changes: 765 additions & 765 deletions tests/functional_tests/__snapshots__/test_keys_app.ambr

Large diffs are not rendered by default.

1,752 changes: 876 additions & 876 deletions tests/functional_tests/__snapshots__/test_layout.ambr

Large diffs are not rendered by default.

3,007 changes: 1,503 additions & 1,504 deletions tests/functional_tests/__snapshots__/test_query_editor.ambr

Large diffs are not rendered by default.

808 changes: 404 additions & 404 deletions tests/functional_tests/__snapshots__/test_results_viewer.ambr

Large diffs are not rendered by default.

1,810 changes: 905 additions & 905 deletions tests/functional_tests/__snapshots__/test_run_query_bar.ambr

Large diffs are not rendered by default.

112 changes: 112 additions & 0 deletions tests/functional_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from textual.worker import WorkerCancelled

from harlequin.app import Harlequin
from harlequin.autocomplete import HarlequinCompletion


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -35,6 +36,117 @@ def mock_config_loader(monkeypatch: pytest.MonkeyPatch) -> None:
)


@pytest.fixture(autouse=True)
def mock_completions(monkeypatch: pytest.MonkeyPatch) -> None:
KEYWORDS = [
"abort",
"all",
"alter",
"always",
"analyze",
"and",
"as",
"asc",
"begin",
"between",
"by",
"cascade",
"case",
"column",
"commit",
"create",
"database",
"delete",
"desc",
"distinct",
"drop",
"else",
"end",
"explain",
"from",
"group",
"groups",
"having",
"in",
"inner",
"insert",
"intersect",
"into",
"is",
"join",
"left",
"like",
"limit",
"null",
"on",
"order",
"outer",
"over",
"partition",
"row",
"savepoint",
"select",
"set",
"table",
"temp",
"temporary",
"then",
"union",
"update",
"using",
"values",
"view",
"when",
"where",
"window",
]

FUNCTIONS = [
("array_select", "fn"),
("count", "agg"),
("greatest", "fn"),
("least", "fn"),
("list_select", "fn"),
("sqrt", "fn"),
("sum", "agg"),
]

keyword_completions = [
HarlequinCompletion(
label=kw_name, type_label="kw", value=kw_name, priority=100, context=None
)
for kw_name in KEYWORDS
]

function_completions = [
HarlequinCompletion(
label=label, type_label=type_label, value=label, priority=1000, context=None
)
for label, type_label in FUNCTIONS
]

completions = [*keyword_completions, *function_completions]
duckdb_completions = [
(
completion.label,
completion.type_label,
completion.priority,
completion.context,
)
for completion in completions
]
monkeypatch.setattr(
"harlequin_sqlite.adapter.get_completion_data",
lambda *_: completions,
raising=True,
)
monkeypatch.setattr(
"harlequin_duckdb.adapter.get_completion_data",
lambda *_: duckdb_completions,
raising=True,
)


@pytest.fixture
def mock_pyperclip(monkeypatch: pytest.MonkeyPatch) -> MagicMock:
mock = MagicMock()
Expand Down
2 changes: 1 addition & 1 deletion tests/functional_tests/test_data_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ async def test_data_catalog(
await pilot.pause()
catalog = app.data_catalog
assert not catalog.database_tree.show_root
snap_results.append(await app_snapshot(app, "Initialization"))

# this test app has two databases attached.
dbs = catalog.database_tree.root.children
Expand All @@ -71,6 +70,7 @@ async def test_data_catalog(
await pilot.pause(0.1)
assert len(dbs[0].children) == 2
assert all(not node.is_expanded for node in dbs[0].children)
snap_results.append(await app_snapshot(app, "Initialization"))

assert str(dbs[1].label) == "tiny db"
assert dbs[0].is_expanded is False
Expand Down
32 changes: 22 additions & 10 deletions tests/functional_tests/test_query_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

import pytest
from textual.widgets.text_area import Selection
from textual.widgets.tree import TreeNode

from harlequin import Harlequin
from harlequin.catalog import CatalogItem


def transaction_button_visible(app: Harlequin) -> bool:
Expand Down Expand Up @@ -114,10 +116,6 @@ async def test_multiple_buffers(
assert all(snap_results)


@pytest.mark.xfail(
sys.platform in ("win32", "darwin"),
reason="Scroll bar is a different size.",
)
@pytest.mark.asyncio
async def test_word_autocomplete(
app_all_adapters: Harlequin,
Expand All @@ -131,6 +129,15 @@ async def test_word_autocomplete(
while app.editor is None or app.editor_collection.word_completer is None:
await pilot.pause()

# we need to let the data catalog load the root's children
while (
app.data_catalog.database_tree.loading
or not app.data_catalog.database_tree.root.children
):
await pilot.pause()

app.editor.focus()

await pilot.press("s")
await pilot.pause()
await wait_for_workers(app)
Expand Down Expand Up @@ -189,27 +196,32 @@ async def test_member_autocomplete(
async with app.run_test() as pilot:
await wait_for_workers(app)

async def _expand_and_wait(node: TreeNode[CatalogItem]) -> None:
node.expand()
while not node.children:
if getattr(node.data, "loaded", True):
break
await pilot.pause()

# we need to expand the data catalog to load items into the completer
while (
app.data_catalog.database_tree.loading
or not app.data_catalog.database_tree.root.children
):
await pilot.pause()
for db_node in app.data_catalog.database_tree.root.children:
db_node.expand()
while not db_node.children:
if getattr(db_node.data, "loaded", True):
break
await pilot.pause()
await _expand_and_wait(db_node)
for schema_node in db_node.children:
schema_node.expand()
await _expand_and_wait(schema_node)
await pilot.pause(1)

# now the completer should be populated
while app.editor is None or app.editor_collection.member_completer is None:
await pilot.pause()

app.editor.text = '"drivers"'
app.editor.selection = Selection((0, 9), (0, 9))
app.editor.focus()

await pilot.press("full_stop")
await pilot.pause()
Expand Down

0 comments on commit 4b107c7

Please sign in to comment.