Add coverage for GUESS SCHEMA FOR t.
@@ -19,9 +19,11 @@ import math
import pytest
import bayeslite
-from bayeslite.metamodels.crosscat import CrosscatMetamodel
-from bayeslite.guess import bayesdb_guess_stattypes
+
from bayeslite.guess import bayesdb_guess_population
+from bayeslite.guess import bayesdb_guess_stattypes
+from bayeslite.exception import BQLError
+from bayeslite.metamodels.crosscat import CrosscatMetamodel
import crosscat.LocalEngine
@@ -153,6 +155,23 @@ def test_guess_population():
(1, None, 2, 'z', 'numerical'),
]
+def test_guess_schema():
+ bdb = bayeslite.bayesdb_open(builtin_metamodels=False)
+ bdb.sql_execute('CREATE TABLE t(x NUMERIC, y NUMERIC, z NUMERIC)')
+ a_z = range(ord('a'), ord('z') + 1)
+ aa_zz = ((c, d) for c in a_z for d in a_z)
+ data = ((chr(c) + chr(d), (c + d) % 2, math.sqrt(c + d)) for c, d in aa_zz)
+ for row in data:
+ bdb.sql_execute('INSERT INTO t (x, y, z) VALUES (?, ?, ?)', row)
+ with pytest.raises(BQLError):
+ bdb.execute('GUESS SCHEMA FOR non_existant_table')
+ guess = bdb.execute('GUESS SCHEMA FOR t')
+ assert len(guess.description) == 3
+ assert guess.description[0][0] == u'column'
+ assert guess.description[1][0] == u'stattype'
+ assert guess.description[2][0] == u'reason'
+ assert len(guess.fetchall()) == 3
+
def isqrt(n):
x = n
y = (x + 1)//2
