Ejemplo n.º 1
0
    def datum(self, doc):
        super().datum(doc)

        resource = self.resources[doc["resource"]]
        handler_class = self.handler_reg[resource["spec"]]
        key = (str(resource["uid"]), handler_class.__name__)

        # this comes back as a single element list for one datum
        fin = self.handlers[key].get_file_list([doc["datum_kwargs"]])[0]

        # replace the root with the new root
        fout = os.path.join(self.new_root, os.path.relpath(fin, self.old_root))

        ensure_path_exists(os.path.dirname(fout))
        # cp fin, new_path
        print(fin, fout)
        shutil.copy2(fin, fout)
Ejemplo n.º 2
0
def test_legacy_config():
    name = databroker.databroker.SPECIAL_NAME
    assert 'test' in name

    path = os.path.join(os.path.expanduser('~'), '.config', 'databroker',
                        name + '.yml')

    if os.path.isfile(path):
        os.remove(path)
        # Test config was dirty. We cleaned up for next time, but we cannot
        # recover. Tests must be re-run.
        assert False

    # Since it does not exist, no singleton should be made on import.

    with pytest.raises(AttributeError):
        databroker.databroker.DataBroker

    with pytest.raises(AttributeError):
        databroker.databroker.get_table

    # Now make a working legacy config file.
    ensure_path_exists(os.path.dirname(path))
    with open(path, 'w') as f:
        yaml.dump(EXAMPLE, f)

    # The singleton should be made this time.
    imp.reload(databroker.databroker)
    databroker.databroker.DataBroker
    databroker.databroker.get_table
    imp.reload(databroker)
    from databroker import db, DataBroker, get_table, get_images

    # now make a broken legacy config file.
    broken_example = copy.deepcopy(EXAMPLE)
    broken_example['metadatastore'].pop('module')
    with open(path, 'w') as f:
        yaml.dump(broken_example, f)

    # The singleton should not be made, and it should warn on import
    # about the legacy config being broken.
    with pytest.warns(UserWarning):
        imp.reload(databroker.databroker)

    # Clean up
    os.remove(path)
Ejemplo n.º 3
0
def test_lookup_config():
    name = '__test_lookup_config'
    path = os.path.join(os.path.expanduser('~'), '.config', 'databroker',
                        name + '.yml')
    ensure_path_exists(os.path.dirname(path))
    with open(path, 'w') as f:
        yaml.dump(EXAMPLE, f)
    actual = lookup_config(name)
    broker = Broker.named(name)  # smoke test
    assert name in list_configs()
    assert name in describe_configs()
    assert describe_configs()[name] == 'DESCRIPTION_PLACEHOLDER'
    os.remove(path)
    assert actual == EXAMPLE

    with pytest.raises(FileNotFoundError):
        lookup_config('__does_not_exist')
Ejemplo n.º 4
0
Archivo: core.py Proyecto: xpdAcq/xpdAn
    def datum(self, doc):
        super().datum(doc)

        resource = self.resources[doc["resource"]]
        handler_class = self.handler_reg[resource["spec"]]
        key = (str(resource["uid"]), handler_class.__name__)

        # this comes back as a single element list for one datum
        fin = self.handlers[key].get_file_list([doc["datum_kwargs"]])[0]

        # replace the root with the new root
        fout = os.path.join(self.new_root, os.path.relpath(fin, self.old_root))

        ensure_path_exists(os.path.dirname(fout))
        # cp fin, new_path
        print(fin, fout)
        shutil.copy2(fin, fout)
Ejemplo n.º 5
0
def test_legacy_config_warnings(RE):
    name = databroker.databroker.SPECIAL_NAME
    assert 'test' in name
    path = os.path.join(os.path.expanduser('~'), '.config', 'databroker',
                        name + '.yml')
    ensure_path_exists(os.path.dirname(path))
    with open(path, 'w') as f:
        yaml.dump(EXAMPLE, f)

    imp.reload(databroker.databroker)
    imp.reload(databroker)
    from databroker import db, DataBroker, get_table, get_events

    RE.subscribe(db.insert)
    uid, = RE(count([det]))
    with pytest.warns(UserWarning):
        assert len(get_table(db[uid]))
    with pytest.warns(UserWarning):
        assert list(get_events(db[uid]))

    # Clean up
    os.remove(path)