From: Noel Power Date: Sat, 4 Aug 2018 20:00:06 +0000 (+0100) Subject: PY3: convert samba.tests.strings to Py2/Py3 X-Git-Tag: tdb-1.3.17~1248 X-Git-Url: http://git.samba.org/?p=samba.git;a=commitdiff_plain;h=8d7830b6fc1b0cfb2f1dd9e9315aff67dbef3c93 PY3: convert samba.tests.strings to Py2/Py3 Previously the py2 api for strcasecmp_m/strstr_m required strings/unicode but couldn't actually handle unicode with anything other than the default encoding (e.g. ascii). The c-api as been fixed and the encoding steps (which were unnecessary and causing errors in PY3) have been removed --- diff --git a/python/samba/tests/strings.py b/python/samba/tests/strings.py index 67c73319b04..3ce778ddd00 100644 --- a/python/samba/tests/strings.py +++ b/python/samba/tests/strings.py @@ -23,8 +23,13 @@ # best way to do that yet. # # -- mbp +from samba.compat import PY3 +if PY3: + import unicodedata + KATAKANA_LETTER_A = unicodedata.lookup("KATAKANA LETTER A") +else: + from unicodenames import KATAKANA_LETTER_A as KATAKANA_LETTER_A -from unicodenames import * import samba.tests from samba import strcasecmp_m, strstr_m @@ -38,7 +43,6 @@ def signum(a): else: return 0 - class strcasecmp_m_Tests(samba.tests.TestCase): """String comparisons in simple ASCII and unicode""" def test_strcasecmp_m(self): @@ -60,9 +64,7 @@ class strcasecmp_m_Tests(samba.tests.TestCase): (KATAKANA_LETTER_A, 'a', 1), ] for a, b, expect in cases: - self.assertEquals(signum(strcasecmp_m(a.encode('utf-8'), - b.encode('utf-8'))), - expect) + self.assertEquals(signum(strcasecmp_m(a, b)), expect) class strstr_m_Tests(samba.tests.TestCase): @@ -98,8 +100,4 @@ class strstr_m_Tests(samba.tests.TestCase): (KATAKANA_LETTER_A * 3, 'a', None), ] for a, b, expect in cases: - if expect is not None: - expect = expect.encode('utf-8') - self.assertEquals(strstr_m(a.encode('utf-8'), - b.encode('utf-8')), - expect) + self.assertEquals(strstr_m(a, b), expect)