Skip to content

Commit b41c5fc

Browse files
simonwclaude
andauthored
Test _shape=arrays and _shape=arrayfirst for rows containing infinity (#3073)
remove_infinites() returns a plain list for a sqlite3.Row that contains infinity. json_renderer() used to assert that every row was a sqlite3.Row or a dict, so those two shapes returned a 500 for such rows. 030d482 (#3005) changed those branches to treat anything that is not a dict as a sequence, which fixed this as a side effect but added no test for it. These tests cover query, table and row pages. Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
1 parent fc67ea9 commit b41c5fc

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎tests/test_table_api.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,39 @@ async def test_infinity_returned_as_null(ds_client):
12911291
]
12921292

12931293

1294+
@pytest.mark.asyncio
1295+
@pytest.mark.parametrize(
1296+
"path,shape,expected",
1297+
(
1298+
(
1299+
"/fixtures/-/query.json?sql=select+value+from+infinity+order+by+rowid",
1300+
"arrays",
1301+
[[None], [None], [1.5]],
1302+
),
1303+
(
1304+
"/fixtures/-/query.json?sql=select+value+from+infinity+order+by+rowid",
1305+
"arrayfirst",
1306+
[None, None, 1.5],
1307+
),
1308+
(
1309+
"/fixtures/infinity.json?_sort=rowid",
1310+
"arrays",
1311+
[[1, None], [2, None], [3, 1.5]],
1312+
),
1313+
("/fixtures/infinity.json?_sort=rowid", "arrayfirst", [1, 2, 3]),
1314+
("/fixtures/infinity/1.json?", "arrays", [[1, None]]),
1315+
("/fixtures/infinity/1.json?", "arrayfirst", [1]),
1316+
),
1317+
)
1318+
async def test_infinity_with_array_shapes(ds_client, path, shape, expected):
1319+
# remove_infinites() returns a plain list for a row containing infinity,
1320+
# so one response can mix those lists with sqlite3.Row objects
1321+
response = await ds_client.get(f"{path}&_shape={shape}")
1322+
assert response.status_code == 200
1323+
data = response.json()
1324+
assert (data["rows"] if shape == "arrays" else data) == expected
1325+
1326+
12941327
@pytest.mark.asyncio
12951328
async def test_infinity_returned_as_invalid_json_if_requested(ds_client):
12961329
response = await ds_client.get(

0 commit comments

Comments
 (0)