From: Joe Guo Date: Mon, 26 Mar 2018 04:07:33 +0000 (+1300) Subject: selftest: enable py3 for samba.tests.common X-Git-Tag: talloc-2.1.13~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0ebf52744c5171d4eb5f0b0616d3880d7bbd9db4;p=thirdparty%2Fsamba.git selftest: enable py3 for samba.tests.common fix dsdb_Dn comparison for Python 3 In Python 3, the builtin `cmp` funtion was dropped. And the `__cmp__` magic method in object is no longer honored, which is replaced by 6 new methods: __eq__, __ne__, __lt__, __le__, __gt__, __ge__. This caused `tests.CommonTests` failed with `py3_compatiable=True`. Fixed by adding the above methods. Signed-off-by: Joe Guo Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- diff --git a/python/samba/common.py b/python/samba/common.py index 1c410a4702d..66003993730 100644 --- a/python/samba/common.py +++ b/python/samba/common.py @@ -23,6 +23,14 @@ from samba.ndr import ndr_pack from samba.dcerpc import misc import binascii +from samba.compat import PY3 + + +if PY3: + # cmp() exists only in Python 2 + def cmp(a, b): + return (a > b) - (a < b) + def confirm(msg, forced=False, allow_all=False): """confirm an action with the user @@ -110,6 +118,25 @@ class dsdb_Dn(object): v = cmp(dn1.binary, dn2.binary) return v + # In Python3, __cmp__ is replaced by these 6 methods + def __eq__(self, other): + return self.__cmp__(other) == 0 + + def __ne__(self, other): + return self.__cmp__(other) != 0 + + def __lt__(self, other): + return self.__cmp__(other) < 0 + + def __le__(self, other): + return self.__cmp__(other) <= 0 + + def __gt__(self, other): + return self.__cmp__(other) > 0 + + def __ge__(self, other): + return self.__cmp__(other) >= 0 + def get_binary_integer(self): '''return binary part of a dsdb_Dn as an integer, or None''' if self.prefix == '': diff --git a/selftest/tests.py b/selftest/tests.py index a2ccee771ee..24ed0c6819d 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -64,7 +64,7 @@ planpythontestsuite("none", "samba.tests.dcerpc.integer") planpythontestsuite("none", "samba.tests.param", py3_compatible=True) planpythontestsuite("none", "samba.tests.upgrade", py3_compatible=True) planpythontestsuite("none", "samba.tests.core", py3_compatible=True) -planpythontestsuite("none", "samba.tests.common") +planpythontestsuite("none", "samba.tests.common", py3_compatible=True) planpythontestsuite("none", "samba.tests.provision", py3_compatible=True) planpythontestsuite("none", "samba.tests.password_quality", py3_compatible=True) planpythontestsuite("none", "samba.tests.strings")