mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Removed units functionality and Pint dependency
Closes #2400, unblocks #2320
This commit is contained in:
parent
d444b6aad5
commit
39dfc7d7d7
14 changed files with 14 additions and 182 deletions
|
|
@ -379,7 +379,6 @@ METADATA = {
|
|||
],
|
||||
},
|
||||
"no_primary_key": {"sortable_columns": [], "hidden": True},
|
||||
"units": {"units": {"distance": "m", "frequency": "Hz"}},
|
||||
"primary_key_multiple_columns_explicit_label": {
|
||||
"label_column": "content2"
|
||||
},
|
||||
|
|
@ -507,16 +506,6 @@ CREATE TABLE "custom_foreign_key_label" (
|
|||
FOREIGN KEY ("foreign_key_with_custom_label") REFERENCES [primary_key_multiple_columns_explicit_label](id)
|
||||
);
|
||||
|
||||
CREATE TABLE units (
|
||||
pk integer primary key,
|
||||
distance int,
|
||||
frequency int
|
||||
);
|
||||
|
||||
INSERT INTO units VALUES (1, 1, 100);
|
||||
INSERT INTO units VALUES (2, 5000, 2500);
|
||||
INSERT INTO units VALUES (3, 100000, 75000);
|
||||
|
||||
CREATE TABLE tags (
|
||||
tag TEXT PRIMARY KEY
|
||||
);
|
||||
|
|
|
|||
|
|
@ -5,18 +5,21 @@ from datasette import tracer
|
|||
from datasette.utils import path_with_added_args
|
||||
from datasette.utils.asgi import asgi_send_json, Response
|
||||
import base64
|
||||
import pint
|
||||
import json
|
||||
import urllib
|
||||
|
||||
ureg = pint.UnitRegistry()
|
||||
import urllib.parse
|
||||
|
||||
|
||||
@hookimpl
|
||||
def prepare_connection(conn, database, datasette):
|
||||
def convert_units(amount, from_, to_):
|
||||
"""select convert_units(100, 'm', 'ft');"""
|
||||
return (amount * ureg(from_)).to(to_).to_tuple()[0]
|
||||
# Convert meters to feet
|
||||
if from_ == "m" and to_ == "ft":
|
||||
return amount * 3.28084
|
||||
# Convert feet to meters
|
||||
if from_ == "ft" and to_ == "m":
|
||||
return amount / 3.28084
|
||||
assert False, "Unsupported conversion"
|
||||
|
||||
conn.create_function("convert_units", 3, convert_units)
|
||||
|
||||
|
|
|
|||
|
|
@ -528,16 +528,6 @@ async def test_database_page(ds_client):
|
|||
},
|
||||
"private": False,
|
||||
},
|
||||
{
|
||||
"name": "units",
|
||||
"columns": ["pk", "distance", "frequency"],
|
||||
"primary_keys": ["pk"],
|
||||
"count": 3,
|
||||
"hidden": False,
|
||||
"fts_table": None,
|
||||
"foreign_keys": {"incoming": [], "outgoing": []},
|
||||
"private": False,
|
||||
},
|
||||
{
|
||||
"name": "no_primary_key",
|
||||
"columns": ["content", "a", "b", "c"],
|
||||
|
|
@ -1133,7 +1123,6 @@ async def test_config_json(config, expected):
|
|||
],
|
||||
},
|
||||
"no_primary_key": {"sortable_columns": [], "hidden": True},
|
||||
"units": {"units": {"distance": "m", "frequency": "Hz"}},
|
||||
"primary_key_multiple_columns_explicit_label": {
|
||||
"label_column": "content2"
|
||||
},
|
||||
|
|
@ -1168,7 +1157,6 @@ async def test_config_json(config, expected):
|
|||
"text",
|
||||
]
|
||||
},
|
||||
"units": {"units": {"distance": "m", "frequency": "Hz"}},
|
||||
# These one get redacted:
|
||||
"no_primary_key": "***",
|
||||
"primary_key_multiple_columns_explicit_label": "***",
|
||||
|
|
|
|||
|
|
@ -422,7 +422,6 @@ async def test_table_names(db):
|
|||
"table/with/slashes.csv",
|
||||
"complex_foreign_keys",
|
||||
"custom_foreign_key_label",
|
||||
"units",
|
||||
"tags",
|
||||
"searchable",
|
||||
"searchable_tags",
|
||||
|
|
|
|||
|
|
@ -424,8 +424,8 @@ def view_names_client(tmp_path_factory):
|
|||
(
|
||||
("/", "index"),
|
||||
("/fixtures", "database"),
|
||||
("/fixtures/units", "table"),
|
||||
("/fixtures/units/1", "row"),
|
||||
("/fixtures/facetable", "table"),
|
||||
("/fixtures/facetable/1", "row"),
|
||||
("/-/versions", "json_data"),
|
||||
("/fixtures/-/query?sql=select+1", "database"),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -720,22 +720,6 @@ async def test_view(ds_client):
|
|||
]
|
||||
|
||||
|
||||
@pytest.mark.xfail
|
||||
@pytest.mark.asyncio
|
||||
async def test_unit_filters(ds_client):
|
||||
response = await ds_client.get(
|
||||
"/fixtures/units.json?_shape=arrays&distance__lt=75km&frequency__gt=1kHz"
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
assert data["units"]["distance"] == "m"
|
||||
assert data["units"]["frequency"] == "Hz"
|
||||
|
||||
assert len(data["rows"]) == 1
|
||||
assert data["rows"][0][0] == 2
|
||||
|
||||
|
||||
def test_page_size_matching_max_returned_rows(
|
||||
app_client_returned_rows_matches_page_size,
|
||||
):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue