mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-21 07:52:27 +01:00
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>
74 lines
2.0 KiB
Python
74 lines
2.0 KiB
Python
"""Statement text to a runnable spec, on synthetic LeetCode-layout statements."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from sql_drills import _lc_problem as lp
|
|
from sql_drills.tests._synthetic import ORDERS, PIVOT
|
|
|
|
|
|
def test_pivot_example() -> None:
|
|
problem = lp.parse_problem(PIVOT)
|
|
assert problem.schemas["Shipments"] == [
|
|
("id", "int"),
|
|
("weight", "int"),
|
|
("month", "varchar"),
|
|
]
|
|
assert not problem.ordered
|
|
(example,) = problem.examples
|
|
dept = example.inputs["Shipments"]
|
|
assert dept.columns == ["id", "weight", "month"]
|
|
assert dept.rows[0] == ["1", "400", "Jan"]
|
|
assert len(dept.rows) == 5
|
|
assert example.expected.columns[:2] == ["id", "Jan_Weight"]
|
|
assert "..." in example.expected.columns
|
|
assert example.expected.rows[1] == ["2", "900", "null", "null", "...", "null"]
|
|
|
|
|
|
def test_orders_example_and_ddl() -> None:
|
|
problem = lp.parse_problem(ORDERS)
|
|
(example,) = problem.examples
|
|
assert example.expected.columns[0] == "month"
|
|
assert len(example.expected.rows) == 3
|
|
my = lp.schema_sql(problem, example, "mysql")
|
|
assert "CREATE TABLE `Orders`" in my
|
|
assert "`status` VARCHAR(255)" in my
|
|
assert "`placed_on` DATE" in my
|
|
assert "(121, " not in my # values are quoted literals
|
|
assert "('121', 'North', 'shipped', '1000', '2018-12-18')" in my
|
|
pg = lp.schema_sql(problem, example, "postgresql")
|
|
assert 'CREATE TABLE "orders"' in pg
|
|
assert '"placed_on" DATE' in pg
|
|
|
|
|
|
def test_schema_nulls_and_quotes() -> None:
|
|
text = """Table: T
|
|
|
|
+-------------+---------+
|
|
| Column Name | Type |
|
|
+-------------+---------+
|
|
| id | int |
|
|
| name | varchar |
|
|
+-------------+---------+
|
|
|
|
Example 1:
|
|
|
|
Input:
|
|
T table:
|
|
+----+------+
|
|
| id | name |
|
|
+----+------+
|
|
| 1 | null |
|
|
| 2 | it's |
|
|
+----+------+
|
|
Output:
|
|
+----+
|
|
| id |
|
|
+----+
|
|
| 2 |
|
|
+----+
|
|
"""
|
|
problem = lp.parse_problem(text)
|
|
sql = lp.schema_sql(problem, problem.examples[0], "mysql")
|
|
assert "('1', NULL)" in sql
|
|
assert "('2', 'it''s')" in sql
|