示例#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)))
示例#2
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
示例#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')))
示例#4
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...
        ''')
示例#5
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
示例#6
0
def test_descriptor_includes_empty_false():
    d = Descriptor.load('''
    id: dep
    includes:
        - http://example.org/empty_ctx:
            empty: false
    ''')
    assert not d.empties
示例#7
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
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
示例#9
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