1
0
mirror of https://github.com/FreeOpcUa/opcua-asyncio synced 2025-10-29 17:07:18 +08:00

enable sqlite tests

This commit is contained in:
Christian Bergmiller 2019-06-21 08:51:44 +02:00
parent 0a5ca1e44c
commit 71c4c56d12
2 changed files with 13 additions and 21 deletions

View File

@ -30,7 +30,7 @@ class HistorySQLite(HistoryStorageInterface):
self._loop = loop or get_event_loop()
async def init(self):
self._db = aiosqlite.connect(self._db_file, loop=self._loop)
self._db = await aiosqlite.connect(self._db_file, loop=self._loop)
async def stop(self):
await self._db.close()
@ -89,28 +89,24 @@ class HistorySQLite(HistoryStorageInterface):
f'THEN MIN(SourceTimestamp) ELSE NULL END FROM "{table}")', (count,), table, node_id)
async def read_node_history(self, node_id, start, end, nb_values):
table = self._get_table_name(node_id)
start_time, end_time, order, limit = self._get_bounds(start, end, nb_values)
cont = None
results = []
# select values from the database; recreate UA Variant from binary
try:
rows = await self._execute_sql(
f'SELECT * FROM "{table}" WHERE "SourceTimestamp" BETWEEN ? AND ? '
f'ORDER BY "_Id" {order} LIMIT ?', (start_time, end_time, limit,)
)
for row in rows:
# rebuild the data value object
dv = ua.DataValue(variant_from_binary(Buffer(row[6])))
dv.ServerTimestamp = row[1]
dv.SourceTimestamp = row[2]
dv.StatusCode = ua.StatusCode(row[3])
results.append(dv)
async with self._db.execute(
f'SELECT * FROM "{table}" WHERE "SourceTimestamp" BETWEEN ? AND ? '
f'ORDER BY "_Id" {order} LIMIT ?', (start_time, end_time, limit,)) as cursor:
async for row in cursor:
# rebuild the data value object
dv = ua.DataValue(variant_from_binary(Buffer(row[6])))
dv.ServerTimestamp = row[1]
dv.SourceTimestamp = row[2]
dv.StatusCode = ua.StatusCode(row[3])
results.append(dv)
except sqlite3.Error as e:
self.logger.error("Historizing SQL Read Error for %s: %s", node_id, e)
if nb_values:
if len(results) > nb_values:
cont = results[nb_values].SourceTimestamp

View File

@ -19,13 +19,9 @@ def pytest_generate_tests(metafunc):
if 'opc' in metafunc.fixturenames:
metafunc.parametrize('opc', ['client', 'server'], indirect=True)
elif 'history' in metafunc.fixturenames:
#metafunc.parametrize('history', ['dict', 'sqlite'], indirect=True)
#FIXME: disable sqlite backend, it breaks
metafunc.parametrize('history', ['dict'], indirect=True)
metafunc.parametrize('history', ['dict', 'sqlite'], indirect=True)
elif 'history_server' in metafunc.fixturenames:
#FIXME: disable sqlite backend, it breaks
#metafunc.parametrize('history_server', ['dict', 'sqlite'], indirect=True)
metafunc.parametrize('history_server', ['dict'], indirect=True)
metafunc.parametrize('history_server', ['dict', 'sqlite'], indirect=True)
@pytest.yield_fixture(scope='module')