Fix loom_store_path in test_backends.
# limitations under the License.
import pytest
+import shutil
import tempfile
import bayeslite
@@ -45,9 +46,11 @@ examples = {
'CREATE GENERATOR p_cc FOR p USING cgpm()',
'CREATE GENERATOR p_cc FOR p USING crosscat',
'CREATE GENERATOR p_cc FOR p USING cgpm ...' ,
+ lambda mm: None,
),
'loom': (
- lambda: LoomBackend(loom_store_path=''),
+ lambda: LoomBackend(
+ loom_store_path=tempfile.mkdtemp(prefix='bayeslite-loom')),
't',
'CREATE TABLE t(x NUMERIC, y CYCLIC, z NOMINAL)',
'INSERT INTO t (x, y, z) VALUES (?, ?, ?)',
@@ -64,6 +67,7 @@ examples = {
'CREATE GENERATOR p_lm FOR p USING loom()',
'CREATE GENERATOR p_lm FOR p USING loom ...',
'CREATE GENERATOR p_lm FOR p USING loom ...',
+ lambda mm: shutil.rmtree(mm.loom_store_path)
),
'iid_gaussian': (
lambda: StdNormalBackend(seed=0),
@@ -77,7 +81,8 @@ examples = {
'CREATE GENERATOR p_sn FOR p USING std_normal()',
# XXX Invent something that fails for backend-specific reasons here.
'CREATE GENERATOR p_sn FOR p USING std_normal ...',
- 'CREATE GENERATOR p_sn FOR p USING std_normal ...'
+ 'CREATE GENERATOR p_sn FOR p USING std_normal ...',
+ lambda mm: None,
),
}
@@ -101,12 +106,13 @@ def test_example(persist, exname):
def _test_example(bdb, exname):
- mm, t, t_sql, data_sql, data, p, g, p_bql, g_bql, g_bqlbad0, g_bqlbad1 = \
- examples[exname]
+ (mm, t, t_sql, data_sql, data, p, g, p_bql, g_bql, g_bqlbad0, g_bqlbad1,
+ cleanup) = examples[exname]
qt = bql_quote_name(t)
qg = bql_quote_name(g)
- bayeslite.bayesdb_register_backend(bdb, mm())
+ metamodel = mm()
+ bayeslite.bayesdb_register_backend(bdb, metamodel)
# Create a table.
assert not core.bayesdb_has_table(bdb, t)
@@ -211,12 +217,12 @@ def _test_example(bdb, exname):
# loom does not allow model numbers to be specified in analyze models
assert exname == 'loom'
-
def _retest_example(bdb, exname):
- mm, t, t_sql, data_sql, data, p, g, p_bql, g_bql, g_bqlbad0, g_bqlbad1 = \
- examples[exname]
+ (mm, t, t_sql, data_sql, data, p, g, p_bql, g_bql, g_bqlbad0, g_bqlbad1,
+ cleanup) = examples[exname]
qg = bql_quote_name(g)
+ metamodel = mm()
bayeslite.bayesdb_register_backend(bdb, mm())
p_id = core.bayesdb_get_population(bdb, p)
@@ -234,3 +240,6 @@ def _retest_example(bdb, exname):
except bayeslite.BQLError, e:
# loom does not allow model numbers to be specified in analyze models
assert exname == 'loom'
+
+ # Run backend-specific cleanup.
+ cleanup(metamodel)
