Commit 7603a506 authored by Sebastien Petitdemange's avatar Sebastien Petitdemange Committed by Vincent Michel

tests: added data iterator tests

parent 6a1d8543
......@@ -457,9 +457,9 @@ class HashSetting(object):
def ttl(self, value=-1):
return ttl_func(self._cnx(), self._name, value)
def raw_get(self, key):
def raw_get(self, *keys):
cnx = self._cnx()
return cnx.hget(self._name, key)
return cnx.hget(self._name, *keys)
@read_decorator
def get(self, key, default=None):
......@@ -533,9 +533,9 @@ class HashSetting(object):
return [(k, v) for k, v in values.iteritems()]
@read_decorator
def fromkeys(self, keys):
def fromkeys(self, *keys):
cnx = self._cnx()
return cnx.hmget(self._name, keys)
return cnx.hmget(self._name, *keys)
def has_key(self, key):
cnx = self._cnx()
......
This diff is collapsed.
......@@ -15,6 +15,7 @@ import pytest
from bliss.config import static
from bliss.config.conductor import client
from bliss.config.conductor import connection
from bliss.config.conductor.client import get_default_connection
BLISS = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
BEACON_DB_PATH = os.path.join(BLISS, 'tests', 'test_configuration')
......@@ -40,3 +41,10 @@ def beacon():
cfg = static.get_config()
yield cfg
proc.terminate()
@pytest.fixture
def redis_data_conn():
cnx = get_default_connection()
redis_conn = cnx.get_redis_connection(db=1)
yield redis_conn
......@@ -7,6 +7,7 @@
import pytest
import time
import gevent
import numpy
import cPickle as pickle
from bliss import setup_globals
......@@ -16,8 +17,10 @@ from bliss.scanning.chain import AcquisitionChain
from bliss.scanning.acquisition.motor import SoftwarePositionTriggerMaster
from bliss.scanning.acquisition.counter import SamplingCounterAcquisitionDevice
from bliss.data.node import DataNodeContainer
from bliss.config.settings import scan as redis_scan
from bliss.data.scan import Scan as ScanNode
from bliss.config.conductor.client import get_default_connection
from bliss.data.node import get_node, DataNodeIterator
from bliss.data.channel import ChannelDataNode
def test_parent_node(beacon):
session = beacon.get("test_session")
......@@ -29,17 +32,17 @@ def test_parent_node(beacon):
assert parent_node.type == "container"
assert isinstance(parent_node, DataNodeContainer)
def test_scan_node(beacon):
def test_scan_node(beacon, redis_data_conn):
session = beacon.get("test_session")
session.setup()
scan_saving = getattr(setup_globals, "SCAN_SAVING")
parent = scan_saving.get_parent_node()
m0 = getattr(setup_globals, "m0")
m0.velocity(10)
m = getattr(setup_globals, "roby")
m.velocity(10)
diode = getattr(setup_globals, "diode")
chain = AcquisitionChain()
chain.add(SoftwarePositionTriggerMaster(m0, 0, 1, 5), SamplingCounterAcquisitionDevice(diode, 0.01))
chain.add(SoftwarePositionTriggerMaster(m, 0, 1, 5), SamplingCounterAcquisitionDevice(diode, 0.01, npoints=5))
s = Scan(chain, "test_scan", parent, { "metadata": 42 })
assert s.name == "test_scan_1"
......@@ -48,37 +51,69 @@ def test_scan_node(beacon):
assert s.node.type == "scan"
assert s.node.db_name == s.root_node.db_name+":"+s.name
# check redis data
cnx = get_default_connection()
redis_conn = cnx.get_redis_connection(db=1)
scan_node_dict = redis_conn.hgetall(s.node.db_name)
scan_node_dict = redis_data_conn.hgetall(s.node.db_name)
assert scan_node_dict.get('name') == "test_scan_1"
assert scan_node_dict.get('db_name') == s.node.db_name
assert scan_node_dict.get('node_type') == "scan"
assert scan_node_dict.get('parent') == s.node.parent.db_name
scan_info_dict = redis_conn.hgetall(s.node.db_name+"_info")
scan_info_dict = redis_data_conn.hgetall(s.node.db_name+"_info")
assert pickle.loads(scan_info_dict['metadata']) == 42
s.run()
m0_node_db_name = s.node.db_name+":m0"
assert redis_conn.lrange(s.node.db_name+"_children_list", 0, -1) == [m0_node_db_name]
assert redis_conn.lrange(m0_node_db_name+"_children_list", 0, -1) == [m0_node_db_name+":m0", m0_node_db_name+":diode"]
m0_node_db_name = s.node.db_name+":roby"
assert redis_data_conn.lrange(s.node.db_name+"_children_list", 0, -1) == [m0_node_db_name]
assert redis_data_conn.lrange(m0_node_db_name+"_children_list", 0, -1) == [m0_node_db_name+":roby", m0_node_db_name+":diode"]
def test_scan_data_0d(beacon):
def test_scan_data_0d(beacon, redis_data_conn):
session = beacon.get("test_session")
session.setup()
counter_class = getattr(setup_globals, 'TestScanGaussianCounter')
counter = counter_class("gaussian", 10, cnt_time=0.1)
s = scans.timescan(0.1, counter, npoints=10, return_scan = True, save=False)
# check redis data
cnx = get_default_connection()
redis_conn = cnx.get_redis_connection(db=1)
redis_data = map(float, redis_conn.lrange(s.node.db_name+":timer:gaussian:gaussian_data", 0, -1))
redis_data = map(float, redis_data_conn.lrange(s.node.db_name+":timer:gaussian:gaussian_data", 0, -1))
assert numpy.array_equal(redis_data, counter.data)
def test_data_iterator(beacon, redis_data_conn):
session = beacon.get("test_session")
redis_keys = set(redis_scan(session.name+"*", connection=redis_data_conn))
session_node = get_node(session.name)
db_names = set([n.db_name for n in DataNodeIterator(session_node).walk(wait=False)])
assert len(db_names) > 0
assert db_names == redis_keys.intersection(db_names)
def test_data_iterator_event(beacon, redis_data_conn):
def iterate_channel_events(scan_db_name, channels):
for e, n in DataNodeIterator(get_node(scan_db_name)).walk_events():
if n.type == 'channel':
channels[n.name] = n.get(0, -1)
scan_saving = getattr(setup_globals, "SCAN_SAVING")
parent = scan_saving.get_parent_node()
m = getattr(setup_globals, "roby")
m.velocity(10)
diode = getattr(setup_globals, "diode")
npts = 5
chain = AcquisitionChain()
chain.add(SoftwarePositionTriggerMaster(m, 0, 1, npts), SamplingCounterAcquisitionDevice(diode, 0.01, npoints=npts))
s = Scan(chain, "test_scan", parent)
channels_data = dict()
iteration_greenlet = gevent.spawn(iterate_channel_events, s.node.db_name, channels_data)
s.run()
time.sleep(0.1)
iteration_greenlet.kill()
assert set(('roby', 'diode')) == set(channels_data.keys())
assert len(channels_data['roby']) == npts
assert len(channels_data['diode']) == npts
for n in DataNodeIterator(get_node(s.node.db_name)).walk_from_last(filter='channel', wait=False):
assert n.get(0, -1) == channels_data[n.name]
assert isinstance(n, ChannelDataNode)
Markdown is supported
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