From cf0dc61303319c45979cfd6e3bb3aa2bc9c72f35 Mon Sep 17 00:00:00 2001 From: yuyafei Date: Mon, 4 Jul 2016 16:53:27 +0800 Subject: [PATCH] Add __ne__ built-in function 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 [1]. [1]https://docs.python.org/2/reference/datamodel.html#object.__ne__ Change-Id: Ibc8ca97679c1e036290d8e745eae2dbbca4913ad --- rally/plugins/openstack/scenarios/vm/utils.py | 3 +++ tests/unit/test_mock.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/rally/plugins/openstack/scenarios/vm/utils.py b/rally/plugins/openstack/scenarios/vm/utils.py index 95dc2da4..eeea1c67 100644 --- a/rally/plugins/openstack/scenarios/vm/utils.py +++ b/rally/plugins/openstack/scenarios/vm/utils.py @@ -86,6 +86,9 @@ class Host(object): other, Host.__class__.__name__)) return self.ip == other.ip and self.status == other.status + def __ne__(self, other): + return not self.__eq__(other) + class VMScenario(nova_utils.NovaScenario, cinder_utils.CinderScenario): """Base class for VM scenarios with basic atomic actions. diff --git a/tests/unit/test_mock.py b/tests/unit/test_mock.py index 1b451a4f..15e83d24 100644 --- a/tests/unit/test_mock.py +++ b/tests/unit/test_mock.py @@ -36,6 +36,9 @@ class Variants(object): def __eq__(self, val): return getattr(val, "variants", val) == self.variants + def __ne__(self, other): + return not self.__eq__(other) + def __contains__(self, val): return val in self.variants