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

test/utils: provide an assertion for internal invariants

parent 52d655e6147c
......@@ -14,6 +14,7 @@ from tshistory.testutil import (
assert_hist,
assert_hist_equals,
assert_group_equals,
assert_structures,
genserie,
tempattr
)
......@@ -26,6 +27,7 @@ def utcdt(*dt):
def test_tstamp_roundtrip(engine, tsh):
assert_structures(engine, tsh)
ts = genserie(datetime(2017, 10, 28, 23),
'H', 4, tz='UTC')
ts.index = ts.index.tz_convert('Europe/Paris')
......@@ -103,9 +105,11 @@ insertion_date value_date
ival = tsh.interval(engine, 'tztest')
assert ival.left == pd.Timestamp('2017-10-28 23:00:00+0000', tz='UTC')
assert ival.right == pd.Timestamp('2017-10-29 04:00:00+0000', tz='UTC')
assert_structures(engine, tsh)
def test_differential(engine, tsh):
assert_structures(engine, tsh)
ts_begin = genserie(datetime(2010, 1, 1), 'D', 10)
tsh.insert(engine, ts_begin, 'ts_test', 'test')
......@@ -274,6 +278,8 @@ seriename table_name
""", tsh.get(cn, 'ts_mixte',
revision_date=datetime.now()))
assert_structures(engine, tsh)
def test_serie_metadata(engine, tsh):
serie = genserie(datetime(2010, 1, 1), 'D', 1, initval=[1])
......@@ -935,16 +941,7 @@ def test_serie_deletion(engine, tsh):
tsh.insert(engine, ts, 'keepme', 'Babar')
tsh.insert(engine, ts, 'deleteme', 'Celeste')
seriecount = engine.execute(
'select count(*) from {}.registry'.format(tsh.namespace)
).scalar()
csetcount = engine.execute(
'select count(*) from {}.changeset'.format(tsh.namespace)
).scalar()
csetcount2 = engine.execute(
'select count(*) from {}.changeset_series'.format(tsh.namespace)
).scalar()
assert csetcount == csetcount2
seriecount, csetcount, csetseriecount = assert_structures(engine, tsh)
with engine.connect() as cn:
tsh.delete(cn, 'deleteme')
......@@ -954,18 +951,10 @@ def test_serie_deletion(engine, tsh):
for entry in tsh.log(engine, names=('keepme', 'deleteme'))]
assert log == ['Babar', 'Babar']
csetcount3 = engine.execute(
'select count(*) from {}.changeset'.format(tsh.namespace)
).scalar()
csetcount4 = engine.execute(
'select count(*) from {}.changeset_series'.format(tsh.namespace)
).scalar()
seriecount2 = engine.execute(
'select count (*) from {}.registry'.format(tsh.namespace)
).scalar()
assert csetcount - csetcount3 == 2
assert csetcount2 - csetcount4 == 2
seriecount2, csetcount2, csetseriecount2 = assert_structures(engine, tsh)
assert csetcount - csetcount2 == 2
assert csetseriecount - csetseriecount2 == 2
assert seriecount - seriecount2 == 1
with pytest.raises(AssertionError) as werr:
......
......@@ -45,6 +45,20 @@ def assert_group_equals(g1, g2):
assert s1.equals(s2)
def assert_structures(engine, tsh):
seriecount = engine.execute(
'select count(*) from {}.registry'.format(tsh.namespace)
).scalar()
csetcount = engine.execute(
'select count(*) from {}.changeset'.format(tsh.namespace)
).scalar()
csetseriecount = engine.execute(
'select count(*) from {}.changeset_series'.format(tsh.namespace)
).scalar()
assert csetcount == csetseriecount
return seriecount, csetcount, csetseriecount
def genserie(start, freq, repeat, initval=None, tz=None, name=None):
if initval is None:
values = range(repeat)
......
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