From 93d61f36890e8da77d6b996175fa3c3c580cad59 Mon Sep 17 00:00:00 2001 From: gengchc2 Date: Mon, 5 Sep 2016 15:59:13 +0800 Subject: [PATCH] Add __ne__ built-in function for astara In Python 3 __ne__ by default delegates to __eq__ and inverts the result,but in Python 2 they urge you to define __ne__ when you define __eq__ for it to work properly.There are no implied relationships among the comparison operators. The truth of x==y does not imply that x!=y is false.Accordingly, when defining __eq__(), one should also define __ne__() so that the operators will behave as expected. Change-Id: I9859ad3bdf304ba87d04c9ecabf069b0fdfe4b45 --- astara/api/neutron.py | 6 ++++++ astara/common/linux/ip_lib.py | 3 +++ astara/test/unit/test_debug.py | 3 +++ 3 files changed, 12 insertions(+) diff --git a/astara/api/neutron.py b/astara/api/neutron.py index ad1cf09d..4c5683d5 100644 --- a/astara/api/neutron.py +++ b/astara/api/neutron.py @@ -362,6 +362,9 @@ class Port(DictModelBase): def __eq__(self, other): return type(self) == type(other) and vars(self) == vars(other) + def __ne__(self, other): + return not self.__eq__(other) + @property def first_v4(self): for fixed_ip in self.fixed_ips: @@ -396,6 +399,9 @@ class FixedIp(DictModelBase): def __eq__(self, other): return type(self) == type(other) and vars(self) == vars(other) + def __ne__(self, other): + return not self.__eq__(other) + @classmethod def from_dict(cls, d): return cls(d['subnet_id'], d['ip_address']) diff --git a/astara/common/linux/ip_lib.py b/astara/common/linux/ip_lib.py index 51bcc600..97eff543 100644 --- a/astara/common/linux/ip_lib.py +++ b/astara/common/linux/ip_lib.py @@ -160,6 +160,9 @@ class IPDevice(SubProcessBase): return (other is not None and self.name == other.name and self.namespace == other.namespace) + def __ne__(self, other): + return not self.__eq__(other) + def __str__(self): return self.name diff --git a/astara/test/unit/test_debug.py b/astara/test/unit/test_debug.py index 794719e1..83becfc5 100644 --- a/astara/test/unit/test_debug.py +++ b/astara/test/unit/test_debug.py @@ -62,6 +62,9 @@ class TestDebug(base.RugTestBase): def __eq__(self, other): return self.crud == other.crud + def __ne__(self, other): + return not self.__eq__(other) + automaton.return_value.send_message.assert_called_once_with( CrudMatch('update') )