Esempio n. 1
0
def test_transitive_dep_null_context_triples_no_imports(custom_bundle):
    dep_dep_desc = Descriptor.load('''
    id: dep_dep
    includes:
      - http://example.com/ctx
    ''')

    dep_desc = Descriptor.load('''
    id: dep
    dependencies:
      - dep_dep
    ''')

    test_desc = Descriptor.load('''
    id: test
    dependencies:
      - dep
    ''')

    depgraph = ConjunctiveGraph()
    ctx_graph = depgraph.get_context('http://example.com/ctx')
    quad = (URIRef('http://example.org/sub'),
            URIRef('http://example.org/prop'),
            URIRef('http://example.org/obj'), ctx_graph)
    depgraph.add(quad)

    with custom_bundle(dep_dep_desc, graph=depgraph) as depdepbun, \
            custom_bundle(dep_desc, bundles_directory=depdepbun.bundles_directory) as depbun, \
            custom_bundle(test_desc, bundles_directory=depbun.bundles_directory) as testbun, \
            Bundle('test', bundles_directory=testbun.bundles_directory) as bnd:
        assert set([quad[:3]]) == set(bnd.rdf.triples((None, None, None)))
Esempio n. 2
0
def test_dependency_version_in_manifest_without_spec(dirs):
    '''
    It is permitted to not specify the version of a bundle dependency in the descriptor,
    but we must pin a specific version of the bundle in the manifest.
    '''
    ctxid_1 = 'http://example.org/ctx1'
    ctxid_2 = 'http://example.org/ctx2'

    # Make a descriptor that includes ctx1 and the imports, but not ctx2
    d = Descriptor('test')
    d.includes.add(make_include_func(ctxid_1))
    d.dependencies.add(DependencyDescriptor('dep'))

    dep_d = Descriptor('dep')
    dep_d.includes.add(make_include_func(ctxid_2))

    # Add some triples so the contexts aren't empty -- we can't save an empty context
    g = rdflib.ConjunctiveGraph()

    cg_1 = g.get_context(ctxid_1)
    cg_2 = g.get_context(ctxid_2)

    cg_1.add((aURI('a'), aURI('b'), aURI('c')))
    cg_2.add((aURI('d'), aURI('e'), aURI('f')))

    bi = Installer(*dirs, graph=g)
    bi.install(dep_d)
    bi.install(d)
    test_bnd = Bundle('test', bundles_directory=dirs.bundles_directory)
    assert test_bnd.manifest_data['dependencies'][0]['version'] == 1
Esempio n. 3
0
def test_add_to_graph_not_supported(custom_bundle):
    dep_desc = Descriptor.load('''
    id: dep
    includes:
      - http://example.com/ctx
    ''')

    test_desc = Descriptor.load('''
    id: test
    dependencies:
      - dep
    ''')

    depgraph = ConjunctiveGraph()
    ctx_graph = depgraph.get_context('http://example.com/ctx')
    quad = (URIRef('http://example.org/sub'),
            URIRef('http://example.org/prop'),
            URIRef('http://example.org/obj'), ctx_graph)
    depgraph.add(quad)

    with custom_bundle(dep_desc, graph=depgraph) as depbun, \
            custom_bundle(test_desc, bundles_directory=depbun.bundles_directory) as testbun, \
            Bundle('test', bundles_directory=testbun.bundles_directory) as bnd:

        with pytest.raises(ZODB.POSException.ReadOnlyError):
            with transaction.manager:
                bnd.rdf.add((URIRef('http://example.org/sub'),
                             URIRef('http://example.org/prop'),
                             URIRef('http://example.org/obj')))
Esempio n. 4
0
def test_triples_choices_context_not_included(custom_bundle):
    dep_desc = Descriptor.load('''
    id: dep
    includes:
      - http://example.com/ctxg
    ''')

    test_desc = Descriptor.load('''
    id: test
    dependencies:
      - dep
    ''')

    depgraph = ConjunctiveGraph()
    ctx_graph = depgraph.get_context('http://example.com/ctx')
    quad = (URIRef('http://example.org/sub'),
            URIRef('http://example.org/prop'),
            URIRef('http://example.org/obj'), ctx_graph)
    depgraph.add(quad)

    with custom_bundle(dep_desc, graph=depgraph) as depbun, \
            custom_bundle(test_desc, bundles_directory=depbun.bundles_directory) as testbun, \
            Bundle('test', bundles_directory=testbun.bundles_directory) as bnd:
        match = False
        for x in bnd.rdf.triples_choices((URIRef('http://example.org/sub'),
                                          URIRef('http://example.org/prop'),
                                          [URIRef('http://example.org/obj')]),
                                         context=ctx_graph):
            match = True
        assert not match
Esempio n. 5
0
def test_imports_in_dependencies(dirs):
    '''
    If we have imports and a dependency includes the context, then we shouldn't have an
    error.

    Versioned bundles are assumed to be immutable, so we won't re-fetch a bundle already
    in the local index
    '''
    imports_ctxid = 'http://example.org/imports'
    ctxid_1 = 'http://example.org/ctx1'
    ctxid_2 = 'http://example.org/ctx2'

    # Make a descriptor that includes ctx1 and the imports, but not ctx2
    d = Descriptor('test')
    d.includes.add(make_include_func(ctxid_1))
    d.includes.add(make_include_func(imports_ctxid))
    d.dependencies.add(DependencyDescriptor('dep'))

    dep_d = Descriptor('dep')
    dep_d.includes.add(make_include_func(ctxid_2))

    # Add some triples so the contexts aren't empty -- we can't save an empty context
    g = rdflib.ConjunctiveGraph()
    cg_1 = g.get_context(ctxid_1)
    cg_2 = g.get_context(ctxid_2)
    cg_imp = g.get_context(imports_ctxid)
    with transaction.manager:
        cg_1.add((aURI('a'), aURI('b'), aURI('c')))
        cg_2.add((aURI('d'), aURI('e'), aURI('f')))
        cg_imp.add((URIRef(ctxid_1), CONTEXT_IMPORTS, URIRef(ctxid_2)))

    bi = Installer(*dirs, imports_ctx=imports_ctxid, graph=g)
    bi.install(dep_d)
    bi.install(d)
Esempio n. 6
0
def test_descriptor_includes_extra_key():
    with pytest.raises(ValueError, match=r'.*empty.*'):
        Descriptor.load('''
        id: dep
        includes:
            - http://example.org/empty_ctx:
              empty: true # Oh no, you don't belong here...
        ''')
Esempio n. 7
0
def test_file_hash(dirs):
    d = Descriptor('test')
    open(p(dirs[0], 'somefile'), 'w').close()
    d.files = FilesDescriptor()
    d.files.includes.add('somefile')
    g = rdflib.ConjunctiveGraph()
    bi = Installer(*dirs, graph=g)
    bi.install(d)
    assert isfile(p(dirs.bundles_directory, 'test', '1', 'files', 'hashes'))
Esempio n. 8
0
def test_file_pattern_copy(dirs):
    d = Descriptor('test')
    open(p(dirs[0], 'somefile'), 'w').close()
    d.files = FilesDescriptor()
    d.files.patterns.add('some*')
    g = rdflib.ConjunctiveGraph()
    bi = Installer(*dirs, graph=g)
    bi.install(d)
    bfiles = p(dirs.bundles_directory, 'test', '1', 'files')
    assert set(listdir(bfiles)) == set(['hashes', 'somefile'])
Esempio n. 9
0
def test_bundle_store_conf_with_two_dep_levels(custom_bundle):
    '''
    Test that transitive dependenices shared by multiple bundles are not included more
    than once
    '''
    imports_ctxid = 'http://example.org/imports'
    ctxid_1 = 'http://example.org/ctx1'
    ctxid_2 = 'http://example.org/ctx2'

    # Make a descriptor that includes ctx1 and the imports, but not ctx2
    d = Descriptor('test')
    d.includes.add(make_include_func(ctxid_1))
    d.includes.add(make_include_func(imports_ctxid))
    d.dependencies.add(DependencyDescriptor('dep'))
    d.dependencies.add(DependencyDescriptor('dep_dep'))

    dep_d = Descriptor('dep')
    dep_d.dependencies.add(DependencyDescriptor('dep_dep'))

    dep_dep_d = Descriptor('dep_dep')
    dep_dep_d.includes.add(make_include_func(ctxid_2))

    # Add some triples so the contexts aren't empty -- we can't save an empty context
    g = rdflib.ConjunctiveGraph()
    cg_1 = g.get_context(ctxid_1)
    cg_2 = g.get_context(ctxid_2)
    cg_1.add((aURI('a'), aURI('b'), aURI('c')))
    cg_2.add((aURI('d'), aURI('e'), aURI('f')))

    # End setup

    with custom_bundle(dep_dep_d, graph=g) as depdepbun, \
            custom_bundle(dep_d, bundles_directory=depdepbun.bundles_directory) as depbun, \
            custom_bundle(d, bundles_directory=depbun.bundles_directory) as testbun, \
            Bundle('test', bundles_directory=testbun.bundles_directory) as bnd:
        assert bnd.conf['rdf.store_conf'] == [
            ('FileStorageZODB',
             dict(url=p(testbun.bundle_directory, BUNDLE_INDEXED_DB_NAME),
                  read_only=True)),
            # dep
            ('owmeta_core_bds',
             dict(type='agg',
                  conf=[('FileStorageZODB',
                         dict(url=p(depbun.bundle_directory,
                                    BUNDLE_INDEXED_DB_NAME),
                              read_only=True)),
                        ('owmeta_core_bds',
                         dict(type='agg',
                              conf=[('FileStorageZODB',
                                     dict(url=p(depdepbun.bundle_directory,
                                                BUNDLE_INDEXED_DB_NAME),
                                          read_only=True))]))]))
        ]
Esempio n. 10
0
def test_file_hash_content(dirs):
    d = Descriptor('test')
    open(p(dirs[0], 'somefile'), 'w').close()
    d.files = FilesDescriptor()
    d.files.includes.add('somefile')
    g = rdflib.ConjunctiveGraph()
    bi = Installer(*dirs, graph=g)
    bi.install(d)
    with open(p(dirs.bundles_directory, 'test', '1', 'files', 'hashes'),
              'rb') as f:
        contents = f.read()
        assert b'somefile' in contents
Esempio n. 11
0
def test_no_write_dependency_on_commit(custom_bundle, owm_project):
    '''
    Make sure we don't have duplicates in the graphs index when we have a dependency

    (This is one of *many* ways in which we're making sure we don't persist data from
     dependencies in the project's store)
    '''

    graph = rdflib.ConjunctiveGraph()
    depctx = 'http://example.org/dep'
    ctxgraph = graph.get_context(URIRef(depctx))
    ctxgraph.add((
        URIRef('http://ex.org/s'),
        URIRef('http://ex.org/p'),
        URIRef('http://ex.org/o'),
    ))
    dep_desc = Descriptor('dep', version=1, includes=(depctx, ))

    with custom_bundle(dep_desc, graph=graph,
                       homedir=owm_project.test_homedir):
        owm = owm_project.owm()
        deps = [{'id': 'dep', 'version': 1}]
        owm.config.set('dependencies', json.dumps(deps))

        commit_output = owm_project.sh("owm commit -m 'Commit message'")
        print('COMMIT OUTPUT')
        print(commit_output)

        with open(p(owm_project.testdir, '.owm', 'graphs', 'index')) as f:
            assert list(f.readlines()) == []
Esempio n. 12
0
def test_unrelated_imports_excluded(dirs):
    imports_ctxid = 'http://example.org/imports'
    ctxid_1 = 'http://example.org/ctx1'
    ctxid_2 = 'http://example.org/ctx2'
    ctxid_3 = 'http://example.org/ctx3'
    ctxid_4 = 'http://example.org/ctx4'

    # Make a descriptor that includes ctx1 and the imports, but not ctx2
    d = Descriptor('test')
    d.includes.add(make_include_func(ctxid_1))
    d.includes.add(make_include_func(ctxid_2))

    # Add some triples so the contexts aren't empty -- we can't save an empty context
    g = rdflib.ConjunctiveGraph()
    cg_1 = g.get_context(ctxid_1)
    cg_2 = g.get_context(ctxid_2)
    cg_3 = g.get_context(ctxid_3)
    cg_4 = g.get_context(ctxid_4)
    cg_imp = g.get_context(imports_ctxid)
    with transaction.manager:
        cg_1.add((aURI('a'), aURI('b'), aURI('c')))
        cg_2.add((aURI('d'), aURI('e'), aURI('f')))
        cg_3.add((aURI('g'), aURI('h'), aURI('i')))
        cg_4.add((aURI('j'), aURI('k'), aURI('l')))
        cg_imp.add((URIRef(ctxid_1), CONTEXT_IMPORTS, URIRef(ctxid_2)))
        cg_imp.add((URIRef(ctxid_3), CONTEXT_IMPORTS, URIRef(ctxid_4)))

    bi = Installer(*dirs, imports_ctx=imports_ctxid, graph=g)
    bi.install(d)
    with Bundle(d.id, dirs.bundles_directory) as bnd:
        g = bnd.rdf.get_context(bnd.conf[IMPORTS_CONTEXT_KEY])
        assert (URIRef(ctxid_3), CONTEXT_IMPORTS, URIRef(ctxid_4)) not in g
Esempio n. 13
0
def test_imports_are_included(dirs):
    '''
    If we have imports and no dependencies, then thrown an exception if we have not
    included them in the bundle
    '''
    imports_ctxid = 'http://example.org/imports'
    ctxid_1 = 'http://example.org/ctx1'
    ctxid_2 = 'http://example.org/ctx2'

    # Make a descriptor that includes ctx1 and the imports, but not ctx2
    d = Descriptor('test')
    d.includes.add(make_include_func(ctxid_1))
    d.includes.add(make_include_func(ctxid_2))

    # Add some triples so the contexts aren't empty -- we can't save an empty context
    g = rdflib.ConjunctiveGraph()
    cg_1 = g.get_context(ctxid_1)
    cg_2 = g.get_context(ctxid_2)
    cg_imp = g.get_context(imports_ctxid)
    with transaction.manager:
        cg_1.add((aURI('a'), aURI('b'), aURI('c')))
        cg_2.add((aURI('d'), aURI('e'), aURI('f')))
        cg_imp.add((URIRef(ctxid_1), CONTEXT_IMPORTS, URIRef(ctxid_2)))

    bi = Installer(*dirs, imports_ctx=imports_ctxid, graph=g)
    bi.install(d)
    with Bundle(d.id, dirs.bundles_directory) as bnd:
        g = bnd.rdf.get_context(bnd.conf[IMPORTS_CONTEXT_KEY])
        assert (URIRef(ctxid_1), CONTEXT_IMPORTS, URIRef(ctxid_2)) in g
Esempio n. 14
0
def test_bundle(custom_bundle):
    from owmeta_core import bundle
    from owmeta_core.context import Context
    from owmeta_core.dataobject import DataObject
    from owmeta_core.bundle import Descriptor, Bundle

    desc = Descriptor.load('''
    id: example/bundleId
    version: 42
    includes:
        - http://example.org/test_bundle
    ''')

    ctx = Context('http://example.org/test_bundle')
    ctx(DataObject)(ident='http://example.org/entities#aDataObject')

    with custom_bundle(desc, graph=ctx.rdf_graph()) as bun:

        class CustomBundle(Bundle):
            def __init__(self, *args, **kwargs):
                super().__init__(*args,
                                 bundles_directory=bun.bundles_directory,
                                 **kwargs)

        [failure_count, return_count
         ] = doctest.testmod(bundle,
                             optionflags=(ALLOW_UNICODE | doctest.ELLIPSIS),
                             extraglobs=dict(Bundle=CustomBundle,
                                             DataObject=DataObject))
    assert failure_count == 0
Esempio n. 15
0
def test_no_dupe(dirs):
    '''
    Test that if we have two contexts with the same contents that we don't create more
    than one file for it.

    The index will point to the same file for the two contexts
    '''
    d = Descriptor('test')
    ctxid_1 = 'http://example.org/ctx1'
    ctxid_2 = 'http://example.org/ctx2'
    d.includes.add(make_include_func(ctxid_1))
    d.includes.add(make_include_func(ctxid_2))
    g = rdflib.ConjunctiveGraph()
    cg = g.get_context(ctxid_1)
    with transaction.manager:
        cg.add((aURI('a'), aURI('b'), aURI('c')))

    cg = g.get_context(ctxid_2)
    with transaction.manager:
        cg.add((aURI('a'), aURI('b'), aURI('c')))

    bi = Installer(*dirs, graph=g)
    bi.install(d)

    graph_files = [
        x for x in listdir(p(dirs.bundles_directory, 'test', '1', 'graphs'))
        if x.endswith('.nt')
    ]
    assert len(graph_files) == 1
Esempio n. 16
0
def test_descriptor_includes_empty_false():
    d = Descriptor.load('''
    id: dep
    includes:
        - http://example.org/empty_ctx:
            empty: false
    ''')
    assert not d.empties
Esempio n. 17
0
def test_descriptor_empties():
    d = Descriptor.load('''
    id: dep
    includes:
        - http://example.org/empty_ctx:
            empty: true
    ''')
    assert 'http://example.org/empty_ctx' in d.empties
Esempio n. 18
0
def test_latest_bundle_selected_by_default(tempdir, custom_bundle):
    d1desc = Descriptor.load('''
    id: dep
    version: 1
    ''')
    d2desc = Descriptor.load('''
    id: dep
    version: 2
    ''')
    bdir = p(tempdir, 'bundles')
    with custom_bundle(d1desc, bundles_directory=bdir), \
            custom_bundle(d2desc, bundles_directory=bdir):
        print('dir contents', os.listdir(bdir))
        s = Archiver(tempdir, bdir).pack('dep')
        with tarfile.open(s, 'r:xz') as tf:
            with tf.extractfile(BUNDLE_MANIFEST_FILE_NAME) as mf:
                md = json.load(mf)
                assert md.get('version') == 2
Esempio n. 19
0
def test_fail_on_non_empty_target(dirs):
    d = Descriptor('test')
    g = rdflib.ConjunctiveGraph()
    bi = Installer(*dirs, graph=g)
    bundles_directory = dirs[1]
    sma = p(bundles_directory, 'test', '1', 'blah')
    makedirs(sma)
    with pytest.raises(TargetIsNotEmpty):
        bi.install(d)
Esempio n. 20
0
def test_context_index_file_exists(dirs):
    d = Descriptor('test')
    ctxid = 'http://example.org/ctx1'
    d.includes.add(make_include_func(ctxid))
    g = rdflib.ConjunctiveGraph()
    cg = g.get_context(ctxid)
    cg.add((aURI('a'), aURI('b'), aURI('c')))
    bi = Installer(*dirs, graph=g)
    bi.install(d)
    assert isfile(p(dirs.bundles_directory, 'test', '1', 'graphs', 'index'))
Esempio n. 21
0
def test_dependency_class_registry(custom_bundle):
    '''
    Test that we can load from the class registry for un-imported classes
    '''
    from owmeta_core.dataobject import DataObject

    class_registry_ctxid = 'http://example.org/class_registry'
    data_ctxid = 'http://example.org/data_context'
    defctxid = 'http://example.org/Person'

    # Add some triples so the contexts aren't empty -- we can't save an empty context
    g = rdflib.ConjunctiveGraph()

    with open(p('tests', 'test_data', 'owmbundletest01_data.n3'), 'rb') as f:
        g.get_context(data_ctxid).parse(f, format='n3')

    with open(p('tests', 'test_data', 'owmbundletest01_class_registry.n3'),
              'rb') as f:
        g.get_context(class_registry_ctxid).parse(f, format='n3')

    with open(p('tests', 'test_data', 'owmbundletest01_defctx.n3'), 'rb') as f:
        g.get_context(defctxid).parse(f, format='n3')

    # Make a descriptor that includes ctx1 and the imports, but not ctx2
    d = Descriptor('test')
    d.includes.add(make_include_func(data_ctxid))
    d.includes.add(make_include_func(defctxid))
    d.dependencies.add(DependencyDescriptor('dep'))

    # Make a dependency that holds the class registry
    dep_d = Descriptor('dep')

    with custom_bundle(dep_d, graph=g, class_registry_ctx=class_registry_ctxid) as depbun, \
            custom_bundle(d, graph=g, bundles_directory=depbun.bundles_directory) as testbun, \
            Bundle('test', bundles_directory=testbun.bundles_directory) as bnd:
        bctx = bnd(Context)().stored
        for m in bctx(DataObject)(
                ident='http://schema.openworm.org/2020/07/Person#bwithers'
        ).load():
            assert type(m).__name__ == 'Person'
            break
        else:  # no break
            pytest.fail('Expected an object')
Esempio n. 22
0
    def make_bundle(self, ident, fname, version):
        desc = Descriptor(ident)
        desc.name = 'A Bundle'
        desc.version = version
        desc.description = 'An example bundle'
        desc.includes = (set([
            make_include_func('https://example.org/bundles#example'),
            make_include_func('https://example.org/imports'),
            make_include_func('https://example.org/types'),
            make_include_func('http://www.w3.org/2000/01/rdf-schema'),
            make_include_func('http://www.w3.org/1999/02/22-rdf-syntax-ns'),
            make_include_func(BASE_SCHEMA_URL)
        ]) | set(make_include_func(x) for x in self.contexts))
        rdf = self.conn.conf['rdf.graph']
        bi = Installer(self.srcdir,
                       self.bnddir,
                       rdf,
                       imports_ctx='https://example.org/imports')
        install_dir = bi.install(desc)
        L.info('installed files in bundle %s at %s', ident, install_dir)

        with tarfile.open(p(self.srvdir, fname + '.tar.xz'),
                          mode='w:xz') as ba:
            # arcname='.' removes the leading part of the path to the install directory
            ba.add(install_dir, arcname='.')
Esempio n. 23
0
def test_context_index_file_contains_ctxid(dirs):
    d = Descriptor('test')
    ctxid = 'http://example.org/ctx1'
    d.includes.add(make_include_func(ctxid))
    g = rdflib.ConjunctiveGraph()
    cg = g.get_context(ctxid)
    with transaction.manager:
        cg.add((aURI('a'), aURI('b'), aURI('c')))
    bi = Installer(*dirs, graph=g)
    bi.install(d)
    with open(p(dirs.bundles_directory, 'test', '1', 'graphs', 'index'),
              'rb') as f:
        assert f.read().startswith(ctxid.encode('UTF-8'))
Esempio n. 24
0
def test_descriptor_dependency():
    d = Descriptor.make({
        'id':
        'testBundle',
        'dependencies':
        ['dep1', {
            'id': 'dep2',
            'version': 2
        }, ('dep3', 4), ('dep4', )]
    })
    assert DependencyDescriptor('dep1') in d.dependencies
    assert DependencyDescriptor('dep2', 2) in d.dependencies
    assert DependencyDescriptor('dep3', 4) in d.dependencies
    assert DependencyDescriptor('dep4') in d.dependencies
Esempio n. 25
0
def test_quad_not_in_dependency(custom_bundle):
    dep_desc = Descriptor.load('''
    id: dep
    includes:
      - http://example.com/ctx
    ''')

    test_desc = Descriptor.load('''
    id: test
    dependencies:
      - dep
    ''')

    depgraph = ConjunctiveGraph()
    ctx_graph = depgraph.get_context('http://example.com/other_ctx')
    quad = (URIRef('http://example.org/sub'),
            URIRef('http://example.org/prop'),
            URIRef('http://example.org/obj'), ctx_graph)
    depgraph.add(quad)

    with custom_bundle(dep_desc, graph=depgraph) as depbun, \
            custom_bundle(test_desc, bundles_directory=depbun.bundles_directory) as testbun, \
            Bundle('test', bundles_directory=testbun.bundles_directory) as bnd:
        assert quad not in bnd.rdf
Esempio n. 26
0
def test_class_registry_in_manifest(dirs):
    '''
    If a class registry context is specified, then include it
    '''
    cr_ctxid = 'http://example.org/class_registry'

    # Make a descriptor that includes ctx1 and the imports, but not ctx2
    d = Descriptor('test')

    # Add some triples so the contexts aren't empty -- we can't save an empty context
    g = rdflib.ConjunctiveGraph()

    bi = Installer(*dirs, class_registry_ctx=cr_ctxid, graph=g)
    bdir = bi.install(d)
    with open(p(bdir, BUNDLE_MANIFEST_FILE_NAME)) as mf:
        manifest_data = json.load(mf)
        assert manifest_data[CLASS_REGISTRY_CONTEXT_KEY]
Esempio n. 27
0
def test_class_registry_contents(dirs):
    '''
    If a class registry context is specified, then include it
    '''
    cr_ctxid = 'http://example.org/class_registry'

    # Make a descriptor that includes ctx1 and the imports, but not ctx2
    d = Descriptor('test')

    # Add some triples so the contexts aren't empty -- we can't save an empty context
    g = rdflib.ConjunctiveGraph()
    cg_cr = g.get_context(cr_ctxid)
    with transaction.manager:
        cg_cr.add((aURI('blah'), aURI('bruh'), aURI('uhhhh')))

    bi = Installer(*dirs, class_registry_ctx=cr_ctxid, graph=g)
    bi.install(d)

    with Bundle(d.id, dirs.bundles_directory) as bnd:
        g = bnd.rdf.get_context(bnd.conf[CLASS_REGISTRY_CONTEXT_KEY])
        assert (aURI('blah'), aURI('bruh'), aURI('uhhhh')) in g
Esempio n. 28
0
def test_multiple_context_hash(dirs):
    d = Descriptor('test')
    ctxid_1 = 'http://example.org/ctx1'
    ctxid_2 = 'http://example.org/ctx2'
    d.includes.add(make_include_func(ctxid_1))
    d.includes.add(make_include_func(ctxid_2))
    g = rdflib.ConjunctiveGraph()
    cg = g.get_context(ctxid_1)
    with transaction.manager:
        cg.add((aURI('a'), aURI('b'), aURI('c')))

    cg = g.get_context(ctxid_2)
    with transaction.manager:
        cg.add((aURI('a'), aURI('b'), aURI('c')))

    bi = Installer(*dirs, graph=g)
    bi.install(d)
    with open(p(dirs.bundles_directory, 'test', '1', 'graphs', 'hashes'),
              'rb') as f:
        contents = f.read()
        assert ctxid_1.encode('UTF-8') in contents
        assert ctxid_2.encode('UTF-8') in contents
Esempio n. 29
0
def test_deploy_sftp(owm_project_with_customizations, custom_bundle):
    desc = Descriptor('test/main', includes=('http://example.org/ctx', ))
    with owm_project_with_customizations(customizations='''\
            from unittest.mock import patch
            import atexit
            patch('owmeta_core.bundle.loaders.sftp.Transport').start()
            SFTPClientPatcher = patch('owmeta_core.bundle.loaders.sftp.SFTPClient')
            SFTPClient = SFTPClientPatcher.start()
            def verify():
                try:
                    SFTPClient.from_transport().__enter__().put.assert_called()
                except AssertionError:
                    print("FAILED")
            atexit.register(verify)
            ''') as owm_project:
        with custom_bundle(desc,
                           bundles_directory=p(owm_project.test_homedir,
                                               '.owmeta', 'bundles')):
            owm_project.sh(
                'owm bundle remote add the-source sftp://example.org/this/doesnt/matter'
            )
            owm_project.apply_customizations()
            output = owm_project.sh('owm bundle deploy test/main')
            assert 'FAILED' not in output
Esempio n. 30
0
def bundle_archive():
    with bundle_archive_helper(Descriptor('test')) as data:
        yield data