diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fe5c3ac41da7eb3c1e1698ea9c2c259de789846..4d5cf2d4a53c605bd0305c87c0732b52207727d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * New setup extra `test` which installs the dependencies for testing. * The Container class has a new member function `filter` which is based o `_filter_entity_list`. +* The `Entity` properties `_cuid` and `_flags` are now available for read-only access + as `cuid` and `flags`, respectively. ### Changed ### diff --git a/src/linkahead/common/models.py b/src/linkahead/common/models.py index 031d8058def2866d3a3d4c3b16438fd22f871a5f..8bd8eacda1035761bbc7b9aff4134fc45f682da0 100644 --- a/src/linkahead/common/models.py +++ b/src/linkahead/common/models.py @@ -349,6 +349,15 @@ class Entity: def pickup(self, new_pickup): self.__pickup = new_pickup + @property # getter for _cuid + def cuid(self): + # Set if None? + return self._cuid + + @property # getter for _flags + def flags(self): + return self._flags.copy() # for dict[str, str] shallow copy is enough + def grant( self, realm: Optional[str] = None, @@ -1342,7 +1351,8 @@ class Entity: else: dt_str = xml2str(self.datatype.to_xml(visited_entities=visited_entities.copy())) # Todo: Use for pretty-printing with calls from _repr_ only? - # dt_str = dt_str.replace('<', 'á¸').replace('>', 'á³').replace(' ', 'â €').replace('"', '\'').replace('\n', '') + # dt_str = dt_str.replace('<', 'á¸').replace('>', 'á³').replace(' ', 'â €').replace( + # '"', '\'').replace('\n', '') xml.set("datatype", dt_str) else: xml.set("datatype", str(self.datatype)) @@ -3758,6 +3768,7 @@ class Container(list): """ return _filter_entity_list(self, pid=pid, name=name, entity=entity, conjunction=conjunction) + @staticmethod def _find_dependencies_in_container(container: Container): """Find elements in a container that are a dependency of another element of the same. diff --git a/unittests/test_container.py b/unittests/test_container.py index 4ef85910fcd2f5328b5208122a8683d4ce3b1ed6..715a6eb8f409c489413120ca72857808029d323a 100644 --- a/unittests/test_container.py +++ b/unittests/test_container.py @@ -70,7 +70,8 @@ def test_get_property_values(): ) assert len(table) == 2 house_row = table[0] - assert house_row == (house.name, 40.2, "ft", window.id, None, None, None, 20.5, 20.5, "m", owner.name) + assert house_row == (house.name, 40.2, "ft", window.id, None, None, None, 20.5, 20.5, "m", + owner.name) owner_row = table[1] assert owner_row == (owner.name, None, None, None, None, None, None, None, None, None, None) @@ -200,11 +201,12 @@ def test_container_slicing(): with pytest.raises(TypeError): cont[[0, 2, 3]] + def test_container_filter(): # this is a very rudimentary test since filter is based on _filter_entity_list which is tested # separately cont = db.Container() cont.extend([db.Record(name=f"TestRec{ii+1}") for ii in range(5)]) recs = cont.filter(name="TestRec2") - assert len(recs)==1 - recs[0].name =="TestRec2" + assert len(recs) == 1 + recs[0].name == "TestRec2"