mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
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
This commit is contained in:
parent
2323972773
commit
8d7830b6fc
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user