Extracted detect_column_types as suggest_column_types, refs #81

This commit is contained in:
Simon Willison 2020-02-01 13:38:26 -08:00
commit 5ecf3ffdea
3 changed files with 47 additions and 27 deletions

View file

@ -0,0 +1,19 @@
import pytest
from sqlite_utils.utils import suggest_column_types
@pytest.mark.parametrize(
"records,types",
[
([{"a": 1}], {"a": int}),
([{"a": "baz"}], {"a": str}),
([{"a": 1.2}], {"a": float}),
([{"a": [1]}], {"a": str}),
([{"a": (1,)}], {"a": str}),
([{"a": {"b": 1}}], {"a": str}),
([{"a": 1}, {"a": 1.1}], {"a": float}),
([{"a": b"b"}], {"a": bytes}),
],
)
def test_suggest_column_types(records, types):
assert types == suggest_column_types(records)