mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
?_json_infinity=1 for handling Infinity/-Infinity - fixes #332
This commit is contained in:
parent
b320f58d13
commit
700d83d8ad
5 changed files with 64 additions and 2 deletions
|
|
@ -367,6 +367,15 @@ CREATE TABLE [select] (
|
|||
);
|
||||
INSERT INTO [select] VALUES ('group', 'having', 'and');
|
||||
|
||||
CREATE TABLE infinity (
|
||||
value REAL
|
||||
);
|
||||
INSERT INTO infinity VALUES
|
||||
(1e999),
|
||||
(-1e999),
|
||||
(1.5)
|
||||
;
|
||||
|
||||
CREATE TABLE facet_cities (
|
||||
id integer primary key,
|
||||
name text
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ def test_homepage(app_client):
|
|||
assert response.json.keys() == {'fixtures': 0}.keys()
|
||||
d = response.json['fixtures']
|
||||
assert d['name'] == 'fixtures'
|
||||
assert d['tables_count'] == 19
|
||||
assert d['tables_count'] == 20
|
||||
|
||||
|
||||
def test_database_page(app_client):
|
||||
|
|
@ -153,6 +153,15 @@ def test_database_page(app_client):
|
|||
'label_column': None,
|
||||
'fts_table': None,
|
||||
'primary_keys': ['pk'],
|
||||
}, {
|
||||
"name": "infinity",
|
||||
"columns": ["value"],
|
||||
"count": 3,
|
||||
"primary_keys": [],
|
||||
"label_column": None,
|
||||
"hidden": False,
|
||||
"fts_table": None,
|
||||
"foreign_keys": {"incoming": [], "outgoing": []}
|
||||
}, {
|
||||
'columns': ['id', 'content', 'content2'],
|
||||
'name': 'primary_key_multiple_columns',
|
||||
|
|
@ -1281,3 +1290,21 @@ def test_config_force_https_urls():
|
|||
"toggle_url"
|
||||
].startswith("https://")
|
||||
assert response.json["suggested_facets"][0]["toggle_url"].startswith("https://")
|
||||
|
||||
|
||||
def test_infinity_returned_as_null(app_client):
|
||||
response = app_client.get("/fixtures/infinity.json?_shape=array")
|
||||
assert [
|
||||
{"rowid": 1, "value": None},
|
||||
{"rowid": 2, "value": None},
|
||||
{"rowid": 3, "value": 1.5}
|
||||
] == response.json
|
||||
|
||||
|
||||
def test_infinity_returned_as_invalid_json_if_requested(app_client):
|
||||
response = app_client.get("/fixtures/infinity.json?_shape=array&_json_infinity=1")
|
||||
assert [
|
||||
{"rowid": 1, "value": float("inf")},
|
||||
{"rowid": 2, "value": float("-inf")},
|
||||
{"rowid": 3, "value": 1.5}
|
||||
] == response.json
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue