Repository: SINTEF/dlite (language: python)

Issue:
test for old entities
Test that an entity writte in the old format is euqal to an entity in the new format.
Make sure to add various shapes etc.


Discussion / hints:

Fix patch:
diff --git a/bindings/python/dlite-entity-python.i b/bindings/python/dlite-entity-python.i
index 3a0581078..b68478618 100644
--- a/bindings/python/dlite-entity-python.i
+++ b/bindings/python/dlite-entity-python.i
@@ -81,6 +81,13 @@ class Metadata(Instance):
                 inst[k] = v
         return inst
 
+    # For convenience. Easier to use than self.properties["properties"]
+    props = property(
+        fget=lambda self: {p.name: p for p in self.properties["properties"]},
+        doc="A dict mapping property name to the `Property` object for the "
+        "described metadata.",
+    )
+
     def getprop(self, name):
         """Returns the metadata property object with the given name."""
         if "properties" not in self.properties:
@@ -173,6 +180,10 @@ def get_instance(id: str, metaid: str = None, check_storages: bool = True) -> "I
         return 'Dimension(name=%r, description=%r)' % (
             self.name, self.description)
 
+    def __eq__(self, other):
+        """Returns true if `other` equals self."""
+        return self.asdict() == other.asdict()
+
     def asdict(self):
         """Returns a dict representation of self."""
         d = {}
@@ -202,6 +213,10 @@ def get_instance(id: str, metaid: str = None, check_storages: bool = True) -> "I
         return 'Property(%r, type=%r%s%s%s%s)' % (
             self.name, self.type, ref, shape, unit, descr)
 
+    def __eq__(self, other):
+        """Returns true if `other` equals self."""
+        return self.asdict() == other.asdict()
+
     def asdict(self, soft7=True, exclude_name=False):
         """Returns a dict representation of self.
 
@@ -356,11 +371,6 @@ def get_instance(id: str, metaid: str = None, check_storages: bool = True) -> "I
     is_meta = property(_is_meta, doc='Whether this is a metadata instance.')
     is_metameta = property(_is_metameta,
                            doc='Whether this is a meta-metadata instance.')
-    namespace = property(
-        lambda self: Namespace(self.get_uri() + '#'),
-        doc='A tripper.Namespace reference to this instance. '
-        'Note, this requires tripper to be installed.'
-    )
 
     @classmethod
     def from_metaid(cls, metaid, dims, id=None):


Test patch:
diff --git a/bindings/python/tests/entities/PersonNew.json b/bindings/python/tests/entities/PersonNew.json
new file mode 100644
index 000000000..7a1640313
--- /dev/null
+++ b/bindings/python/tests/entities/PersonNew.json
@@ -0,0 +1,23 @@
+{
+  "uri": "http://onto-ns.com/meta/0.1/PersonNew",
+  "description": "A person.",
+  "dimensions": {
+    "N": "Number of skills."
+  },
+  "properties": {
+    "name": {
+      "type": "string",
+      "description": "Full name."
+    },
+    "age": {
+      "type": "float",
+      "unit": "years",
+      "description": "Age of person."
+    },
+    "skills": {
+      "type": "string",
+      "shape": ["N"],
+      "description": "List of skills."
+    }
+  }
+}
diff --git a/bindings/python/tests/entities/PersonOld.json b/bindings/python/tests/entities/PersonOld.json
new file mode 100644
index 000000000..5af8c8d73
--- /dev/null
+++ b/bindings/python/tests/entities/PersonOld.json
@@ -0,0 +1,31 @@
+{
+  "name": "PersonOld",
+  "version": "0.1",
+  "namespace": "http://onto-ns.com/meta",
+  "description": "A person.",
+  "dimensions": [
+    {
+      "name": "N",
+      "description": "Number of skills."
+    }
+  ],
+  "properties": [
+    {
+      "name": "name",
+      "type": "string",
+      "description": "Full name."
+    },
+    {
+      "name": "age",
+      "type": "float",
+      "unit": "years",
+      "description": "Age of person."
+    },
+    {
+      "name": "skills",
+      "type": "string",
+      "dims": ["N"],
+      "description": "List of skills."
+    }
+  ]
+}
diff --git a/bindings/python/tests/test_entity.py b/bindings/python/tests/test_entity.py
index 84c87a9bd..aacc5c198 100755
--- a/bindings/python/tests/test_entity.py
+++ b/bindings/python/tests/test_entity.py
@@ -12,7 +12,9 @@
 
 thisdir = Path(__file__).absolute().parent
 indir = thisdir / "input"
+entitydir = thisdir / "entities"
 dlite.storage_path.append(indir / "*.json")
+dlite.storage_path.append(entitydir / "*.json")
 
 url = f"json://{thisdir}/MyEntity.json"
 
@@ -325,3 +327,10 @@
 # For issue #691
 with raises(dlite.DLiteStorageOpenError):
     Invalid3 = dlite.Instance.from_location("json", indir / "Invalid3.json")
+
+
+# For issue #702
+PersonOld = dlite.get_instance("http://onto-ns.com/meta/0.1/PersonOld")
+PersonNew = dlite.get_instance("http://onto-ns.com/meta/0.1/PersonNew")
+assert PersonOld.props == PersonNew.props
+assert PersonOld.dimnames() == PersonNew.dimnames()