mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
bdf59eb7db
commit
527cec66b0
3 changed files with 100 additions and 0 deletions
|
|
@ -655,3 +655,53 @@ def test_tilde_encoding(original, expected):
|
|||
def test_truncate_url(url, length, expected):
|
||||
actual = utils.truncate_url(url, length)
|
||||
assert actual == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"pairs,expected",
|
||||
(
|
||||
# Simple nested objects
|
||||
([("a", "b")], {"a": "b"}),
|
||||
([("a.b", "c")], {"a": {"b": "c"}}),
|
||||
# JSON literals
|
||||
([("a.b", "true")], {"a": {"b": True}}),
|
||||
([("a.b", "false")], {"a": {"b": False}}),
|
||||
([("a.b", "null")], {"a": {"b": None}}),
|
||||
([("a.b", "1")], {"a": {"b": 1}}),
|
||||
([("a.b", "1.1")], {"a": {"b": 1.1}}),
|
||||
# Nested JSON literals
|
||||
([("a.b", '{"foo": "bar"}')], {"a": {"b": {"foo": "bar"}}}),
|
||||
([("a.b", "[1, 2, 3]")], {"a": {"b": [1, 2, 3]}}),
|
||||
# JSON strings are preserved
|
||||
([("a.b", '"true"')], {"a": {"b": "true"}}),
|
||||
([("a.b", '"[1, 2, 3]"')], {"a": {"b": "[1, 2, 3]"}}),
|
||||
# Later keys over-ride the previous
|
||||
(
|
||||
[
|
||||
("a", "b"),
|
||||
("a.b", "c"),
|
||||
],
|
||||
{"a": {"b": "c"}},
|
||||
),
|
||||
(
|
||||
[
|
||||
("settings.trace_debug", "true"),
|
||||
("plugins.datasette-ripgrep.path", "/etc"),
|
||||
("settings.trace_debug", "false"),
|
||||
],
|
||||
{
|
||||
"settings": {
|
||||
"trace_debug": False,
|
||||
},
|
||||
"plugins": {
|
||||
"datasette-ripgrep": {
|
||||
"path": "/etc",
|
||||
}
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_pairs_to_nested_config(pairs, expected):
|
||||
actual = utils.pairs_to_nested_config(pairs)
|
||||
assert actual == expected
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue