示例#1
0
def test_dict_save_complex():
    from intake.catalog.base import Catalog
    fn = os.path.join(tempfile.mkdtemp(), 'mycat.yaml')
    cat = Catalog()
    entry = LocalCatalogEntry(name='trial', description='get this back',
                              driver='csv', cache=[], catalog=cat,
                              parameters=[UserParameter(name='par1', description='desc', type='int')],
                              args={'urlpath': 'none'})

    cat._entries = {'trial': entry}
    cat.save(fn)

    cat2 = open_catalog(fn)
    assert 'trial' in cat2
    assert cat2.name == 'mycat'
    assert cat2.trial.describe()['plugin'][0] == 'csv'
示例#2
0
    def flatten_remote_catalogs(self, catalog):
        from intake.catalog.base import Catalog
        cat_dict = {}

        for name in catalog:
            try:
                from intake.catalog.base import RemoteCatalog
                sub_cat = catalog[name]
                # @TODO remote catalogs are one level too high. This check is
                # pretty rough. Would rather check that a catalog's children
                # should be top-level.
                # This is making the terrible assumption that children
                # of a RemoteCatalog be treated as top-level. But until
                # we figure out how to tell that a catalog is a real catalog
                # with data, it's as good as we can get
                if isinstance(sub_cat(), RemoteCatalog):
                    for name in sub_cat:
                        cat_dict[name] = sub_cat[name]
                else:
                    cat_dict[name] = sub_cat
            except Exception as e:
                log.error(e)
                msg.showMessage("Unable to query top level catalogs: ", str(e))

        return Catalog.from_dict(cat_dict)
示例#3
0
def test_from_dict_with_data_source():
    "Check that Catalog.from_dict accepts DataSources not wrapped in Entry."
    from intake.catalog.base import Catalog
    fn = os.path.join(tempfile.mkdtemp(), 'mycat.yaml')
    entry = LocalCatalogEntry(name='trial', description='get this back',
                              driver='csv', args=dict(urlpath=""))
    ds = entry()
    cat = Catalog.from_dict({'trial': ds}, name='mycat')
示例#4
0
def test_filter():
    from intake.catalog.base import Catalog
    entry1 = LocalCatalogEntry(name='trial', description='get this back',
                               driver='csv', args=dict(urlpath=""))
    entry2 = LocalCatalogEntry(name='trial', description='pass this through',
                               driver='csv', args=dict(urlpath=""))
    cat = Catalog.from_dict({'trial1': entry1,
                             'trial2': entry2}, name='mycat')
    cat2 = cat.filter(lambda e: 'pass' in e._description)
    assert list(cat2) == ['trial2']
    assert cat2.trial2 == entry2()
示例#5
0
def test_dict_adddel():
    from intake.catalog.base import Catalog
    entry = LocalCatalogEntry(name='trial', description='get this back',
                              driver='csv', args=dict(urlpath=""))
    cat = Catalog.from_dict({'trial': entry}, name='mycat')
    assert 'trial' in cat
    cat['trial2'] = entry
    assert list(cat) == ['trial', 'trial2']
    cat.pop('trial')
    assert list(cat) == ['trial2']
    assert cat['trial2'].describe() == entry.describe()
示例#6
0
def test_dict_save():
    from intake.catalog.base import Catalog
    fn = os.path.join(tempfile.mkdtemp(), 'mycat.yaml')
    entry = LocalCatalogEntry(name='trial', description='get this back',
                              driver='csv', args=dict(urlpath=""))
    cat = Catalog.from_dict({'trial': entry}, name='mycat')
    cat.save(fn)

    cat2 = open_catalog(fn)
    assert 'trial' in cat2
    assert cat2.name == 'mycat'
    assert "CSV" in cat2.trial.classname
示例#7
0
def test_no_entry():
    cat = Catalog()
    cat2 = cat.configure_new()
    assert isinstance(cat2, Catalog)
    assert cat.auth is None
    assert cat2.auth is None
示例#8
0
def test_regression():
    with pytest.raises(ValueError):
        Catalog("URI")