Skip to content

Commit eb52669

Browse files
committed
Tests for issue #89: incorrect isinstance checks with subclasses of future types
1 parent d824e8b commit eb52669

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

future/tests/test_bytes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ def test_bytes_fromhex(self):
9999
def test_isinstance_bytes(self):
100100
self.assertTrue(isinstance(bytes(b'blah'), bytes))
101101

102+
def test_isinstance_bytes_subclass(self):
103+
"""
104+
Issue #89
105+
"""
106+
value = bytes(b'abc')
107+
class Magic(bytes):
108+
pass
109+
self.assertTrue(isinstance(value, bytes))
110+
self.assertFalse(isinstance(value, Magic))
111+
102112
def test_isinstance_oldbytestrings_bytes(self):
103113
"""
104114
Watch out for this. Byte-strings produced in various places in Py2

future/tests/test_dict.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ def test_isinstance_dict(self):
6464
d = self.d1
6565
self.assertTrue(isinstance(d, dict))
6666

67+
def test_isinstance_dict_subclass(self):
68+
"""
69+
Issue #89
70+
"""
71+
value = dict()
72+
class Magic(dict):
73+
pass
74+
self.assertTrue(isinstance(value, dict))
75+
self.assertFalse(isinstance(value, Magic))
76+
6777
def test_dict_getitem(self):
6878
d = dict({'C': 1, 'B': 2, 'A': 3})
6979
self.assertEqual(d['C'], 1)

future/tests/test_int.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ def cpython_only(f):
4949

5050
class IntTestCases(unittest.TestCase):
5151

52+
def test_isinstance_int_subclass(self):
53+
"""
54+
Issue #89
55+
"""
56+
value = int(10)
57+
class Magic(int):
58+
pass
59+
self.assertTrue(isinstance(value, int))
60+
self.assertFalse(isinstance(value, Magic))
61+
5262
def test_basic(self):
5363
self.assertEqual(int(314), 314)
5464
self.assertEqual(int(3.14), 3)

future/tests/test_list.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ def test_isinstance_list(self):
1414
self.assertTrue(isinstance([], list))
1515
self.assertEqual([1, 2, 3], list([1, 2, 3]))
1616

17+
def test_isinstance_list_subclass(self):
18+
"""
19+
Issue #89
20+
"""
21+
value = list([1, 2, 3])
22+
class Magic(list):
23+
pass
24+
self.assertTrue(isinstance(value, list))
25+
self.assertFalse(isinstance(value, Magic))
26+
1727
def test_list_empty(self):
1828
"""
1929
list() -> []

future/tests/test_str.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ def test_str_hasattr_decode(self):
9494
def test_isinstance_str(self):
9595
self.assertTrue(isinstance(str('blah'), str))
9696

97+
def test_isinstance_str_subclass(self):
98+
"""
99+
Issue #89
100+
"""
101+
value = str(u'abc')
102+
class Magic(str):
103+
pass
104+
self.assertTrue(isinstance(value, str))
105+
self.assertFalse(isinstance(value, Magic))
106+
97107
def test_str_getitem(self):
98108
s = str('ABCD')
99109
self.assertNotEqual(s[0], 65)

0 commit comments

Comments
 (0)