PY3: convert samba.tests.strings to Py2/Py3
authorNoel Power <noel.power@suse.com>
Sat, 4 Aug 2018 20:00:06 +0000 (21:00 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 23 Oct 2018 03:50:26 +0000 (05:50 +0200)
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

python/samba/tests/strings.py

index 67c73319b04dd46270b33cf75f5314b3cf8f5a3c..3ce778ddd0025be52be73052d6589404c4fa9d45 100644 (file)
 # 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)