diff options
author | Walter Dörwald <walter@livinglogic.de> | 2007-05-03 21:05:51 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2007-05-03 21:05:51 (GMT) |
commit | aa97f0496412ed834aada921e29588ed16d68e40 (patch) | |
tree | cfe74cb3cd3ed5a27cbcfa404ea9fc8c73fd63f1 /Lib/test | |
parent | 5d7a7001d9df605606b249b3e11707d6d1ad2e3d (diff) | |
download | cpython-aa97f0496412ed834aada921e29588ed16d68e40.zip cpython-aa97f0496412ed834aada921e29588ed16d68e40.tar.gz cpython-aa97f0496412ed834aada921e29588ed16d68e40.tar.bz2 |
Fix various spots where int/long and str/unicode unification
lead to type checks like isinstance(foo, (str, str)) or
isinstance(foo, (int, int)).
Diffstat (limited to 'Lib/test')
-rwxr-xr-x | Lib/test/test_array.py | 2 | ||||
-rw-r--r-- | Lib/test/test_long.py | 2 | ||||
-rw-r--r-- | Lib/test/test_struct.py | 9 | ||||
-rw-r--r-- | Lib/test/test_unicode.py | 40 |
4 files changed, 24 insertions, 29 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index b845570..5278f23 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -65,7 +65,7 @@ class BaseTest(unittest.TestCase): bi = a.buffer_info() self.assert_(isinstance(bi, tuple)) self.assertEqual(len(bi), 2) - self.assert_(isinstance(bi[0], (int, int))) + self.assert_(isinstance(bi[0], int)) self.assert_(isinstance(bi[1], int)) self.assertEqual(bi[1], len(a)) diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index 2876f83..1f65202 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -426,7 +426,7 @@ class LongTest(unittest.TestCase): # represents all Python ints, longs and floats exactly). class Rat: def __init__(self, value): - if isinstance(value, (int, int)): + if isinstance(value, int): self.n = value self.d = 1 elif isinstance(value, float): diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index b62d74c..c3df222 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -492,12 +492,11 @@ test_705836() def test_1229380(): import sys for endian in ('', '>', '<'): - for cls in (int, int): - for fmt in ('B', 'H', 'I', 'L'): - deprecated_err(struct.pack, endian + fmt, cls(-1)) + for fmt in ('B', 'H', 'I', 'L'): + deprecated_err(struct.pack, endian + fmt, -1) - deprecated_err(struct.pack, endian + 'B', cls(300)) - deprecated_err(struct.pack, endian + 'H', cls(70000)) + deprecated_err(struct.pack, endian + 'B', 300) + deprecated_err(struct.pack, endian + 'H', 70000) deprecated_err(struct.pack, endian + 'I', sys.maxint * 4) deprecated_err(struct.pack, endian + 'L', sys.maxint * 4) diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 3dd92ae..ccfa922 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -134,31 +134,27 @@ class UnicodeTest( def test_index(self): string_tests.CommonTest.test_index(self) - # check mixed argument types - for (t1, t2) in ((str, str), (str, str)): - self.checkequalnofix(0, t1('abcdefghiabc'), 'index', t2('')) - self.checkequalnofix(3, t1('abcdefghiabc'), 'index', t2('def')) - self.checkequalnofix(0, t1('abcdefghiabc'), 'index', t2('abc')) - self.checkequalnofix(9, t1('abcdefghiabc'), 'index', t2('abc'), 1) - self.assertRaises(ValueError, t1('abcdefghiabc').index, t2('hib')) - self.assertRaises(ValueError, t1('abcdefghiab').index, t2('abc'), 1) - self.assertRaises(ValueError, t1('abcdefghi').index, t2('ghi'), 8) - self.assertRaises(ValueError, t1('abcdefghi').index, t2('ghi'), -1) + self.checkequalnofix(0, 'abcdefghiabc', 'index', '') + self.checkequalnofix(3, 'abcdefghiabc', 'index', 'def') + self.checkequalnofix(0, 'abcdefghiabc', 'index', 'abc') + self.checkequalnofix(9, 'abcdefghiabc', 'index', 'abc', 1) + self.assertRaises(ValueError, 'abcdefghiabc'.index, 'hib') + self.assertRaises(ValueError, 'abcdefghiab'.index, 'abc', 1) + self.assertRaises(ValueError, 'abcdefghi'.index, 'ghi', 8) + self.assertRaises(ValueError, 'abcdefghi'.index, 'ghi', -1) def test_rindex(self): string_tests.CommonTest.test_rindex(self) - # check mixed argument types - for (t1, t2) in ((str, str), (str, str)): - self.checkequalnofix(12, t1('abcdefghiabc'), 'rindex', t2('')) - self.checkequalnofix(3, t1('abcdefghiabc'), 'rindex', t2('def')) - self.checkequalnofix(9, t1('abcdefghiabc'), 'rindex', t2('abc')) - self.checkequalnofix(0, t1('abcdefghiabc'), 'rindex', t2('abc'), 0, -1) - - self.assertRaises(ValueError, t1('abcdefghiabc').rindex, t2('hib')) - self.assertRaises(ValueError, t1('defghiabc').rindex, t2('def'), 1) - self.assertRaises(ValueError, t1('defghiabc').rindex, t2('abc'), 0, -1) - self.assertRaises(ValueError, t1('abcdefghi').rindex, t2('ghi'), 0, 8) - self.assertRaises(ValueError, t1('abcdefghi').rindex, t2('ghi'), 0, -1) + self.checkequalnofix(12, 'abcdefghiabc', 'rindex', '') + self.checkequalnofix(3, 'abcdefghiabc', 'rindex', 'def') + self.checkequalnofix(9, 'abcdefghiabc', 'rindex', 'abc') + self.checkequalnofix(0, 'abcdefghiabc', 'rindex', 'abc', 0, -1) + + self.assertRaises(ValueError, 'abcdefghiabc'.rindex, 'hib') + self.assertRaises(ValueError, 'defghiabc'.rindex, 'def', 1) + self.assertRaises(ValueError, 'defghiabc'.rindex, 'abc', 0, -1) + self.assertRaises(ValueError, 'abcdefghi'.rindex, 'ghi', 0, 8) + self.assertRaises(ValueError, 'abcdefghi'.rindex, 'ghi', 0, -1) def test_translate(self): self.checkequalnofix('bbbc', 'abababc', 'translate', {ord('a'):None}) |