File: test_suggest_column_types.py

package info (click to toggle)
sqlite-utils 4.0~a0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,320 kB
  • sloc: python: 14,310; makefile: 33; ansic: 26; javascript: 21; sh: 5
file content (28 lines) | stat: -rw-r--r-- 989 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pytest
from collections import OrderedDict
from sqlite_utils.utils import suggest_column_types


@pytest.mark.parametrize(
    "records,types",
    [
        ([{"a": 1}], {"a": int}),
        ([{"a": 1}, {"a": None}], {"a": int}),
        ([{"a": "baz"}], {"a": str}),
        ([{"a": "baz"}, {"a": None}], {"a": str}),
        ([{"a": 1.2}], {"a": float}),
        ([{"a": 1.2}, {"a": None}], {"a": float}),
        ([{"a": [1]}], {"a": str}),
        ([{"a": [1]}, {"a": None}], {"a": str}),
        ([{"a": (1,)}], {"a": str}),
        ([{"a": {"b": 1}}], {"a": str}),
        ([{"a": {"b": 1}}, {"a": None}], {"a": str}),
        ([{"a": OrderedDict({"b": 1})}], {"a": str}),
        ([{"a": 1}, {"a": 1.1}], {"a": float}),
        ([{"a": b"b"}], {"a": bytes}),
        ([{"a": b"b"}, {"a": None}], {"a": bytes}),
        ([{"a": "a", "b": None}], {"a": str, "b": str}),
    ],
)
def test_suggest_column_types(records, types):
    assert types == suggest_column_types(records)