Commit 14e760ac authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

util/tx: if we get an engine, just use a transaction for the method scope

Hence we can drop the _testing hack and end users
will feel less punished.
parent e704b9c90e0a
......@@ -43,9 +43,7 @@ def tsh(request, engine):
if namespace == 'zzz':
Snapshot._max_bucket_size = 5
tsh = tsio.TimeSerie(namespace)
tsh._testing = True
yield tsh
yield tsio.TimeSerie(namespace)
@pytest.fixture(scope='session')
......
......@@ -27,18 +27,11 @@ def utcdt(*dt):
return pd.Timestamp(datetime(*dt), tz='UTC')
def test_in_tx(engine):
tsh = TimeSerie()
def test_in_tx(tsh, engine):
assert tsh.type(engine, 'foo') == 'primary'
with pytest.raises(TypeError) as err:
tsh.insert(engine, 0, 0, 0)
assert err.value.args[0] == 'You must use a transaction object'
with engine.connect() as cn:
with pytest.raises(TypeError) as err:
tsh.insert(cn, 0, 0, 0)
tsh.insert(engine.connect(), 0, 0, 0)
assert err.value.args[0] == 'You must use a transaction object'
ts = genserie(datetime(2017, 10, 28, 23),
......
......@@ -236,9 +236,12 @@ def tx(func):
" a decorator to check that the first method argument is a transaction "
def check_tx_and_call(self, cn, *a, **kw):
# safety belt to make sure important api points are tx-safe
if isinstance(cn, Engine) or not cn.in_transaction():
if not getattr(self, '_testing', False):
if not isinstance(cn, Engine):
if not cn.in_transaction():
raise TypeError('You must use a transaction object')
else:
with cn.begin() as txcn:
return func(self, txcn, *a, **kw)
return func(self, cn, *a, **kw)
return check_tx_and_call
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment