Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_read_canonical_scalar(bundle):
cat = intake.open_catalog(bundle.intake_server, page_size=10)
run = cat['xyz']()[bundle.det_scan_uid]
run.read_canonical()
def sorted_actual():
for name_ in ('start', 'descriptor', 'event', 'stop'):
for name, doc in bundle.det_scan_docs:
if name == name_:
yield name, doc
for actual, expected in zip(run.read_canonical(), sorted_actual()):
actual_name, actual_doc = actual
expected_name, expected_doc = expected
assert actual_name == expected_name
assert actual_doc == expected_doc
def test_access_scalar_data(bundle):
"Access simple scalar data that is stored directly in Event documents."
cat = intake.open_catalog(bundle.intake_server, page_size=10)
run = cat['xyz']()[bundle.det_scan_uid]()
entry = run['primary']
entry.read()
entry().to_dask()
entry().to_dask().load()
def test_access_nonscalar_data(bundle):
"Access nonscalar data that is stored directly in Event documents."
cat = intake.open_catalog(bundle.intake_server, page_size=10)
run = cat['xyz']()[bundle.direct_img_scan_uid]()
entry = run['primary']
entry.read()
entry().to_dask()
entry().to_dask().load()
def get_master_catalog():
# TODO: replace with environment variable
fname = os.path.join(os.path.dirname(__file__),
'../intake-catalogs/master.yaml')
return intake.open_catalog(fname)
def test_read_canonical_nonscalar(bundle):
cat = intake.open_catalog(bundle.intake_server, page_size=10)
run = cat['xyz']()[bundle.direct_img_scan_uid]
run.read_canonical()
def sorted_actual():
for name_ in ('start', 'descriptor', 'event', 'stop'):
for name, doc in bundle.direct_img_scan_docs:
if name == name_:
yield name, doc
for actual, expected in zip(run.read_canonical(), sorted_actual()):
actual_name, actual_doc = actual
expected_name, expected_doc = expected
assert actual_name == expected_name
assert actual_doc == expected_doc
def cat_from_string_or_cat(cat):
"""Return a catalog instance when given a cat or a string"""
if isinstance(cat, str):
cat = intake.open_catalog(cat)
return cat
def preprocess(cls, cat):
"""Function to run on each cat input"""
if isinstance(cat, str):
cat = intake.open_catalog(cat)
return cat
try:
from intake import open_catalog
except:
raise ImportError('Loading hvPlot sample data requires intake '
'and intake-parquet. Install it using conda or '
'pip before loading data.')
_file_path = os.path.dirname(__file__)
if os.path.isdir(os.path.join(_file_path, 'examples')):
_cat_path = os.path.join(_file_path, 'examples', 'datasets.yaml')
else:
_cat_path = os.path.join(_file_path, '..', 'examples', 'datasets.yaml')
# Load catalogue
catalogue = open_catalog(_cat_path)
# Add catalogue entries to namespace
for _c in catalogue:
globals()[_c] = catalogue[_c]
def add_cat(self, ev=None):
"""Add catalog instance to the browser
Also called, without a catalog instance, when the (+) button is
pressed, which will attempt to read a catalog and, if successful,
add it to the browser.
"""
if isinstance(ev, intake.catalog.Catalog):
cat = ev
else:
try:
cat = intake.open_catalog(ev)
list(cat) # fails if parse is bad
except Exception as e:
self.exception = e
return
self.cats[cat.name] = cat
self.update_cat_list()
self.cat_list.value = cat._name
self.cat_selected({'new': cat._name})
def cat(self):
"""Catalog object initialized from from cat_url"""
# might want to do some validation in here
return intake.open_catalog(self.cat_url)