Skip to content

Commit daf2a24

Browse files
committed
Unit tests covering column_affinity, refs #92
1 parent 1125460 commit daf2a24

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/test_column_affinity.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import pytest
2+
from sqlite_utils.utils import column_affinity
3+
4+
EXAMPLES = [
5+
# Examples from https://www.sqlite.org/datatype3.html#affinity_name_examples
6+
("INT", int),
7+
("INTEGER", int),
8+
("TINYINT", int),
9+
("SMALLINT", int),
10+
("MEDIUMINT", int),
11+
("BIGINT", int),
12+
("UNSIGNED BIG INT", int),
13+
("INT2", int),
14+
("INT8", int),
15+
("CHARACTER(20)", str),
16+
("VARCHAR(255)", str),
17+
("VARYING CHARACTER(255)", str),
18+
("NCHAR(55)", str),
19+
("NATIVE CHARACTER(70)", str),
20+
("NVARCHAR(100)", str),
21+
("TEXT", str),
22+
("CLOB", str),
23+
("BLOB", bytes),
24+
("REAL", float),
25+
("DOUBLE", float),
26+
("DOUBLE PRECISION", float),
27+
("FLOAT", float),
28+
# Numeric, treated as float:
29+
("NUMERIC", float),
30+
("DECIMAL(10,5)", float),
31+
("BOOLEAN", float),
32+
("DATE", float),
33+
("DATETIME", float),
34+
]
35+
36+
37+
@pytest.mark.parametrize("column_def,expected_type", EXAMPLES)
38+
def test_column_affinity(column_def, expected_type):
39+
assert expected_type is column_affinity(column_def)
40+
41+
42+
@pytest.mark.parametrize("column_def,expected_type", EXAMPLES)
43+
def test_columns_dict(fresh_db, column_def, expected_type):
44+
fresh_db.conn.execute("create table foo (col {})".format(column_def))
45+
assert {"col": expected_type} == fresh_db["foo"].columns_dict

0 commit comments

Comments
 (0)