except ImportError: # If the ontology is not installed. from osp.core.ontology.namespace_registry import namespace_registry from osp.core.ontology.parser.parser import OntologyParser namespace_registry.load_parser( OntologyParser.get_parser( str(Path(__file__).parent / "test_importexport.owl.yml"))) test_importexport = namespace_registry.test_importexport # Load also the city ontology. try: from osp.core.namespaces import city except ImportError: from osp.core.ontology import Parser from osp.core.ontology.namespace_registry import namespace_registry Parser().parse("city") city = namespace_registry.city class TestImportExport(unittest.TestCase): """Loads files containing CUDS and checks the correctness of the data. The loading process returns cuds objects corresponding to the individuals in the ontology. Some of the known information about the individuals in the file is tested against the loaded data. """ def test_application_rdf_xml(self): """Test importing and exporting the `application/rdf+xml` mime type.""" with CoreSession() as session: test_data_path = str( Path(__file__).parent / "test_importexport_data.owl")
from osp.wrappers.dataspace import DataspaceSession from osp.core.session import DbWrapperSession from osp.core.session.transport.transport_session_server import \ TransportSessionServer try: from tests.test_sqlite_city import check_state except ImportError: from test_sqlite_city import check_state try: from osp.core.namespaces import city except ImportError: from osp.core.ontology import Parser from osp.core.namespaces import _namespace_registry Parser(_namespace_registry._graph).parse("city") _namespace_registry.update_namespaces() city = _namespace_registry.city HOST = "127.0.0.1" PORT = 8681 URI = f"ws://{HOST}:{PORT}" DB = "dataspace.db" class TestDataspaceWrapper(unittest.TestCase): """Test the DataspaceWrapper.""" SERVER_STARTED = False @classmethod
"""Test the API of CUDS objects using the foaf ontology.""" import unittest2 as unittest import uuid try: from osp.core.namespaces import foaf except ImportError: from osp.core.ontology import Parser from osp.core.namespaces import _namespace_registry Parser(_namespace_registry._graph).parse("foaf") _namespace_registry.update_namespaces() foaf = _namespace_registry.foaf class TestAPIfoaf(unittest.TestCase): """Test the API of CUDS objects using the foaf ontology.""" def test_creation(self): """Test creation of objectes are possible.""" c = foaf.Person() self.assertTrue(c.is_a(foaf.Person)) def test_uid(self): """Test that the uid variable contains a UUID object.""" c = foaf.Person() self.assertIsInstance(c.uid, uuid.UUID) def test_relations(self): """Test some relationships.""" a = foaf.Person() b = foaf.Person()
import rdflib import unittest2 as unittest from osp.core.ontology import OntologyEntity from osp.core.ontology.attribute import OntologyAttribute from osp.core.ontology.oclass_composition import Composition from osp.core.ontology.oclass_restriction import QUANTIFIER, RTYPE, Restriction from osp.core.ontology.relationship import OntologyRelationship try: from osp.core.namespaces import materials, math, siunits except ImportError: # When the EMMO ontology is not installed. from osp.core.ontology import Parser from osp.core.ontology.namespace_registry import namespace_registry Parser().parse("emmo") math = namespace_registry.math materials = namespace_registry.materials siunits = namespace_registry.siunits # Mappings from OWL objects and ontology classes to enums used # in oclass_composition.py. quantifier_owl_to_enum = { rdflib.OWL.someValuesFrom: QUANTIFIER.SOME, rdflib.OWL.allValuesFrom: QUANTIFIER.ONLY, rdflib.OWL.cardinality: QUANTIFIER.EXACTLY, rdflib.OWL.minCardinality: QUANTIFIER.MIN, rdflib.OWL.maxCardinality: QUANTIFIER.MAX, rdflib.OWL.hasValue: QUANTIFIER.VALUE, }
"""Test the API with the EMMO ontology.""" import unittest2 as unittest import uuid from osp.core.utils import create_from_cuds_object from osp.core.session.core_session import CoreSession from osp.core.namespaces import cuba try: from osp.core.namespaces import math, holistic, mereotopology, perceptual except ImportError: from osp.core.ontology import Parser from osp.core.namespaces import _namespace_registry Parser(_namespace_registry._graph).parse("emmo") _namespace_registry.update_namespaces() math = _namespace_registry.math holistic = _namespace_registry.holistic mereotopology = _namespace_registry.mereotopology perceptual = _namespace_registry.perceptual class TestAPIEmmo(unittest.TestCase): """Test the API with the EMMO ontology.""" def test_is_a(self): """Test instance check.""" # TODO update emmo c = math.Real(hasNumericalData=12) self.assertTrue(c.is_a(math.Number)) self.assertTrue(c.is_a(math.Numerical)) self.assertFalse(c.is_a(cuba.relationship))