Handle entity equality comparison against non-matching types
Signed-off-by: martin f. krafft <madduck@madduck.net>
diff --git a/reclass/datatypes/entity.py b/reclass/datatypes/entity.py
index 2606e9e..ed10e0d 100644
--- a/reclass/datatypes/entity.py
+++ b/reclass/datatypes/entity.py
@@ -59,7 +59,8 @@
self._parameters.interpolate()
def __eq__(self, other):
- return self._applications == other._applications \
+ return isinstance(other, type(self)) \
+ and self._applications == other._applications \
and self._classes == other._classes \
and self._parameters == other._parameters \
and self._name == other._name
diff --git a/reclass/datatypes/tests/test_entity.py b/reclass/datatypes/tests/test_entity.py
index d4f85b3..fdfb8f4 100644
--- a/reclass/datatypes/tests/test_entity.py
+++ b/reclass/datatypes/tests/test_entity.py
@@ -68,6 +68,13 @@
for i in instances:
i.__eq__.assert_called_once_with(i)
+ def test_unequal_types(self, **types):
+ instances = self._make_instances(**types)
+ self.assertNotEqual(Entity(*instances, name='empty'),
+ None)
+ for i in instances:
+ self.assertEqual(i.__eq__.call_count, 0)
+
def _test_constructor_wrong_types(self, which_replace, **types):
instances = self._make_instances(**types)
instances[which_replace] = 'Invalid type'