def bundle(request, intake_server, example_data, tmp_path): # noqa serializer = Serializer(tmp_path) uid, docs = example_data for name, doc in docs: serializer(name, doc) serializer.close() fullname = os.path.join(TMP_DIR, YAML_FILENAME) with open(fullname, 'w') as f: f.write(f''' plugins: source: - module: intake_bluesky sources: xyz: description: Some imaginary beamline driver: intake_bluesky.jsonl.BlueskyJSONLCatalog container: catalog args: paths: {[str(path) for path in serializer.artifacts['all']]} handler_registry: NPY_SEQ: ophyd.sim.NumpySeqHandler metadata: beamline: "00-ID" ''') time.sleep(2) if request.param == 'local': cat = intake.Catalog(os.path.join(TMP_DIR, YAML_FILENAME)) elif request.param == 'remote': cat = intake.Catalog(intake_server, page_size=10) else: raise ValueError return types.SimpleNamespace(cat=cat, uid=uid, docs=docs)
def test_double_close(example_data, tmp_path): collector = example_data() with Serializer(tmp_path) as sc: for name, doc in collector: sc(name, doc) sc.close() sc.close()
def test_no_stop_document(RE, tmpdir): """ When a Run has no RunStop document, whether because it does not exist yet or because the Run was interrupted in a critical way and never completed, we expect the field for 'stop' to contain None. """ directory = str(tmpdir) serializer = Serializer(directory) def insert_all_except_stop(name, doc): if name != 'stop': serializer(name, doc) RE(count([det]), insert_all_except_stop) serializer.close() catalog = BlueskyJSONLCatalog(f'{directory}/*.jsonl') assert catalog[-1].metadata['start'] is not None assert catalog[-1].metadata['stop'] is None
def test_relative_root_map(RE, tmpdir): """ When a Run has no RunStop document, whether because it does not exist yet or because the Run was interrupted in a critical way and never completed, we expect the field for 'stop' to contain None. """ directory = str(tmpdir) serializer = Serializer(directory) RE(count([img]), serializer) serializer.close() dest = shutil.copytree(img.save_path, pathlib.Path(directory, 'external_data')) relative_d = str(pathlib.Path(dest.relative_to(directory))) root_map = {img.save_path: relative_d} # At this point root map maps the original absolute path to one relative to # the diretory containing the catalog. CATALOG_FILE = f""" sources: test_relative_root_map: driver: bluesky-jsonl-catalog args: paths: - {directory}/*.jsonl root_map: {img.save_path}: {relative_d}""" catalog_path = str(pathlib.Path(directory, "catalog.yml")) with open(catalog_path, "w") as file: file.write(CATALOG_FILE) catalog = intake.open_catalog(catalog_path) subcatalog = catalog["test_relative_root_map"]() # At init time, Broker should resolve the relative path to an absolute one. assert subcatalog.root_map[img.save_path] == str(dest) # But it can only do this if it has a catalog *file* to interpret the path # relative to. with pytest.raises(ValueError): BlueskyJSONLCatalog(f'{directory}/*.jsonl', root_map=root_map)
def factory(name, doc): serializer = Serializer(data_path / 'xyz') serializer('start', doc) return [serializer], []
def factory(name, doc): serializer = Serializer(data_path / 'abc', flush=True) serializer('start', doc) return [serializer], []
def factory(name, doc): serializer = Serializer(directory) return [serializer], []
def factory(name, doc): serializer = Serializer(data_path / "abc", flush=True) return [serializer], []