Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests via adding next(cg) #28

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ omit =
*_version.py

exclude_lines =
pragma: no cover
raise ImportError
if __name__ == '__main__':
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ before_install:

install:
- export GIT_FULL_HASH=`git rev-parse HEAD`
- conda create -n testenv nose python=$TRAVIS_PYTHON_VERSION pytest coverage pip databroker bluesky flake8 pyFAI mongoquery codecov attrs metadatastore filestore -c conda-forge -c lightsource2-tag -c soft-matter
- conda create -n testenv nose python=$TRAVIS_PYTHON_VERSION pytest coverage pip databroker flake8 pyFAI mongoquery codecov attrs metadatastore filestore -c conda-forge -c lightsource2-tag -c soft-matter
- source activate testenv
- 'pip install https://github.com/NSLS-II/portable-mds/zipball/master#egg=portable_mds'
- 'pip install https://github.com/NSLS-II/portable-fs/zipball/master#egg=portable_fs'
- 'pip install https://github.com/NSLS-II/bluesky/zipball/master#egg=bluesky'
- python setup.py install
# Need to clean the python build directory (and other cruft) or pytest is
# going to find the build directory and get confused why there are two sets
Expand Down
43 changes: 11 additions & 32 deletions xpdsim/dets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from cycler import cycler
from pims import ImageSequence
from pkg_resources import resource_filename as rs_fn
from bluesky.utils import new_uid

DATA_DIR = rs_fn('xpdsim', 'data/')

Expand Down Expand Up @@ -75,39 +74,19 @@ def __init__(self, name, read_fields, fs, shutter=None,
else:
self._dark_fields = None

def trigger(self):
def trigger_read(self):
if self.shutter and self._dark_fields and \
self.shutter.read()['rad']['value'] == 0:
read_v = {field: {'value': func(), 'timestamp': ttime.time()}
for field, func in self._dark_fields.items()
if field in self.read_attrs}
self._result.clear()
for idx, (name, reading) in enumerate(read_v.items()):
# Save the actual reading['value'] to disk and create a record
# in FileStore.
np.save('{}_{}.npy'.format(self._path_stem, idx),
reading['value'])
datum_id = new_uid()
self.fs.insert_datum(self._resource_id, datum_id,
dict(index=idx))
# And now change the reading in place, replacing the value with
# a reference to FileStore.
reading['value'] = datum_id
self._result[name] = reading

delay_time = self.exposure_time
if delay_time:
if self.loop.is_running():
st = be.SimpleStatus()
self.loop.call_later(delay_time, st._finished)
return st
else:
ttime.sleep(delay_time)

return be.NullStatus()

self.shutter.read()['rad']['value'] == 0:
rv = {field: {'value': func(), 'timestamp': ttime.time()}
for field, func in self._dark_fields.items()
if field in self.read_attrs}
print('======Triggered shutter======')
print(rv)
else:
return super().trigger()
rv = super().trigger_read()
read_v = dict(rv)
read_v['pe1_image']['value'] = read_v['pe1_image']['value'].copy()
return read_v


def build_image_cycle(path):
Expand Down
4 changes: 2 additions & 2 deletions xpdsim/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
[build_pymongo_backed_broker,
build_sqlite_backed_broker],
['metadatastore', 'portable_mds']):
try:
try: # pragma: no cover
importlib.import_module(mod)
except ImportError:
except ImportError: # pragma: no cover
pass
else:
params.append(name)
Expand Down
3 changes: 2 additions & 1 deletion xpdsim/tests/test_dets.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ def test_dets_shutter(db, tmp_dir, name, fp):
for n, d in db.restream(db[-1], fill=True):
if n == 'event':
assert_array_equal(d['data']['pe1_image'],
np.zeros(next(cg)['pe1_image'].shape))
np.zeros(d['data']['pe1_image'].shape))
assert uid is not None

# With the shutter up
RE(abs_set(shctl1, 1, wait=True))
uid = RE(scan)
next(cg)
for n, d in db.restream(db[-1], fill=True):
if n == 'event':
assert_array_equal(d['data']['pe1_image'], next(cg)['pe1_image'])
Expand Down