mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
use assert[Not]IsInstance where appropriate
This commit is contained in:
parent
f14c7fc33d
commit
b0f5adc3f4
57 changed files with 269 additions and 272 deletions
|
|
@ -410,11 +410,11 @@ class ClassPropertiesAndMethods(unittest.TestCase):
|
|||
def test_python_dicts(self):
|
||||
# Testing Python subclass of dict...
|
||||
self.assertTrue(issubclass(dict, dict))
|
||||
self.assertTrue(isinstance({}, dict))
|
||||
self.assertIsInstance({}, dict)
|
||||
d = dict()
|
||||
self.assertEqual(d, {})
|
||||
self.assertTrue(d.__class__ is dict)
|
||||
self.assertTrue(isinstance(d, dict))
|
||||
self.assertIsInstance(d, dict)
|
||||
class C(dict):
|
||||
state = -1
|
||||
def __init__(self_local, *a, **kw):
|
||||
|
|
@ -427,7 +427,7 @@ class ClassPropertiesAndMethods(unittest.TestCase):
|
|||
def __getitem__(self, key):
|
||||
return self.get(key, 0)
|
||||
def __setitem__(self_local, key, value):
|
||||
self.assertTrue(isinstance(key, type(0)))
|
||||
self.assertIsInstance(key, type(0))
|
||||
dict.__setitem__(self_local, key, value)
|
||||
def setstate(self, state):
|
||||
self.state = state
|
||||
|
|
@ -1222,7 +1222,7 @@ order (MRO) for bases """
|
|||
MyABC.register(Unrelated)
|
||||
|
||||
u = Unrelated()
|
||||
self.assertTrue(isinstance(u, MyABC))
|
||||
self.assertIsInstance(u, MyABC)
|
||||
|
||||
# This used to crash
|
||||
self.assertRaises(TypeError, MyABC.a.__set__, u, 3)
|
||||
|
|
@ -2025,7 +2025,7 @@ order (MRO) for bases """
|
|||
self.assertFalse(hasattr(a, "x"))
|
||||
|
||||
raw = C.__dict__['x']
|
||||
self.assertTrue(isinstance(raw, property))
|
||||
self.assertIsInstance(raw, property)
|
||||
|
||||
attrs = dir(raw)
|
||||
self.assertIn("__doc__", attrs)
|
||||
|
|
@ -4237,29 +4237,29 @@ order (MRO) for bases """
|
|||
pass
|
||||
a = C()
|
||||
pa = Proxy(a)
|
||||
self.assertTrue(isinstance(a, C)) # Baseline
|
||||
self.assertTrue(isinstance(pa, C)) # Test
|
||||
self.assertIsInstance(a, C) # Baseline
|
||||
self.assertIsInstance(pa, C) # Test
|
||||
# Test with a classic subclass
|
||||
class D(C):
|
||||
pass
|
||||
a = D()
|
||||
pa = Proxy(a)
|
||||
self.assertTrue(isinstance(a, C)) # Baseline
|
||||
self.assertTrue(isinstance(pa, C)) # Test
|
||||
self.assertIsInstance(a, C) # Baseline
|
||||
self.assertIsInstance(pa, C) # Test
|
||||
# Test with a new-style class
|
||||
class C(object):
|
||||
pass
|
||||
a = C()
|
||||
pa = Proxy(a)
|
||||
self.assertTrue(isinstance(a, C)) # Baseline
|
||||
self.assertTrue(isinstance(pa, C)) # Test
|
||||
self.assertIsInstance(a, C) # Baseline
|
||||
self.assertIsInstance(pa, C) # Test
|
||||
# Test with a new-style subclass
|
||||
class D(C):
|
||||
pass
|
||||
a = D()
|
||||
pa = Proxy(a)
|
||||
self.assertTrue(isinstance(a, C)) # Baseline
|
||||
self.assertTrue(isinstance(pa, C)) # Test
|
||||
self.assertIsInstance(a, C) # Baseline
|
||||
self.assertIsInstance(pa, C) # Test
|
||||
|
||||
def test_proxy_super(self):
|
||||
# Testing super() for a proxy object...
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue