From 71f51dd30ad8cfabaf78db805ecc49c2978b40af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Fri, 10 Jan 2025 12:46:21 +0100 Subject: [PATCH] TST: add unittest for deprecation warning --- src/linkahead/common/models.py | 4 ++-- unittests/test_entity.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/linkahead/common/models.py b/src/linkahead/common/models.py index c83354f..18508d5 100644 --- a/src/linkahead/common/models.py +++ b/src/linkahead/common/models.py @@ -2564,7 +2564,7 @@ class PropertyList(list): def filter(self, *args, **kwargs): warnings.warn(DeprecationWarning("This function was renamed to filter_by_identity.")) - return self.filter(*args, **kwargs) + return self.filter_by_identity(*args, **kwargs) def filter_by_identity(self, prop: Optional[Property] = None, pid: Union[None, str, int] = None, @@ -2735,7 +2735,7 @@ class ParentList(list): def filter(self, *args, **kwargs): warnings.warn(DeprecationWarning("This function was renamed to filter_by_identity.")) - return self.filter(*args, **kwargs) + return self.filter_by_identity(*args, **kwargs) def filter_by_identity(self, parent: Optional[Parent] = None, pid: Union[None, str, int] = None, diff --git a/unittests/test_entity.py b/unittests/test_entity.py index e946fd4..da05778 100644 --- a/unittests/test_entity.py +++ b/unittests/test_entity.py @@ -29,6 +29,7 @@ import unittest import linkahead from linkahead import (INTEGER, Entity, Parent, Property, Record, RecordType, configure_connection) +import warnings from linkahead.common.models import SPECIAL_ATTRIBUTES from linkahead.connection.mockup import MockUpServerConnection from lxml import etree @@ -282,3 +283,16 @@ def test_filter_by_identity(): assert len(r8.properties.filter_by_identity(name="B")) == 3 assert len(r8.properties.filter_by_identity(name="C")) == 1 assert len(r8.properties.filter_by_identity(pid=12)) == 1 + + + with warnings.catch_warnings(record=True) as w: + # Cause all warnings to always be triggered. + warnings.simplefilter("always") + + r7.properties.filter(pid=34) + assert issubclass(w[-1].category, DeprecationWarning) + assert "This function was renamed" in str(w[-1].message) + + t.parents.filter(pid=234) + assert issubclass(w[-1].category, DeprecationWarning) + assert "This function was renamed" in str(w[-1].message) -- GitLab