#!/usr/bin/env python # -*- coding: utf-8 -*- import os import dlite from dlite import Instance, Dimension, Property, Relation assert len(dlite.istore_get_uuids()) == 3 + 3 thisdir = os.path.abspath(os.path.dirname(__file__)) url = 'json://' + thisdir + '/MyEntity.json' # myentity is already defined via test_global_dlite_state, no new instance is added to istore myentity = Instance.create_from_url(url) assert myentity.uri == "http://onto-ns.com/meta/0.1/MyEntity" assert len(dlite.istore_get_uuids()) == 3 + 3 i1 = Instance.create_from_metaid(myentity.uri, [2, 3], 'myid') assert i1.uri == "myid" assert i1.uuid in dlite.istore_get_uuids() assert len(dlite.istore_get_uuids()) == 3 + 4
import os import importlib import dlite from dlite import Instance from global_dlite_state_mod1 import assert_exists_in_module thisdir = os.path.abspath(os.path.dirname(__file__)) assert len(dlite.istore_get_uuids()) == 3 # 3 Hardcoded dlite instances coll = dlite.Collection() # (1) assert dlite.has_instance(coll.uuid) assert coll.uuid in dlite.istore_get_uuids() assert len(dlite.istore_get_uuids()) == 3 + 1 # Must exist in imported dlite in different module (mod1) assert_exists_in_module(coll.uuid) url = 'json://' + thisdir + '/MyEntity.json' + "?mode=r" e = Instance.create_from_url(url) # (2) assert len(dlite.istore_get_uuids()) == 3 + 2 inst1 = Instance.create_from_metaid(e.uri, [3, 2]) # (3) assert len(dlite.istore_get_uuids()) == 3 + 3 inst2 = Instance.create_from_metaid(e.uri, (3, 4), 'myinst') # (4) assert len(dlite.istore_get_uuids()) == 3 + 4 del inst1 assert len(dlite.istore_get_uuids()) == 3 + 3
except dlite.DLiteError: pass else: assert False, 'overwriting single-entity formatted file' # Create an instance of `myentity` with dimensions 2, 3 # For convinience, we give it an unique label "myid" that can be used # interchangable with its uuid inst = Instance.create_from_metaid(myentity.uri, [2, 3], 'myid') assert inst.dimensions == {'N': 2, 'M': 3} assert inst.is_data assert not inst.is_meta assert not inst.is_metameta assert dlite.has_instance(inst.uuid) assert inst.uuid in dlite.istore_get_uuids() # Assign properties inst['a-blob'] = bytearray(b'0123456789abcdef') inst['a-blob'] = b'0123456789abcdef' inst['a-blob-array'] = [[b'abcd', '00112233'], [np.int32(42), b'xyz_']] inst['a-blob-array'] = [[b'0123', b'4567'], [b'89ab', b'cdef']] inst['a-bool'] = False inst['a-bool-array'] = True, False inst['an-int'] = 42 inst['an-int-array'] = 1, 2, 3 inst['a-float'] = 42.3 inst['a-float64-array'] = 3.14, 5.0, 42.3 inst['a-fixstring'] = 'something' inst['a-fixstring-array'] = [['Al', 'X'], ['Mg', 'Si']] inst['a-string'] = 'Hello!'
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import dlite assert len(dlite.istore_get_uuids()) == 3 + 5 coll=dlite.Collection() assert len(dlite.istore_get_uuids()) == 3 + 6
def assert_exists_in_module(uuid): assert dlite.has_instance(uuid) assert uuid in dlite.istore_get_uuids()