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
This commit is contained in:
gengchc2 2016-09-05 15:59:13 +08:00 committed by mark mcclain
parent 59e25b504d
commit 93d61f3689
3 changed files with 12 additions and 0 deletions

View File

@ -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'])

View File

@ -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

View File

@ -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')
)