Strengthen test_unicode with explicit type checking for assertEqual tests.

This commit is contained in:
Florent Xicluna 2010-09-13 08:53:00 +00:00
parent 60d512c3b0
commit c0c0b14671
3 changed files with 25 additions and 9 deletions

View File

@ -254,7 +254,7 @@ class CommonTest(unittest.TestCase):
r2 = j in i
self.assertEqual(r1, r2)
if loc != -1:
self.assertEqual(i[loc:loc+len(j)], j)
self.assertEqual(i[loc:loc+len(j)], self.fixtype(j))
# issue 7458
self.checkequal(-1, 'ab', 'rfind', 'xxx', sys.maxsize + 1, 0)

View File

@ -34,6 +34,16 @@ class UnicodeTest(
):
type2test = unicode
def assertEqual(self, first, second, msg=None):
# strict assertEqual method: reject implicit bytes/unicode equality
super(UnicodeTest, self).assertEqual(first, second, msg)
if isinstance(first, unicode) or isinstance(second, unicode):
self.assertIsInstance(first, unicode)
self.assertIsInstance(second, unicode)
elif isinstance(first, str) or isinstance(second, str):
self.assertIsInstance(first, str)
self.assertIsInstance(second, str)
def checkequalnofix(self, result, object, methodname, *args):
method = getattr(object, methodname)
realresult = method(*args)
@ -197,9 +207,9 @@ class UnicodeTest(
def test_comparison(self):
# Comparisons:
self.assertEqual(u'abc', 'abc')
self.assertEqual('abc', u'abc')
self.assertEqual(u'abc', u'abc')
self.assertTrue(u'abc' == 'abc')
self.assertTrue('abc' == u'abc')
self.assertTrue(u'abc' == u'abc')
self.assertTrue(u'abcd' > 'abc')
self.assertTrue('abcd' > u'abc')
self.assertTrue(u'abcd' > u'abc')
@ -398,8 +408,10 @@ class UnicodeTest(
for num in range(0x00,0x80):
char = chr(num)
self.assertEqual(u"%c" % char, char)
self.assertEqual(u"%c" % num, char)
self.assertEqual(u"%c" % char, unicode(char))
self.assertEqual(u"%c" % num, unicode(char))
self.assertTrue(char == u"%c" % char)
self.assertTrue(char == u"%c" % num)
# Issue 7649
for num in range(0x80,0x100):
uchar = unichr(num)
@ -558,9 +570,11 @@ class UnicodeTest(
set_o = '!"#$%&*;<=>@[]^_`{|}'
for c in set_d:
self.assertEqual(c.encode('utf7'), c.encode('ascii'))
self.assertEqual(c.encode('ascii').decode('utf7'), c)
self.assertEqual(c.encode('ascii').decode('utf7'), unicode(c))
self.assertTrue(c == c.encode('ascii').decode('utf7'))
for c in set_o:
self.assertEqual(c.encode('ascii').decode('utf7'), c)
self.assertEqual(c.encode('ascii').decode('utf7'), unicode(c))
self.assertTrue(c == c.encode('ascii').decode('utf7'))
def test_codecs_utf8(self):
self.assertEqual(u''.encode('utf-8'), '')
@ -1364,7 +1378,7 @@ class UnicodeTest(
return u'__unicode__ overridden'
u = U(u'xxx')
self.assertEqual("%s" % u, u'__unicode__ overridden')
self.assertEqual("{}".format(u), u'__unicode__ overridden')
self.assertEqual("{}".format(u), '__unicode__ overridden')
def test_main():

View File

@ -337,6 +337,8 @@ Build
Tests
-----
- Strengthen test_unicode with explicit type checking for assertEqual tests.
- Issue #8857: Provide a test case for socket.getaddrinfo.
- Issue #7564: Skip test_ioctl if another process is attached to /dev/tty.