utils/sql_drills/sql_drills/tests/test_lc_run_inputs.py
Krzysztof kuhy Rudnicki c29d0989dd Clear inherited CI debt in the Python libs
main was red on file length, the noqa ban, codespell, test naming and
dart coverage; this change touches every one of those jobs.

- sickdays: set_enabled is keyword-only; the panel test splits in two
  with shared probes; the sync wire format moves to DOCS-sync.md.
- earned_time: _focus types the project as a Protocol, no noqa; the
  gate-maturity section moves to DOCS-maturity.md; codespell knows the
  `checkin` event name.
- focus_project: real fixes for every noqa (local-day clocks, typed
  fakes, logged broad catches, split helpers). The public API that
  focus-guard calls keeps its signatures; their PLR0913 exemption
  lives in pyproject with the reason, not in noqa.
- crdt-sync: pylint gets nacl/argon2, docstrings, and allows the
  public E2eLayout.of; _blobs moves to _e2e_blobs.py.
- crdt_sync_dart: Argon2Params and the header errors move to
  e2e_params.dart (re-exported); tests split and reach 100% lines.
- sql_drills: test helpers get a leading underscore, as in earned_time.

Todo: fda71ed1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 08:58:01 +01:00

83 lines
1.9 KiB
Python

"""``run_problem``: several examples, unknown input, slug/URL resolution."""
from __future__ import annotations
from typing import TYPE_CHECKING, cast
import pytest
import sql_drills as sd
from sql_drills.tests._stubs import GOOD_ROWS, MONTHS, done, install
from sql_drills.tests._synthetic import PIVOT
if TYPE_CHECKING:
from sql_drills._dialect import Dialect
def test_every_example_runs_in_its_own_sandbox(monkeypatch: pytest.MonkeyPatch) -> None:
text = """Example 1:
Input:
T table:
+---+
| a |
+---+
| 1 |
+---+
Output:
+---+
| a |
+---+
| 1 |
+---+
Example 2:
Input:
T table:
+---+
| a |
+---+
| 2 |
+---+
Output:
+---+
| a |
+---+
| 2 |
+---+
"""
schemas, boxes = install(monkeypatch, done(["a"], [["1"]]))
first, second = sd.run_problem(text, "x", "mysql")
assert first.match
assert not second.match
assert len(boxes) == 2
assert sum(s.startswith("CREATE TABLE") for s in schemas) == 2
def test_unknown_dialect_is_rejected_before_anything_runs() -> None:
with pytest.raises(sd.DialectError):
sd.run_problem("Example 1:", "x", cast("Dialect", "oracle"))
def test_statement_without_examples_raises(monkeypatch: pytest.MonkeyPatch) -> None:
with pytest.raises(sd.NoExamplesError):
sd.run_problem("nothing to see here, really", "x", "mysql")
@pytest.mark.parametrize(
"arg",
[
"pivot-shipments",
"https://leetcode.com/problems/pivot-shipments/description/",
],
)
def test_slug_and_url_are_fetched(monkeypatch: pytest.MonkeyPatch, arg: str) -> None:
asked: list[tuple[str, str]] = []
def fetch(slug: str, dialect: str) -> str:
asked.append((slug, dialect))
return PIVOT
install(monkeypatch, done(["id", *MONTHS], GOOD_ROWS))
(res,) = sd.run_problem(arg, "x", "postgresql", fetch=fetch)
assert res.match
assert asked == [("pivot-shipments", "postgresql")]