File: test_db_inference.py

package info (click to toggle)
python-petl 1.7.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,224 kB
  • sloc: python: 22,617; makefile: 109; xml: 9
file content (21 lines) | stat: -rw-r--r-- 597 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import pytest

from petl.io.db_create import make_sqlalchemy_column

try:
    import sqlalchemy  # noqa: F401
except ImportError as e:
    pytest.skip('SKIP generic DB inference tests: %s' % e, allow_module_level=True)
else:
    from sqlalchemy import JSON, Integer

def test_json_inference():
    data = [{'a': 1}, {'b': 2}, None]
    col = make_sqlalchemy_column(data, 'payload')
    assert col.name == 'payload'
    assert isinstance(col.type, JSON)

def test_int_inference():
    col = make_sqlalchemy_column([1, 2, 3], 'n')
    assert col.name == 'n'
    assert isinstance(col.type, Integer)