mirror of https://github.com/python/cpython
use assert[Not]IsInstance where appropriate
This commit is contained in:
parent
f14c7fc33d
commit
b0f5adc3f4
|
@ -451,7 +451,7 @@ class TestMappingProtocol(BasicTestMappingProtocol):
|
|||
ud = mydict.fromkeys('ab')
|
||||
self.assertEqual(ud, {'a':None, 'b':None})
|
||||
# FIXME: the following won't work with UserDict, because it's an old style class
|
||||
# self.assertTrue(isinstance(ud, UserDict.UserDict))
|
||||
# self.assertIsInstance(ud, UserDict.UserDict)
|
||||
self.assertRaises(TypeError, dict.fromkeys)
|
||||
|
||||
class Exc(Exception): pass
|
||||
|
@ -481,7 +481,7 @@ class TestMappingProtocol(BasicTestMappingProtocol):
|
|||
self.assertEqual(d.copy(), {1:1, 2:2, 3:3})
|
||||
d = self._empty_mapping()
|
||||
self.assertEqual(d.copy(), d)
|
||||
self.assertTrue(isinstance(d.copy(), d.__class__))
|
||||
self.assertIsInstance(d.copy(), d.__class__)
|
||||
self.assertRaises(TypeError, d.copy, None)
|
||||
|
||||
def test_get(self):
|
||||
|
@ -586,7 +586,7 @@ class TestHashMappingProtocol(TestMappingProtocol):
|
|||
return UserDict.UserDict()
|
||||
ud = mydict.fromkeys('ab')
|
||||
self.assertEqual(ud, {'a':None, 'b':None})
|
||||
self.assertTrue(isinstance(ud, UserDict.UserDict))
|
||||
self.assertIsInstance(ud, UserDict.UserDict)
|
||||
|
||||
def test_pop(self):
|
||||
TestMappingProtocol.test_pop(self)
|
||||
|
|
|
@ -89,20 +89,20 @@ class TestABC(unittest.TestCase):
|
|||
b = B()
|
||||
self.assertEqual(issubclass(B, A), False)
|
||||
self.assertEqual(issubclass(B, (A,)), False)
|
||||
self.assertEqual(isinstance(b, A), False)
|
||||
self.assertEqual(isinstance(b, (A,)), False)
|
||||
self.assertNotIsInstance(b, A)
|
||||
self.assertNotIsInstance(b, (A,))
|
||||
A.register(B)
|
||||
self.assertEqual(issubclass(B, A), True)
|
||||
self.assertEqual(issubclass(B, (A,)), True)
|
||||
self.assertEqual(isinstance(b, A), True)
|
||||
self.assertEqual(isinstance(b, (A,)), True)
|
||||
self.assertIsInstance(b, A)
|
||||
self.assertIsInstance(b, (A,))
|
||||
class C(B):
|
||||
pass
|
||||
c = C()
|
||||
self.assertEqual(issubclass(C, A), True)
|
||||
self.assertEqual(issubclass(C, (A,)), True)
|
||||
self.assertEqual(isinstance(c, A), True)
|
||||
self.assertEqual(isinstance(c, (A,)), True)
|
||||
self.assertIsInstance(c, A)
|
||||
self.assertIsInstance(c, (A,))
|
||||
|
||||
def test_isinstance_invalidation(self):
|
||||
class A:
|
||||
|
@ -120,15 +120,15 @@ class TestABC(unittest.TestCase):
|
|||
class A:
|
||||
__metaclass__ = abc.ABCMeta
|
||||
A.register(int)
|
||||
self.assertEqual(isinstance(42, A), True)
|
||||
self.assertEqual(isinstance(42, (A,)), True)
|
||||
self.assertIsInstance(42, A)
|
||||
self.assertIsInstance(42, (A,))
|
||||
self.assertEqual(issubclass(int, A), True)
|
||||
self.assertEqual(issubclass(int, (A,)), True)
|
||||
class B(A):
|
||||
pass
|
||||
B.register(basestring)
|
||||
self.assertEqual(isinstance("", A), True)
|
||||
self.assertEqual(isinstance("", (A,)), True)
|
||||
self.assertIsInstance("", A)
|
||||
self.assertIsInstance("", (A,))
|
||||
self.assertEqual(issubclass(str, A), True)
|
||||
self.assertEqual(issubclass(str, (A,)), True)
|
||||
|
||||
|
@ -185,8 +185,8 @@ class TestABC(unittest.TestCase):
|
|||
pass
|
||||
self.assertTrue(issubclass(MyInt, A))
|
||||
self.assertTrue(issubclass(MyInt, (A,)))
|
||||
self.assertTrue(isinstance(42, A))
|
||||
self.assertTrue(isinstance(42, (A,)))
|
||||
self.assertIsInstance(42, A)
|
||||
self.assertIsInstance(42, (A,))
|
||||
|
||||
def test_all_new_methods_are_called(self):
|
||||
class A:
|
||||
|
|
|
@ -63,10 +63,10 @@ class BaseTest(unittest.TestCase):
|
|||
a = array.array(self.typecode, self.example)
|
||||
self.assertRaises(TypeError, a.buffer_info, 42)
|
||||
bi = a.buffer_info()
|
||||
self.assertTrue(isinstance(bi, tuple))
|
||||
self.assertIsInstance(bi, tuple)
|
||||
self.assertEqual(len(bi), 2)
|
||||
self.assertTrue(isinstance(bi[0], (int, long)))
|
||||
self.assertTrue(isinstance(bi[1], int))
|
||||
self.assertIsInstance(bi[0], (int, long))
|
||||
self.assertIsInstance(bi[1], int)
|
||||
self.assertEqual(bi[1], len(a))
|
||||
|
||||
def test_byteswap(self):
|
||||
|
|
|
@ -154,7 +154,7 @@ class AST_Tests(unittest.TestCase):
|
|||
slc = ast.parse("x[::]").body[0].value.slice
|
||||
self.assertIsNone(slc.upper)
|
||||
self.assertIsNone(slc.lower)
|
||||
self.assertTrue(isinstance(slc.step, ast.Name))
|
||||
self.assertIsInstance(slc.step, ast.Name)
|
||||
self.assertEqual(slc.step.id, "None")
|
||||
|
||||
def test_from_import(self):
|
||||
|
|
|
@ -99,7 +99,7 @@ class AugAssignTest(unittest.TestCase):
|
|||
y = x
|
||||
x += 10
|
||||
|
||||
self.assertTrue(isinstance(x, aug_test))
|
||||
self.assertIsInstance(x, aug_test)
|
||||
self.assertTrue(y is not x)
|
||||
self.assertEquals(x.val, 11)
|
||||
|
||||
|
@ -114,7 +114,7 @@ class AugAssignTest(unittest.TestCase):
|
|||
y = x
|
||||
x += 10
|
||||
|
||||
self.assertTrue(isinstance(x, aug_test3))
|
||||
self.assertIsInstance(x, aug_test3)
|
||||
self.assertTrue(y is not x)
|
||||
self.assertEquals(x.val, 13)
|
||||
|
||||
|
|
|
@ -233,15 +233,15 @@ class BoolTest(unittest.TestCase):
|
|||
|
||||
def test_boolean(self):
|
||||
self.assertEqual(True & 1, 1)
|
||||
self.assertTrue(not isinstance(True & 1, bool))
|
||||
self.assertNotIsInstance(True & 1, bool)
|
||||
self.assertIs(True & True, True)
|
||||
|
||||
self.assertEqual(True | 1, 1)
|
||||
self.assertTrue(not isinstance(True | 1, bool))
|
||||
self.assertNotIsInstance(True | 1, bool)
|
||||
self.assertIs(True | True, True)
|
||||
|
||||
self.assertEqual(True ^ 1, 0)
|
||||
self.assertTrue(not isinstance(True ^ 1, bool))
|
||||
self.assertNotIsInstance(True ^ 1, bool)
|
||||
self.assertIs(True ^ True, False)
|
||||
|
||||
def test_fileclosed(self):
|
||||
|
|
|
@ -970,7 +970,7 @@ class ByteArraySubclassTest(unittest.TestCase):
|
|||
|
||||
def test_basic(self):
|
||||
self.assertTrue(issubclass(ByteArraySubclass, bytearray))
|
||||
self.assertTrue(isinstance(ByteArraySubclass(), bytearray))
|
||||
self.assertIsInstance(ByteArraySubclass(), bytearray)
|
||||
|
||||
a, b = b"abcd", b"efgh"
|
||||
_a, _b = ByteArraySubclass(a), ByteArraySubclass(b)
|
||||
|
|
|
@ -1141,14 +1141,14 @@ class Str2StrTest(unittest.TestCase):
|
|||
reader = codecs.getreader("base64_codec")(StringIO.StringIO(sin))
|
||||
sout = reader.read()
|
||||
self.assertEqual(sout, "\x80")
|
||||
self.assertTrue(isinstance(sout, str))
|
||||
self.assertIsInstance(sout, str)
|
||||
|
||||
def test_readline(self):
|
||||
sin = "\x80".encode("base64_codec")
|
||||
reader = codecs.getreader("base64_codec")(StringIO.StringIO(sin))
|
||||
sout = reader.readline()
|
||||
self.assertEqual(sout, "\x80")
|
||||
self.assertTrue(isinstance(sout, str))
|
||||
self.assertIsInstance(sout, str)
|
||||
|
||||
all_unicode_encodings = [
|
||||
"ascii",
|
||||
|
|
|
@ -101,7 +101,7 @@ class TestNamedTuple(unittest.TestCase):
|
|||
Point = namedtuple('Point', 'x y')
|
||||
p = Point(11, 22)
|
||||
|
||||
self.assertTrue(isinstance(p, tuple))
|
||||
self.assertIsInstance(p, tuple)
|
||||
self.assertEqual(p, (11, 22)) # matches a real tuple
|
||||
self.assertEqual(tuple(p), (11, 22)) # coercable to a real tuple
|
||||
self.assertEqual(list(p), [11, 22]) # coercable to a list
|
||||
|
@ -233,7 +233,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
# Check some non-hashables
|
||||
non_samples = [list(), set(), dict()]
|
||||
for x in non_samples:
|
||||
self.assertFalse(isinstance(x, Hashable), repr(x))
|
||||
self.assertNotIsInstance(x, Hashable)
|
||||
self.assertFalse(issubclass(type(x), Hashable), repr(type(x)))
|
||||
# Check some hashables
|
||||
samples = [None,
|
||||
|
@ -243,7 +243,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
int, list, object, type,
|
||||
]
|
||||
for x in samples:
|
||||
self.assertTrue(isinstance(x, Hashable), repr(x))
|
||||
self.assertIsInstance(x, Hashable)
|
||||
self.assertTrue(issubclass(type(x), Hashable), repr(type(x)))
|
||||
self.assertRaises(TypeError, Hashable)
|
||||
# Check direct subclassing
|
||||
|
@ -259,7 +259,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
# Check some non-iterables
|
||||
non_samples = [None, 42, 3.14, 1j]
|
||||
for x in non_samples:
|
||||
self.assertFalse(isinstance(x, Iterable), repr(x))
|
||||
self.assertNotIsInstance(x, Iterable)
|
||||
self.assertFalse(issubclass(type(x), Iterable), repr(type(x)))
|
||||
# Check some iterables
|
||||
samples = [str(),
|
||||
|
@ -269,7 +269,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
(x for x in []),
|
||||
]
|
||||
for x in samples:
|
||||
self.assertTrue(isinstance(x, Iterable), repr(x))
|
||||
self.assertIsInstance(x, Iterable)
|
||||
self.assertTrue(issubclass(type(x), Iterable), repr(type(x)))
|
||||
# Check direct subclassing
|
||||
class I(Iterable):
|
||||
|
@ -283,7 +283,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
non_samples = [None, 42, 3.14, 1j, "".encode('ascii'), "", (), [],
|
||||
{}, set()]
|
||||
for x in non_samples:
|
||||
self.assertFalse(isinstance(x, Iterator), repr(x))
|
||||
self.assertNotIsInstance(x, Iterator)
|
||||
self.assertFalse(issubclass(type(x), Iterator), repr(type(x)))
|
||||
samples = [iter(str()),
|
||||
iter(tuple()), iter(list()), iter(dict()),
|
||||
|
@ -294,7 +294,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
(x for x in []),
|
||||
]
|
||||
for x in samples:
|
||||
self.assertTrue(isinstance(x, Iterator), repr(x))
|
||||
self.assertIsInstance(x, Iterator)
|
||||
self.assertTrue(issubclass(type(x), Iterator), repr(type(x)))
|
||||
self.validate_abstract_methods(Iterator, 'next')
|
||||
|
||||
|
@ -304,14 +304,14 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
(x for x in []),
|
||||
]
|
||||
for x in non_samples:
|
||||
self.assertFalse(isinstance(x, Sized), repr(x))
|
||||
self.assertNotIsInstance(x, Sized)
|
||||
self.assertFalse(issubclass(type(x), Sized), repr(type(x)))
|
||||
samples = [str(),
|
||||
tuple(), list(), set(), frozenset(), dict(),
|
||||
dict().keys(), dict().items(), dict().values(),
|
||||
]
|
||||
for x in samples:
|
||||
self.assertTrue(isinstance(x, Sized), repr(x))
|
||||
self.assertIsInstance(x, Sized)
|
||||
self.assertTrue(issubclass(type(x), Sized), repr(type(x)))
|
||||
self.validate_abstract_methods(Sized, '__len__')
|
||||
|
||||
|
@ -321,14 +321,14 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
(x for x in []),
|
||||
]
|
||||
for x in non_samples:
|
||||
self.assertFalse(isinstance(x, Container), repr(x))
|
||||
self.assertNotIsInstance(x, Container)
|
||||
self.assertFalse(issubclass(type(x), Container), repr(type(x)))
|
||||
samples = [str(),
|
||||
tuple(), list(), set(), frozenset(), dict(),
|
||||
dict().keys(), dict().items(),
|
||||
]
|
||||
for x in samples:
|
||||
self.assertTrue(isinstance(x, Container), repr(x))
|
||||
self.assertIsInstance(x, Container)
|
||||
self.assertTrue(issubclass(type(x), Container), repr(type(x)))
|
||||
self.validate_abstract_methods(Container, '__contains__')
|
||||
|
||||
|
@ -339,7 +339,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
(x for x in []),
|
||||
]
|
||||
for x in non_samples:
|
||||
self.assertFalse(isinstance(x, Callable), repr(x))
|
||||
self.assertNotIsInstance(x, Callable)
|
||||
self.assertFalse(issubclass(type(x), Callable), repr(type(x)))
|
||||
samples = [lambda: None,
|
||||
type, int, object,
|
||||
|
@ -347,7 +347,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
list.append, [].append,
|
||||
]
|
||||
for x in samples:
|
||||
self.assertTrue(isinstance(x, Callable), repr(x))
|
||||
self.assertIsInstance(x, Callable)
|
||||
self.assertTrue(issubclass(type(x), Callable), repr(type(x)))
|
||||
self.validate_abstract_methods(Callable, '__call__')
|
||||
|
||||
|
@ -395,7 +395,7 @@ class TestCollectionABCs(ABCTestCase):
|
|||
|
||||
def test_Set(self):
|
||||
for sample in [set, frozenset]:
|
||||
self.assertTrue(isinstance(sample(), Set))
|
||||
self.assertIsInstance(sample(), Set)
|
||||
self.assertTrue(issubclass(sample, Set))
|
||||
self.validate_abstract_methods(Set, '__contains__', '__iter__', '__len__')
|
||||
|
||||
|
@ -415,9 +415,9 @@ class TestCollectionABCs(ABCTestCase):
|
|||
self.assertTrue(hash(a) == hash(b))
|
||||
|
||||
def test_MutableSet(self):
|
||||
self.assertTrue(isinstance(set(), MutableSet))
|
||||
self.assertIsInstance(set(), MutableSet)
|
||||
self.assertTrue(issubclass(set, MutableSet))
|
||||
self.assertFalse(isinstance(frozenset(), MutableSet))
|
||||
self.assertNotIsInstance(frozenset(), MutableSet)
|
||||
self.assertFalse(issubclass(frozenset, MutableSet))
|
||||
self.validate_abstract_methods(MutableSet, '__contains__', '__iter__', '__len__',
|
||||
'add', 'discard')
|
||||
|
@ -457,24 +457,24 @@ class TestCollectionABCs(ABCTestCase):
|
|||
|
||||
def test_Mapping(self):
|
||||
for sample in [dict]:
|
||||
self.assertTrue(isinstance(sample(), Mapping))
|
||||
self.assertIsInstance(sample(), Mapping)
|
||||
self.assertTrue(issubclass(sample, Mapping))
|
||||
self.validate_abstract_methods(Mapping, '__contains__', '__iter__', '__len__',
|
||||
'__getitem__')
|
||||
|
||||
def test_MutableMapping(self):
|
||||
for sample in [dict]:
|
||||
self.assertTrue(isinstance(sample(), MutableMapping))
|
||||
self.assertIsInstance(sample(), MutableMapping)
|
||||
self.assertTrue(issubclass(sample, MutableMapping))
|
||||
self.validate_abstract_methods(MutableMapping, '__contains__', '__iter__', '__len__',
|
||||
'__getitem__', '__setitem__', '__delitem__')
|
||||
|
||||
def test_Sequence(self):
|
||||
for sample in [tuple, list, str]:
|
||||
self.assertTrue(isinstance(sample(), Sequence))
|
||||
self.assertIsInstance(sample(), Sequence)
|
||||
self.assertTrue(issubclass(sample, Sequence))
|
||||
self.assertTrue(issubclass(basestring, Sequence))
|
||||
self.assertTrue(isinstance(range(10), Sequence))
|
||||
self.assertIsInstance(range(10), Sequence)
|
||||
self.assertTrue(issubclass(xrange, Sequence))
|
||||
self.assertTrue(issubclass(str, Sequence))
|
||||
self.validate_abstract_methods(Sequence, '__contains__', '__iter__', '__len__',
|
||||
|
@ -482,10 +482,10 @@ class TestCollectionABCs(ABCTestCase):
|
|||
|
||||
def test_MutableSequence(self):
|
||||
for sample in [tuple, str]:
|
||||
self.assertFalse(isinstance(sample(), MutableSequence))
|
||||
self.assertNotIsInstance(sample(), MutableSequence)
|
||||
self.assertFalse(issubclass(sample, MutableSequence))
|
||||
for sample in [list]:
|
||||
self.assertTrue(isinstance(sample(), MutableSequence))
|
||||
self.assertIsInstance(sample(), MutableSequence)
|
||||
self.assertTrue(issubclass(sample, MutableSequence))
|
||||
self.assertFalse(issubclass(basestring, MutableSequence))
|
||||
self.validate_abstract_methods(MutableSequence, '__contains__', '__iter__',
|
||||
|
@ -497,8 +497,8 @@ class TestCounter(unittest.TestCase):
|
|||
c = Counter('abcaba')
|
||||
self.assertEqual(c, Counter({'a':3 , 'b': 2, 'c': 1}))
|
||||
self.assertEqual(c, Counter(a=3, b=2, c=1))
|
||||
self.assertTrue(isinstance(c, dict))
|
||||
self.assertTrue(isinstance(c, Mapping))
|
||||
self.assertIsInstance(c, dict)
|
||||
self.assertIsInstance(c, Mapping)
|
||||
self.assertTrue(issubclass(Counter, dict))
|
||||
self.assertTrue(issubclass(Counter, Mapping))
|
||||
self.assertEqual(len(c), 3)
|
||||
|
|
|
@ -249,8 +249,8 @@ if 1:
|
|||
self.fail("How many bits *does* this machine have???")
|
||||
# Verify treatment of contant folding on -(sys.maxint+1)
|
||||
# i.e. -2147483648 on 32 bit platforms. Should return int, not long.
|
||||
self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 1)), int))
|
||||
self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 2)), long))
|
||||
self.assertIsInstance(eval("%s" % (-sys.maxint - 1)), int)
|
||||
self.assertIsInstance(eval("%s" % (-sys.maxint - 2)), long)
|
||||
|
||||
if sys.maxint == 9223372036854775807:
|
||||
def test_32_63_bit_values(self):
|
||||
|
@ -265,7 +265,7 @@ if 1:
|
|||
|
||||
for variable in self.test_32_63_bit_values.func_code.co_consts:
|
||||
if variable is not None:
|
||||
self.assertTrue(isinstance(variable, int))
|
||||
self.assertIsInstance(variable, int)
|
||||
|
||||
def test_sequence_unpacking_error(self):
|
||||
# Verify sequence packing/unpacking with "or". SF bug #757818
|
||||
|
|
|
@ -110,7 +110,7 @@ class CompilerTest(unittest.TestCase):
|
|||
|
||||
def _check_lineno(self, node):
|
||||
if not node.__class__ in NOLINENO:
|
||||
self.assertTrue(isinstance(node.lineno, int),
|
||||
self.assertIsInstance(node.lineno, int,
|
||||
"lineno=%s on %s" % (node.lineno, node.__class__))
|
||||
self.assertTrue(node.lineno > 0,
|
||||
"lineno=%s on %s" % (node.lineno, node.__class__))
|
||||
|
|
|
@ -1043,7 +1043,7 @@ class CookieTests(TestCase):
|
|||
for i in range(4):
|
||||
i = 0
|
||||
for c in cs:
|
||||
self.assertTrue(isinstance(c, Cookie))
|
||||
self.assertIsInstance(c, Cookie)
|
||||
self.assertEquals(c.version, versions[i])
|
||||
self.assertEquals(c.name, names[i])
|
||||
self.assertEquals(c.domain, domains[i])
|
||||
|
|
|
@ -81,7 +81,7 @@ class TestTZInfo(unittest.TestCase):
|
|||
self.__name = name
|
||||
self.assertTrue(issubclass(NotEnough, tzinfo))
|
||||
ne = NotEnough(3, "NotByALongShot")
|
||||
self.assertTrue(isinstance(ne, tzinfo))
|
||||
self.assertIsInstance(ne, tzinfo)
|
||||
|
||||
dt = datetime.now()
|
||||
self.assertRaises(NotImplementedError, ne.tzname, dt)
|
||||
|
@ -90,7 +90,7 @@ class TestTZInfo(unittest.TestCase):
|
|||
|
||||
def test_normal(self):
|
||||
fo = FixedOffset(3, "Three")
|
||||
self.assertTrue(isinstance(fo, tzinfo))
|
||||
self.assertIsInstance(fo, tzinfo)
|
||||
for dt in datetime.now(), None:
|
||||
self.assertEqual(fo.utcoffset(dt), timedelta(minutes=3))
|
||||
self.assertEqual(fo.tzname(dt), "Three")
|
||||
|
@ -111,14 +111,14 @@ class TestTZInfo(unittest.TestCase):
|
|||
# Make sure we can pickle/unpickle an instance of a subclass.
|
||||
offset = timedelta(minutes=-300)
|
||||
orig = PicklableFixedOffset(offset, 'cookie')
|
||||
self.assertTrue(isinstance(orig, tzinfo))
|
||||
self.assertIsInstance(orig, tzinfo)
|
||||
self.assertTrue(type(orig) is PicklableFixedOffset)
|
||||
self.assertEqual(orig.utcoffset(None), offset)
|
||||
self.assertEqual(orig.tzname(None), 'cookie')
|
||||
for pickler, unpickler, proto in pickle_choices:
|
||||
green = pickler.dumps(orig, proto)
|
||||
derived = unpickler.loads(green)
|
||||
self.assertTrue(isinstance(derived, tzinfo))
|
||||
self.assertIsInstance(derived, tzinfo)
|
||||
self.assertTrue(type(derived) is PicklableFixedOffset)
|
||||
self.assertEqual(derived.utcoffset(None), offset)
|
||||
self.assertEqual(derived.tzname(None), 'cookie')
|
||||
|
@ -391,9 +391,9 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
|
|||
self.assertEqual(td, td2)
|
||||
|
||||
def test_resolution_info(self):
|
||||
self.assertTrue(isinstance(timedelta.min, timedelta))
|
||||
self.assertTrue(isinstance(timedelta.max, timedelta))
|
||||
self.assertTrue(isinstance(timedelta.resolution, timedelta))
|
||||
self.assertIsInstance(timedelta.min, timedelta)
|
||||
self.assertIsInstance(timedelta.max, timedelta)
|
||||
self.assertIsInstance(timedelta.resolution, timedelta)
|
||||
self.assertTrue(timedelta.max > timedelta.min)
|
||||
self.assertEqual(timedelta.min, timedelta(-999999999))
|
||||
self.assertEqual(timedelta.max, timedelta(999999999, 24*3600-1, 1e6-1))
|
||||
|
@ -905,9 +905,9 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
|
|||
self.assertEqual(b.__format__(fmt), 'B')
|
||||
|
||||
def test_resolution_info(self):
|
||||
self.assertTrue(isinstance(self.theclass.min, self.theclass))
|
||||
self.assertTrue(isinstance(self.theclass.max, self.theclass))
|
||||
self.assertTrue(isinstance(self.theclass.resolution, timedelta))
|
||||
self.assertIsInstance(self.theclass.min, self.theclass)
|
||||
self.assertIsInstance(self.theclass.max, self.theclass)
|
||||
self.assertIsInstance(self.theclass.resolution, timedelta)
|
||||
self.assertTrue(self.theclass.max > self.theclass.min)
|
||||
|
||||
def test_extreme_timedelta(self):
|
||||
|
@ -1891,9 +1891,9 @@ class TestTime(HarmlessMixedComparison, unittest.TestCase):
|
|||
"%s(23, 15)" % name)
|
||||
|
||||
def test_resolution_info(self):
|
||||
self.assertTrue(isinstance(self.theclass.min, self.theclass))
|
||||
self.assertTrue(isinstance(self.theclass.max, self.theclass))
|
||||
self.assertTrue(isinstance(self.theclass.resolution, timedelta))
|
||||
self.assertIsInstance(self.theclass.min, self.theclass)
|
||||
self.assertIsInstance(self.theclass.max, self.theclass)
|
||||
self.assertIsInstance(self.theclass.resolution, timedelta)
|
||||
self.assertTrue(self.theclass.max > self.theclass.min)
|
||||
|
||||
def test_pickling(self):
|
||||
|
@ -2260,7 +2260,7 @@ class TestTimeTZ(TestTime, TZInfoBase, unittest.TestCase):
|
|||
green = pickler.dumps(orig, proto)
|
||||
derived = unpickler.loads(green)
|
||||
self.assertEqual(orig, derived)
|
||||
self.assertTrue(isinstance(derived.tzinfo, PicklableFixedOffset))
|
||||
self.assertIsInstance(derived.tzinfo, PicklableFixedOffset)
|
||||
self.assertEqual(derived.utcoffset(), timedelta(minutes=-300))
|
||||
self.assertEqual(derived.tzname(), 'cookie')
|
||||
|
||||
|
@ -2487,8 +2487,7 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
|
|||
green = pickler.dumps(orig, proto)
|
||||
derived = unpickler.loads(green)
|
||||
self.assertEqual(orig, derived)
|
||||
self.assertTrue(isinstance(derived.tzinfo,
|
||||
PicklableFixedOffset))
|
||||
self.assertIsInstance(derived.tzinfo, PicklableFixedOffset)
|
||||
self.assertEqual(derived.utcoffset(), timedelta(minutes=-300))
|
||||
self.assertEqual(derived.tzname(), 'cookie')
|
||||
|
||||
|
|
|
@ -521,7 +521,7 @@ class DecimalExplicitConstructionTest(unittest.TestCase):
|
|||
|
||||
# from int
|
||||
d = nc.create_decimal(456)
|
||||
self.assertTrue(isinstance(d, Decimal))
|
||||
self.assertIsInstance(d, Decimal)
|
||||
self.assertEqual(nc.create_decimal(45678),
|
||||
nc.create_decimal('457E+2'))
|
||||
|
||||
|
@ -1529,7 +1529,7 @@ class DecimalPythonAPItests(unittest.TestCase):
|
|||
def test_abc(self):
|
||||
self.assertTrue(issubclass(Decimal, numbers.Number))
|
||||
self.assertTrue(not issubclass(Decimal, numbers.Real))
|
||||
self.assertTrue(isinstance(Decimal(0), numbers.Number))
|
||||
self.assertIsInstance(Decimal(0), numbers.Number)
|
||||
self.assertTrue(not isinstance(Decimal(0), numbers.Real))
|
||||
|
||||
def test_pickle(self):
|
||||
|
|
|
@ -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...
|
||||
|
|
|
@ -225,7 +225,7 @@ class DictTest(unittest.TestCase):
|
|||
return UserDict.UserDict()
|
||||
ud = mydict.fromkeys('ab')
|
||||
self.assertEqual(ud, {'a':None, 'b':None})
|
||||
self.assertTrue(isinstance(ud, UserDict.UserDict))
|
||||
self.assertIsInstance(ud, UserDict.UserDict)
|
||||
self.assertRaises(TypeError, dict.fromkeys)
|
||||
|
||||
class Exc(Exception): pass
|
||||
|
|
|
@ -71,17 +71,17 @@ class DictSetTest(unittest.TestCase):
|
|||
|
||||
def test_dict_repr(self):
|
||||
d = {1: 10, "a": "ABC"}
|
||||
self.assertTrue(isinstance(repr(d), str))
|
||||
self.assertIsInstance(repr(d), str)
|
||||
r = repr(d.viewitems())
|
||||
self.assertTrue(isinstance(r, str))
|
||||
self.assertIsInstance(r, str)
|
||||
self.assertTrue(r == "dict_items([('a', 'ABC'), (1, 10)])" or
|
||||
r == "dict_items([(1, 10), ('a', 'ABC')])")
|
||||
r = repr(d.viewkeys())
|
||||
self.assertTrue(isinstance(r, str))
|
||||
self.assertIsInstance(r, str)
|
||||
self.assertTrue(r == "dict_keys(['a', 1])" or
|
||||
r == "dict_keys([1, 'a'])")
|
||||
r = repr(d.viewvalues())
|
||||
self.assertTrue(isinstance(r, str))
|
||||
self.assertIsInstance(r, str)
|
||||
self.assertTrue(r == "dict_values(['ABC', 10])" or
|
||||
r == "dict_values([10, 'ABC'])")
|
||||
|
||||
|
|
|
@ -92,16 +92,16 @@ class MiscTests(unittest.TestCase):
|
|||
|
||||
def test_ident(self):
|
||||
#Test sanity of _thread.get_ident()
|
||||
self.assertTrue(isinstance(_thread.get_ident(), int),
|
||||
"_thread.get_ident() returned a non-integer")
|
||||
self.assertIsInstance(_thread.get_ident(), int,
|
||||
"_thread.get_ident() returned a non-integer")
|
||||
self.assertTrue(_thread.get_ident() != 0,
|
||||
"_thread.get_ident() returned 0")
|
||||
|
||||
def test_LockType(self):
|
||||
#Make sure _thread.LockType is the same type as _thread.allocate_locke()
|
||||
self.assertTrue(isinstance(_thread.allocate_lock(), _thread.LockType),
|
||||
"_thread.LockType is not an instance of what is "
|
||||
"returned by _thread.allocate_lock()")
|
||||
self.assertIsInstance(_thread.allocate_lock(), _thread.LockType,
|
||||
"_thread.LockType is not an instance of what "
|
||||
"is returned by _thread.allocate_lock()")
|
||||
|
||||
def test_interrupt_main(self):
|
||||
#Calling start_new_thread with a function that executes interrupt_main
|
||||
|
|
|
@ -582,36 +582,36 @@ class TestTLS_FTPClass(TestCase):
|
|||
self.server.stop()
|
||||
|
||||
def test_control_connection(self):
|
||||
self.assertFalse(isinstance(self.client.sock, ssl.SSLSocket))
|
||||
self.assertNotIsInstance(self.client.sock, ssl.SSLSocket)
|
||||
self.client.auth()
|
||||
self.assertTrue(isinstance(self.client.sock, ssl.SSLSocket))
|
||||
self.assertIsInstance(self.client.sock, ssl.SSLSocket)
|
||||
|
||||
def test_data_connection(self):
|
||||
# clear text
|
||||
sock = self.client.transfercmd('list')
|
||||
self.assertFalse(isinstance(sock, ssl.SSLSocket))
|
||||
self.assertNotIsInstance(sock, ssl.SSLSocket)
|
||||
sock.close()
|
||||
self.client.voidresp()
|
||||
|
||||
# secured, after PROT P
|
||||
self.client.prot_p()
|
||||
sock = self.client.transfercmd('list')
|
||||
self.assertTrue(isinstance(sock, ssl.SSLSocket))
|
||||
self.assertIsInstance(sock, ssl.SSLSocket)
|
||||
sock.close()
|
||||
self.client.voidresp()
|
||||
|
||||
# PROT C is issued, the connection must be in cleartext again
|
||||
self.client.prot_c()
|
||||
sock = self.client.transfercmd('list')
|
||||
self.assertFalse(isinstance(sock, ssl.SSLSocket))
|
||||
self.assertNotIsInstance(sock, ssl.SSLSocket)
|
||||
sock.close()
|
||||
self.client.voidresp()
|
||||
|
||||
def test_login(self):
|
||||
# login() is supposed to implicitly secure the control connection
|
||||
self.assertFalse(isinstance(self.client.sock, ssl.SSLSocket))
|
||||
self.assertNotIsInstance(self.client.sock, ssl.SSLSocket)
|
||||
self.client.login()
|
||||
self.assertTrue(isinstance(self.client.sock, ssl.SSLSocket))
|
||||
self.assertIsInstance(self.client.sock, ssl.SSLSocket)
|
||||
# make sure that AUTH TLS doesn't get issued again
|
||||
self.client.login()
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ class FunctionPropertiesTest(FuncAttrsTest):
|
|||
a = 12
|
||||
def f(): print a
|
||||
c = f.func_closure
|
||||
self.assertTrue(isinstance(c, tuple))
|
||||
self.assertIsInstance(c, tuple)
|
||||
self.assertEqual(len(c), 1)
|
||||
# don't have a type object handy
|
||||
self.assertEqual(c[0].__class__.__name__, "cell")
|
||||
|
|
|
@ -109,7 +109,7 @@ class FutureTest(unittest.TestCase):
|
|||
def test_unicode_literals_exec(self):
|
||||
scope = {}
|
||||
exec "from __future__ import unicode_literals; x = ''" in scope
|
||||
self.assertTrue(isinstance(scope["x"], unicode))
|
||||
self.assertIsInstance(scope["x"], unicode)
|
||||
|
||||
|
||||
def test_main():
|
||||
|
|
|
@ -9,7 +9,7 @@ from . import test_support
|
|||
class TestMultipleFeatures(unittest.TestCase):
|
||||
|
||||
def test_unicode_literals(self):
|
||||
self.assertTrue(isinstance("", unicode))
|
||||
self.assertIsInstance("", unicode)
|
||||
|
||||
def test_print_function(self):
|
||||
with test_support.captured_output("stderr") as s:
|
||||
|
|
|
@ -12,13 +12,13 @@ class GroupDatabaseTestCase(unittest.TestCase):
|
|||
# attributes promised by the docs
|
||||
self.assertEqual(len(value), 4)
|
||||
self.assertEqual(value[0], value.gr_name)
|
||||
self.assertTrue(isinstance(value.gr_name, basestring))
|
||||
self.assertIsInstance(value.gr_name, basestring)
|
||||
self.assertEqual(value[1], value.gr_passwd)
|
||||
self.assertTrue(isinstance(value.gr_passwd, basestring))
|
||||
self.assertIsInstance(value.gr_passwd, basestring)
|
||||
self.assertEqual(value[2], value.gr_gid)
|
||||
self.assertTrue(isinstance(value.gr_gid, int))
|
||||
self.assertIsInstance(value.gr_gid, int)
|
||||
self.assertEqual(value[3], value.gr_mem)
|
||||
self.assertTrue(isinstance(value.gr_mem, list))
|
||||
self.assertIsInstance(value.gr_mem, list)
|
||||
|
||||
def test_values(self):
|
||||
entries = grp.getgrall()
|
||||
|
|
|
@ -105,11 +105,11 @@ class HashInheritanceTestCase(unittest.TestCase):
|
|||
objects = (self.default_expected +
|
||||
self.fixed_expected)
|
||||
for obj in objects:
|
||||
self.assertTrue(isinstance(obj, Hashable), repr(obj))
|
||||
self.assertIsInstance(obj, Hashable)
|
||||
|
||||
def test_not_hashable(self):
|
||||
for obj in self.error_expected:
|
||||
self.assertFalse(isinstance(obj, Hashable), repr(obj))
|
||||
self.assertNotIsInstance(obj, Hashable)
|
||||
|
||||
|
||||
# Issue #4701: Check that some builtin types are correctly hashable
|
||||
|
|
|
@ -76,15 +76,15 @@ class IntTestCases(unittest.TestCase):
|
|||
s = repr(-1-sys.maxint)
|
||||
x = int(s)
|
||||
self.assertEqual(x+1, -sys.maxint)
|
||||
self.assertTrue(isinstance(x, int))
|
||||
self.assertIsInstance(x, int)
|
||||
# should return long
|
||||
self.assertEqual(int(s[1:]), sys.maxint+1)
|
||||
|
||||
# should return long
|
||||
x = int(1e100)
|
||||
self.assertTrue(isinstance(x, long))
|
||||
self.assertIsInstance(x, long)
|
||||
x = int(-1e100)
|
||||
self.assertTrue(isinstance(x, long))
|
||||
self.assertIsInstance(x, long)
|
||||
|
||||
|
||||
# SF bug 434186: 0x80000000/2 != 0x80000000>>1.
|
||||
|
@ -102,11 +102,11 @@ class IntTestCases(unittest.TestCase):
|
|||
self.assertRaises(ValueError, int, '123\x00 245', 20)
|
||||
|
||||
x = int('1' * 600)
|
||||
self.assertTrue(isinstance(x, long))
|
||||
self.assertIsInstance(x, long)
|
||||
|
||||
if have_unicode:
|
||||
x = int(unichr(0x661) * 600)
|
||||
self.assertTrue(isinstance(x, long))
|
||||
self.assertIsInstance(x, long)
|
||||
|
||||
self.assertRaises(TypeError, int, 1, 12)
|
||||
|
||||
|
|
|
@ -2361,27 +2361,27 @@ class MiscIOTest(unittest.TestCase):
|
|||
|
||||
def test_abcs(self):
|
||||
# Test the visible base classes are ABCs.
|
||||
self.assertTrue(isinstance(self.IOBase, abc.ABCMeta))
|
||||
self.assertTrue(isinstance(self.RawIOBase, abc.ABCMeta))
|
||||
self.assertTrue(isinstance(self.BufferedIOBase, abc.ABCMeta))
|
||||
self.assertTrue(isinstance(self.TextIOBase, abc.ABCMeta))
|
||||
self.assertIsInstance(self.IOBase, abc.ABCMeta)
|
||||
self.assertIsInstance(self.RawIOBase, abc.ABCMeta)
|
||||
self.assertIsInstance(self.BufferedIOBase, abc.ABCMeta)
|
||||
self.assertIsInstance(self.TextIOBase, abc.ABCMeta)
|
||||
|
||||
def _check_abc_inheritance(self, abcmodule):
|
||||
with self.open(support.TESTFN, "wb", buffering=0) as f:
|
||||
self.assertTrue(isinstance(f, abcmodule.IOBase))
|
||||
self.assertTrue(isinstance(f, abcmodule.RawIOBase))
|
||||
self.assertFalse(isinstance(f, abcmodule.BufferedIOBase))
|
||||
self.assertFalse(isinstance(f, abcmodule.TextIOBase))
|
||||
self.assertIsInstance(f, abcmodule.IOBase)
|
||||
self.assertIsInstance(f, abcmodule.RawIOBase)
|
||||
self.assertNotIsInstance(f, abcmodule.BufferedIOBase)
|
||||
self.assertNotIsInstance(f, abcmodule.TextIOBase)
|
||||
with self.open(support.TESTFN, "wb") as f:
|
||||
self.assertTrue(isinstance(f, abcmodule.IOBase))
|
||||
self.assertFalse(isinstance(f, abcmodule.RawIOBase))
|
||||
self.assertTrue(isinstance(f, abcmodule.BufferedIOBase))
|
||||
self.assertFalse(isinstance(f, abcmodule.TextIOBase))
|
||||
self.assertIsInstance(f, abcmodule.IOBase)
|
||||
self.assertNotIsInstance(f, abcmodule.RawIOBase)
|
||||
self.assertIsInstance(f, abcmodule.BufferedIOBase)
|
||||
self.assertNotIsInstance(f, abcmodule.TextIOBase)
|
||||
with self.open(support.TESTFN, "w") as f:
|
||||
self.assertTrue(isinstance(f, abcmodule.IOBase))
|
||||
self.assertFalse(isinstance(f, abcmodule.RawIOBase))
|
||||
self.assertFalse(isinstance(f, abcmodule.BufferedIOBase))
|
||||
self.assertTrue(isinstance(f, abcmodule.TextIOBase))
|
||||
self.assertIsInstance(f, abcmodule.IOBase)
|
||||
self.assertNotIsInstance(f, abcmodule.RawIOBase)
|
||||
self.assertNotIsInstance(f, abcmodule.BufferedIOBase)
|
||||
self.assertIsInstance(f, abcmodule.TextIOBase)
|
||||
|
||||
def test_abc_inheritance(self):
|
||||
# Test implementations inherit from their respective ABCs
|
||||
|
|
|
@ -552,7 +552,7 @@ class LongTest(unittest.TestCase):
|
|||
y = int(x)
|
||||
except OverflowError:
|
||||
self.fail("int(long(sys.maxint) + 1) mustn't overflow")
|
||||
self.assertTrue(isinstance(y, long),
|
||||
self.assertIsInstance(y, long,
|
||||
"int(long(sys.maxint) + 1) should have returned long")
|
||||
|
||||
x = hugeneg_aslong - 1
|
||||
|
@ -560,7 +560,7 @@ class LongTest(unittest.TestCase):
|
|||
y = int(x)
|
||||
except OverflowError:
|
||||
self.fail("int(long(-sys.maxint-1) - 1) mustn't overflow")
|
||||
self.assertTrue(isinstance(y, long),
|
||||
self.assertIsInstance(y, long,
|
||||
"int(long(-sys.maxint-1) - 1) should have returned long")
|
||||
|
||||
class long2(long):
|
||||
|
|
|
@ -635,7 +635,7 @@ class CBytesIOTest(PyBytesIOTest):
|
|||
state = memio.__getstate__()
|
||||
self.assertEqual(len(state), 3)
|
||||
bytearray(state[0]) # Check if state[0] supports the buffer interface.
|
||||
self.assert_(isinstance(state[1], int))
|
||||
self.assertIsInstance(state[1], int)
|
||||
self.assert_(isinstance(state[2], dict) or state[2] is None)
|
||||
memio.close()
|
||||
self.assertRaises(ValueError, memio.__getstate__)
|
||||
|
@ -679,9 +679,9 @@ class CStringIOTest(PyStringIOTest):
|
|||
memio = self.ioclass()
|
||||
state = memio.__getstate__()
|
||||
self.assertEqual(len(state), 4)
|
||||
self.assert_(isinstance(state[0], unicode))
|
||||
self.assert_(isinstance(state[1], str))
|
||||
self.assert_(isinstance(state[2], int))
|
||||
self.assertIsInstance(state[0], unicode)
|
||||
self.assertIsInstance(state[1], str)
|
||||
self.assertIsInstance(state[2], int)
|
||||
self.assert_(isinstance(state[3], dict) or state[3] is None)
|
||||
memio.close()
|
||||
self.assertRaises(ValueError, memio.__getstate__)
|
||||
|
|
|
@ -28,7 +28,7 @@ class AbstractMemoryTests:
|
|||
oldrefcount = sys.getrefcount(b)
|
||||
m = self._view(b)
|
||||
self.assertEquals(m[0], item(b"a"))
|
||||
self.assertTrue(isinstance(m[0], bytes), type(m[0]))
|
||||
self.assertIsInstance(m[0], bytes)
|
||||
self.assertEquals(m[5], item(b"f"))
|
||||
self.assertEquals(m[-1], item(b"f"))
|
||||
self.assertEquals(m[-6], item(b"a"))
|
||||
|
@ -125,7 +125,7 @@ class AbstractMemoryTests:
|
|||
expected = b"".join(
|
||||
self.getitem_type(c) for c in b"abcdef")
|
||||
self.assertEquals(b, expected)
|
||||
self.assertTrue(isinstance(b, bytes), type(b))
|
||||
self.assertIsInstance(b, bytes)
|
||||
|
||||
def test_tolist(self):
|
||||
for tp in self._types:
|
||||
|
|
|
@ -132,7 +132,7 @@ class _TestProcess(BaseTestCase):
|
|||
|
||||
self.assertTrue(current.is_alive())
|
||||
self.assertTrue(not current.daemon)
|
||||
self.assertTrue(isinstance(authkey, bytes))
|
||||
self.assertIsInstance(authkey, bytes)
|
||||
self.assertTrue(len(authkey) > 0)
|
||||
self.assertEqual(current.ident, os.getpid())
|
||||
self.assertEqual(current.exitcode, None)
|
||||
|
|
|
@ -125,8 +125,8 @@ class TestNtpath(unittest.TestCase):
|
|||
|
||||
# Issue 5827: Make sure normpath preserves unicode
|
||||
for path in (u'', u'.', u'/', u'\\', u'///foo/.//bar//'):
|
||||
self.assertTrue(isinstance(ntpath.normpath(path), unicode),
|
||||
'normpath() returned str instead of unicode')
|
||||
self.assertIsInstance(ntpath.normpath(path), unicode,
|
||||
'normpath() returned str instead of unicode')
|
||||
|
||||
def test_expandvars(self):
|
||||
with test_support.EnvironmentVarGuard() as env:
|
||||
|
|
|
@ -64,7 +64,7 @@ class OpcodeTest(unittest.TestCase):
|
|||
|
||||
try: raise DClass, a
|
||||
except DClass, v:
|
||||
self.assertTrue(isinstance(v, DClass))
|
||||
self.assertIsInstance(v, DClass)
|
||||
else:
|
||||
self.fail("no exception")
|
||||
|
||||
|
|
|
@ -348,7 +348,7 @@ class TestOptionParser(BaseTest):
|
|||
|
||||
def test_get_option(self):
|
||||
opt1 = self.parser.get_option("-v")
|
||||
self.assertTrue(isinstance(opt1, Option))
|
||||
self.assertIsInstance(opt1, Option)
|
||||
self.assertEqual(opt1._short_opts, ["-v", "-n"])
|
||||
self.assertEqual(opt1._long_opts, ["--verbose", "--noisy"])
|
||||
self.assertEqual(opt1.action, "store_true")
|
||||
|
|
|
@ -33,7 +33,7 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
|
|||
code = suite.compile()
|
||||
scope = {}
|
||||
exec code in scope
|
||||
self.assertTrue(isinstance(scope["x"], unicode))
|
||||
self.assertIsInstance(scope["x"], unicode)
|
||||
|
||||
def check_suite(self, s):
|
||||
self.roundtrip(parser.suite, s)
|
||||
|
|
|
@ -133,7 +133,7 @@ class PosixTester(unittest.TestCase):
|
|||
fp = open(test_support.TESTFN)
|
||||
try:
|
||||
fd = posix.dup(fp.fileno())
|
||||
self.assertTrue(isinstance(fd, int))
|
||||
self.assertIsInstance(fd, int)
|
||||
os.close(fd)
|
||||
finally:
|
||||
fp.close()
|
||||
|
@ -273,7 +273,7 @@ class PosixTester(unittest.TestCase):
|
|||
def test_umask(self):
|
||||
if hasattr(posix, 'umask'):
|
||||
old_mask = posix.umask(0)
|
||||
self.assertTrue(isinstance(old_mask, int))
|
||||
self.assertIsInstance(old_mask, int)
|
||||
posix.umask(old_mask)
|
||||
|
||||
def test_strerror(self):
|
||||
|
|
|
@ -335,15 +335,15 @@ class PosixPathTest(unittest.TestCase):
|
|||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
self.assertTrue(isinstance(posixpath.expanduser("~/"), basestring))
|
||||
self.assertIsInstance(posixpath.expanduser("~/"), basestring)
|
||||
# if home directory == root directory, this test makes no sense
|
||||
if posixpath.expanduser("~") != '/':
|
||||
self.assertEqual(
|
||||
posixpath.expanduser("~") + "/",
|
||||
posixpath.expanduser("~/")
|
||||
)
|
||||
self.assertTrue(isinstance(posixpath.expanduser("~root/"), basestring))
|
||||
self.assertTrue(isinstance(posixpath.expanduser("~foo/"), basestring))
|
||||
self.assertIsInstance(posixpath.expanduser("~root/"), basestring)
|
||||
self.assertIsInstance(posixpath.expanduser("~foo/"), basestring)
|
||||
|
||||
with test_support.EnvironmentVarGuard() as env:
|
||||
env['HOME'] = '/'
|
||||
|
@ -383,8 +383,8 @@ class PosixPathTest(unittest.TestCase):
|
|||
|
||||
# Issue 5827: Make sure normpath preserves unicode
|
||||
for path in (u'', u'.', u'/', u'\\', u'///foo/.//bar//'):
|
||||
self.assertTrue(isinstance(posixpath.normpath(path), unicode),
|
||||
'normpath() returned str instead of unicode')
|
||||
self.assertIsInstance(posixpath.normpath(path), unicode,
|
||||
'normpath() returned str instead of unicode')
|
||||
|
||||
self.assertRaises(TypeError, posixpath.normpath)
|
||||
|
||||
|
|
|
@ -128,11 +128,11 @@ class TestPrint(unittest.TestCase):
|
|||
self.assertEqual(u''.join(buf.buf), 'hi nothing\n')
|
||||
buf = Recorder(False)
|
||||
print('hi', 'bye', end=u'\n', file=buf)
|
||||
self.assertTrue(isinstance(buf.buf[1], unicode))
|
||||
self.assertTrue(isinstance(buf.buf[3], unicode))
|
||||
self.assertIsInstance(buf.buf[1], unicode)
|
||||
self.assertIsInstance(buf.buf[3], unicode)
|
||||
del buf.buf[:]
|
||||
print(sep=u'x', file=buf)
|
||||
self.assertTrue(isinstance(buf.buf[-1], unicode))
|
||||
self.assertIsInstance(buf.buf[-1], unicode)
|
||||
|
||||
|
||||
def test_main():
|
||||
|
|
|
@ -13,19 +13,19 @@ class PwdTest(unittest.TestCase):
|
|||
for e in entries:
|
||||
self.assertEqual(len(e), 7)
|
||||
self.assertEqual(e[0], e.pw_name)
|
||||
self.assertTrue(isinstance(e.pw_name, basestring))
|
||||
self.assertIsInstance(e.pw_name, basestring)
|
||||
self.assertEqual(e[1], e.pw_passwd)
|
||||
self.assertTrue(isinstance(e.pw_passwd, basestring))
|
||||
self.assertIsInstance(e.pw_passwd, basestring)
|
||||
self.assertEqual(e[2], e.pw_uid)
|
||||
self.assertTrue(isinstance(e.pw_uid, int))
|
||||
self.assertIsInstance(e.pw_uid, int)
|
||||
self.assertEqual(e[3], e.pw_gid)
|
||||
self.assertTrue(isinstance(e.pw_gid, int))
|
||||
self.assertIsInstance(e.pw_gid, int)
|
||||
self.assertEqual(e[4], e.pw_gecos)
|
||||
self.assertTrue(isinstance(e.pw_gecos, basestring))
|
||||
self.assertIsInstance(e.pw_gecos, basestring)
|
||||
self.assertEqual(e[5], e.pw_dir)
|
||||
self.assertTrue(isinstance(e.pw_dir, basestring))
|
||||
self.assertIsInstance(e.pw_dir, basestring)
|
||||
self.assertEqual(e[6], e.pw_shell)
|
||||
self.assertTrue(isinstance(e.pw_shell, basestring))
|
||||
self.assertIsInstance(e.pw_shell, basestring)
|
||||
|
||||
# The following won't work, because of duplicate entries
|
||||
# for one uid
|
||||
|
|
|
@ -92,12 +92,12 @@ class PyclbrTest(TestCase):
|
|||
self.assertHasattr(module, name, ignore)
|
||||
py_item = getattr(module, name)
|
||||
if isinstance(value, pyclbr.Function):
|
||||
self.assertTrue(isinstance(py_item, (FunctionType, BuiltinFunctionType)))
|
||||
self.assertIsInstance(py_item, (FunctionType, BuiltinFunctionType))
|
||||
if py_item.__module__ != moduleName:
|
||||
continue # skip functions that came from somewhere else
|
||||
self.assertEquals(py_item.__module__, value.module)
|
||||
else:
|
||||
self.assertTrue(isinstance(py_item, (ClassType, type)))
|
||||
self.assertIsInstance(py_item, (ClassType, type))
|
||||
if py_item.__module__ != moduleName:
|
||||
continue # skip classes that came from somewhere else
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ class SysModuleTest(unittest.TestCase):
|
|||
if test.test_support.have_unicode:
|
||||
self.assertRaises(TypeError, sys.getdefaultencoding, 42)
|
||||
# can't check more than the type, as the user might have changed it
|
||||
self.assertTrue(isinstance(sys.getdefaultencoding(), str))
|
||||
self.assertIsInstance(sys.getdefaultencoding(), str)
|
||||
|
||||
# testing sys.settrace() is done in test_trace.py
|
||||
# testing sys.setprofile() is done in test_profile.py
|
||||
|
@ -205,13 +205,13 @@ class SysModuleTest(unittest.TestCase):
|
|||
def test_getwindowsversion(self):
|
||||
if hasattr(sys, "getwindowsversion"):
|
||||
v = sys.getwindowsversion()
|
||||
self.assertTrue(isinstance(v, tuple))
|
||||
self.assertIsInstance(v, tuple)
|
||||
self.assertEqual(len(v), 5)
|
||||
self.assertTrue(isinstance(v[0], int))
|
||||
self.assertTrue(isinstance(v[1], int))
|
||||
self.assertTrue(isinstance(v[2], int))
|
||||
self.assertTrue(isinstance(v[3], int))
|
||||
self.assertTrue(isinstance(v[4], str))
|
||||
self.assertIsInstance(v[0], int)
|
||||
self.assertIsInstance(v[1], int)
|
||||
self.assertIsInstance(v[2], int)
|
||||
self.assertIsInstance(v[3], int)
|
||||
self.assertIsInstance(v[4], str)
|
||||
|
||||
def test_dlopenflags(self):
|
||||
if hasattr(sys, "setdlopenflags"):
|
||||
|
@ -236,7 +236,7 @@ class SysModuleTest(unittest.TestCase):
|
|||
del n
|
||||
self.assertEqual(sys.getrefcount(None), c)
|
||||
if hasattr(sys, "gettotalrefcount"):
|
||||
self.assertTrue(isinstance(sys.gettotalrefcount(), int))
|
||||
self.assertIsInstance(sys.gettotalrefcount(), int)
|
||||
|
||||
def test_getframe(self):
|
||||
self.assertRaises(TypeError, sys._getframe, 42, 42)
|
||||
|
@ -332,13 +332,13 @@ class SysModuleTest(unittest.TestCase):
|
|||
self.assertTrue(d[0] is sys._getframe())
|
||||
|
||||
def test_attributes(self):
|
||||
self.assertTrue(isinstance(sys.api_version, int))
|
||||
self.assertTrue(isinstance(sys.argv, list))
|
||||
self.assertIsInstance(sys.api_version, int)
|
||||
self.assertIsInstance(sys.argv, list)
|
||||
self.assertIn(sys.byteorder, ("little", "big"))
|
||||
self.assertTrue(isinstance(sys.builtin_module_names, tuple))
|
||||
self.assertTrue(isinstance(sys.copyright, basestring))
|
||||
self.assertTrue(isinstance(sys.exec_prefix, basestring))
|
||||
self.assertTrue(isinstance(sys.executable, basestring))
|
||||
self.assertIsInstance(sys.builtin_module_names, tuple)
|
||||
self.assertIsInstance(sys.copyright, basestring)
|
||||
self.assertIsInstance(sys.exec_prefix, basestring)
|
||||
self.assertIsInstance(sys.executable, basestring)
|
||||
self.assertEqual(len(sys.float_info), 11)
|
||||
self.assertEqual(sys.float_info.radix, 2)
|
||||
self.assertEqual(len(sys.long_info), 2)
|
||||
|
@ -346,26 +346,26 @@ class SysModuleTest(unittest.TestCase):
|
|||
self.assertTrue(sys.long_info.sizeof_digit >= 1)
|
||||
self.assertEqual(type(sys.long_info.bits_per_digit), int)
|
||||
self.assertEqual(type(sys.long_info.sizeof_digit), int)
|
||||
self.assertTrue(isinstance(sys.hexversion, int))
|
||||
self.assertTrue(isinstance(sys.maxint, int))
|
||||
self.assertIsInstance(sys.hexversion, int)
|
||||
self.assertIsInstance(sys.maxint, int)
|
||||
if test.test_support.have_unicode:
|
||||
self.assertTrue(isinstance(sys.maxunicode, int))
|
||||
self.assertTrue(isinstance(sys.platform, basestring))
|
||||
self.assertTrue(isinstance(sys.prefix, basestring))
|
||||
self.assertTrue(isinstance(sys.version, basestring))
|
||||
self.assertIsInstance(sys.maxunicode, int)
|
||||
self.assertIsInstance(sys.platform, basestring)
|
||||
self.assertIsInstance(sys.prefix, basestring)
|
||||
self.assertIsInstance(sys.version, basestring)
|
||||
vi = sys.version_info
|
||||
self.assertTrue(isinstance(vi[:], tuple))
|
||||
self.assertIsInstance(vi[:], tuple)
|
||||
self.assertEqual(len(vi), 5)
|
||||
self.assertTrue(isinstance(vi[0], int))
|
||||
self.assertTrue(isinstance(vi[1], int))
|
||||
self.assertTrue(isinstance(vi[2], int))
|
||||
self.assertIsInstance(vi[0], int)
|
||||
self.assertIsInstance(vi[1], int)
|
||||
self.assertIsInstance(vi[2], int)
|
||||
self.assertIn(vi[3], ("alpha", "beta", "candidate", "final"))
|
||||
self.assertTrue(isinstance(vi[4], int))
|
||||
self.assertTrue(isinstance(vi.major, int))
|
||||
self.assertTrue(isinstance(vi.minor, int))
|
||||
self.assertTrue(isinstance(vi.micro, int))
|
||||
self.assertIsInstance(vi[4], int)
|
||||
self.assertIsInstance(vi.major, int)
|
||||
self.assertIsInstance(vi.minor, int)
|
||||
self.assertIsInstance(vi.micro, int)
|
||||
self.assertIn(vi.releaselevel, ("alpha", "beta", "candidate", "final"))
|
||||
self.assertTrue(isinstance(vi.serial, int))
|
||||
self.assertIsInstance(vi.serial, int)
|
||||
self.assertEqual(vi[0], vi.major)
|
||||
self.assertEqual(vi[1], vi.minor)
|
||||
self.assertEqual(vi[2], vi.micro)
|
||||
|
|
|
@ -105,7 +105,7 @@ class TestSysConfig(unittest.TestCase):
|
|||
|
||||
def test_get_config_vars(self):
|
||||
cvars = get_config_vars()
|
||||
self.assertTrue(isinstance(cvars, dict))
|
||||
self.assertIsInstance(cvars, dict)
|
||||
self.assertTrue(cvars)
|
||||
|
||||
def test_get_platform(self):
|
||||
|
|
|
@ -142,8 +142,7 @@ class test__candidate_tempdir_list(TC):
|
|||
|
||||
self.assertFalse(len(cand) == 0)
|
||||
for c in cand:
|
||||
self.assertTrue(isinstance(c, basestring),
|
||||
"%s is not a string" % c)
|
||||
self.assertIsInstance(c, basestring)
|
||||
|
||||
def test_wanted_dirs(self):
|
||||
# _candidate_tempdir_list contains the expected directories
|
||||
|
@ -184,7 +183,7 @@ class test__get_candidate_names(TC):
|
|||
def test_retval(self):
|
||||
# _get_candidate_names returns a _RandomNameSequence object
|
||||
obj = tempfile._get_candidate_names()
|
||||
self.assertTrue(isinstance(obj, tempfile._RandomNameSequence))
|
||||
self.assertIsInstance(obj, tempfile._RandomNameSequence)
|
||||
|
||||
def test_same_thing(self):
|
||||
# _get_candidate_names always returns the same object
|
||||
|
@ -322,7 +321,7 @@ class test_gettempprefix(TC):
|
|||
# gettempprefix returns a nonempty prefix string
|
||||
p = tempfile.gettempprefix()
|
||||
|
||||
self.assertTrue(isinstance(p, basestring))
|
||||
self.assertIsInstance(p, basestring)
|
||||
self.assertTrue(len(p) > 0)
|
||||
|
||||
def test_usable_template(self):
|
||||
|
|
|
@ -349,9 +349,10 @@ What a mess!
|
|||
self.check_wrap(text, 50, [u"Hello there, how are you today?"])
|
||||
self.check_wrap(text, 20, [u"Hello there, how are", "you today?"])
|
||||
olines = self.wrapper.wrap(text)
|
||||
assert isinstance(olines, list) and isinstance(olines[0], unicode)
|
||||
self.assertIsInstance(olines, list)
|
||||
self.assertIsInstance(olines[0], unicode)
|
||||
otext = self.wrapper.fill(text)
|
||||
assert isinstance(otext, unicode)
|
||||
self.assertIsInstance(otext, unicode)
|
||||
|
||||
def test_no_split_at_umlaut(self):
|
||||
text = u"Die Empf\xe4nger-Auswahl"
|
||||
|
|
|
@ -154,8 +154,7 @@ class ThreadTests(BaseTestCase):
|
|||
# Wait for the thread to finish.
|
||||
mutex.acquire()
|
||||
self.assertIn(tid, threading._active)
|
||||
self.assertTrue(isinstance(threading._active[tid],
|
||||
threading._DummyThread))
|
||||
self.assertIsInstance(threading._active[tid], threading._DummyThread)
|
||||
del threading._active[tid]
|
||||
|
||||
# PyThreadState_SetAsyncExc() is a CPython-only gimmick, not (currently)
|
||||
|
|
|
@ -14,11 +14,11 @@ class Tests(unittest.TestCase):
|
|||
|
||||
for s in snippets:
|
||||
a = transformer.parse(s)
|
||||
assert isinstance(a, ast.Module)
|
||||
self.assertIsInstance(a, ast.Module)
|
||||
child1 = a.getChildNodes()[0]
|
||||
assert isinstance(child1, ast.Stmt)
|
||||
self.assertIsInstance(child1, ast.Stmt)
|
||||
child2 = child1.getChildNodes()[0]
|
||||
assert isinstance(child2, ast.Assign)
|
||||
self.assertIsInstance(child2, ast.Assign)
|
||||
|
||||
# This actually tests the compiler, but it's a way to assure the ast
|
||||
# is correct
|
||||
|
|
|
@ -79,8 +79,8 @@ class TypeChecksTest(unittest.TestCase):
|
|||
def __subclasscheck__(self, cls):
|
||||
return True
|
||||
class Sub(X): pass
|
||||
self.assertFalse(isinstance(3, X))
|
||||
self.assertTrue(isinstance(X(), X))
|
||||
self.assertNotIsInstance(3, X)
|
||||
self.assertIsInstance(X(), X)
|
||||
self.assertFalse(issubclass(int, X))
|
||||
self.assertTrue(issubclass(Sub, X))
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ class Test_TestLoader(TestCase):
|
|||
self.assertFalse('runTest'.startswith(loader.testMethodPrefix))
|
||||
|
||||
suite = loader.loadTestsFromTestCase(Foo)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
self.assertEqual(list(suite), [Foo('runTest')])
|
||||
|
||||
################################################################
|
||||
|
@ -205,7 +205,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromModule(m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
|
||||
expected = [loader.suiteClass([MyTestCase('test')])]
|
||||
self.assertEqual(list(suite), expected)
|
||||
|
@ -218,7 +218,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromModule(m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
self.assertEqual(list(suite), [])
|
||||
|
||||
# "This method searches `module` for classes derived from TestCase"
|
||||
|
@ -232,7 +232,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromModule(m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
|
||||
self.assertEqual(list(suite), [loader.suiteClass()])
|
||||
|
||||
|
@ -468,7 +468,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromName('testcase_1', m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
self.assertEqual(list(suite), [MyTestCase('test')])
|
||||
|
||||
# "The specifier name is a ``dotted name'' that may resolve either to
|
||||
|
@ -484,7 +484,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromName('testsuite', m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
|
||||
self.assertEqual(list(suite), [MyTestCase('test')])
|
||||
|
||||
|
@ -499,7 +499,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromName('testcase_1.test', m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
|
||||
self.assertEqual(list(suite), [MyTestCase('test')])
|
||||
|
||||
|
@ -538,7 +538,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromName('return_TestSuite', m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
self.assertEqual(list(suite), [testcase_1, testcase_2])
|
||||
|
||||
# "The specifier name is a ``dotted name'' that may resolve ... to
|
||||
|
@ -552,7 +552,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromName('return_TestCase', m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
self.assertEqual(list(suite), [testcase_1])
|
||||
|
||||
# "The specifier name is a ``dotted name'' that may resolve ... to
|
||||
|
@ -572,7 +572,7 @@ class Test_TestLoader(TestCase):
|
|||
loader = unittest.TestLoader()
|
||||
loader.suiteClass = SubTestSuite
|
||||
suite = loader.loadTestsFromName('return_TestCase', m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
self.assertEqual(list(suite), [testcase_1])
|
||||
|
||||
# "The specifier name is a ``dotted name'' that may resolve ... to
|
||||
|
@ -592,7 +592,7 @@ class Test_TestLoader(TestCase):
|
|||
loader = unittest.TestLoader()
|
||||
loader.suiteClass=SubTestSuite
|
||||
suite = loader.loadTestsFromName('testcase_1.test', m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
|
||||
self.assertEqual(list(suite), [MyTestCase('test')])
|
||||
|
||||
|
@ -632,7 +632,7 @@ class Test_TestLoader(TestCase):
|
|||
try:
|
||||
suite = loader.loadTestsFromName(module_name)
|
||||
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
self.assertEqual(list(suite), [])
|
||||
|
||||
# audioop should now be loaded, thanks to loadTestsFromName()
|
||||
|
@ -655,7 +655,7 @@ class Test_TestLoader(TestCase):
|
|||
loader = unittest.TestLoader()
|
||||
|
||||
suite = loader.loadTestsFromNames([])
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
self.assertEqual(list(suite), [])
|
||||
|
||||
# "Similar to loadTestsFromName(), but takes a sequence of names rather
|
||||
|
@ -670,7 +670,7 @@ class Test_TestLoader(TestCase):
|
|||
loader = unittest.TestLoader()
|
||||
|
||||
suite = loader.loadTestsFromNames([], unittest)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
self.assertEqual(list(suite), [])
|
||||
|
||||
# "The specifier name is a ``dotted name'' that may resolve either to
|
||||
|
@ -871,7 +871,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromNames(['testcase_1'], m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
|
||||
expected = loader.suiteClass([MyTestCase('test')])
|
||||
self.assertEqual(list(suite), [expected])
|
||||
|
@ -887,7 +887,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromNames(['testsuite'], m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
|
||||
self.assertEqual(list(suite), [m.testsuite])
|
||||
|
||||
|
@ -902,7 +902,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromNames(['testcase_1.test'], m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
|
||||
ref_suite = unittest.TestSuite([MyTestCase('test')])
|
||||
self.assertEqual(list(suite), [ref_suite])
|
||||
|
@ -939,7 +939,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromNames(['return_TestSuite'], m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
|
||||
expected = unittest.TestSuite([testcase_1, testcase_2])
|
||||
self.assertEqual(list(suite), [expected])
|
||||
|
@ -955,7 +955,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromNames(['return_TestCase'], m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
|
||||
ref_suite = unittest.TestSuite([testcase_1])
|
||||
self.assertEqual(list(suite), [ref_suite])
|
||||
|
@ -979,7 +979,7 @@ class Test_TestLoader(TestCase):
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromNames(['Foo.foo'], m)
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
|
||||
ref_suite = unittest.TestSuite([testcase_1])
|
||||
self.assertEqual(list(suite), [ref_suite])
|
||||
|
@ -1020,7 +1020,7 @@ class Test_TestLoader(TestCase):
|
|||
try:
|
||||
suite = loader.loadTestsFromNames([module_name])
|
||||
|
||||
self.assertTrue(isinstance(suite, loader.suiteClass))
|
||||
self.assertIsInstance(suite, loader.suiteClass)
|
||||
self.assertEqual(list(suite), [unittest.TestSuite()])
|
||||
|
||||
# audioop should now be loaded, thanks to loadTestsFromName()
|
||||
|
@ -1798,7 +1798,7 @@ class Test_FunctionTestCase(TestCase):
|
|||
def test_id(self):
|
||||
test = unittest.FunctionTestCase(lambda: None)
|
||||
|
||||
self.assertTrue(isinstance(test.id(), basestring))
|
||||
self.assertIsInstance(test.id(), basestring)
|
||||
|
||||
# "Returns a one-line description of the test, or None if no description
|
||||
# has been provided. The default implementation of this method returns
|
||||
|
@ -1986,7 +1986,7 @@ class Test_TestResult(TestCase):
|
|||
|
||||
test_case, formatted_exc = result.failures[0]
|
||||
self.assertTrue(test_case is test)
|
||||
self.assertTrue(isinstance(formatted_exc, str))
|
||||
self.assertIsInstance(formatted_exc, str)
|
||||
|
||||
# "addError(test, err)"
|
||||
# ...
|
||||
|
@ -2036,7 +2036,7 @@ class Test_TestResult(TestCase):
|
|||
|
||||
test_case, formatted_exc = result.errors[0]
|
||||
self.assertTrue(test_case is test)
|
||||
self.assertTrue(isinstance(formatted_exc, str))
|
||||
self.assertIsInstance(formatted_exc, str)
|
||||
|
||||
### Support code for Test_TestCase
|
||||
################################################################
|
||||
|
@ -2427,7 +2427,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
|
|||
def runTest(self):
|
||||
pass
|
||||
|
||||
self.assertTrue(isinstance(Foo().id(), basestring))
|
||||
self.assertIsInstance(Foo().id(), basestring)
|
||||
|
||||
# "If result is omitted or None, a temporary result object is created
|
||||
# and used, but is not made available to the caller. As TestCase owns the
|
||||
|
@ -2887,7 +2887,7 @@ test case
|
|||
with ctx:
|
||||
Stub(v)
|
||||
e = ctx.exc_value
|
||||
self.assertTrue(isinstance(e, ExceptionMock))
|
||||
self.assertIsInstance(e, ExceptionMock)
|
||||
self.assertEqual(e.args[0], v)
|
||||
|
||||
def testSynonymAssertMethodNames(self):
|
||||
|
|
|
@ -66,8 +66,7 @@ class urlopen_FileTests(unittest.TestCase):
|
|||
|
||||
def test_fileno(self):
|
||||
file_num = self.returned_obj.fileno()
|
||||
self.assertTrue(isinstance(file_num, int),
|
||||
"fileno() did not return an int")
|
||||
self.assertIsInstance(file_num, int, "fileno() did not return an int")
|
||||
self.assertEqual(os.read(file_num, len(self.text)), self.text,
|
||||
"Reading on the file descriptor returned by fileno() "
|
||||
"did not return the expected text")
|
||||
|
@ -78,7 +77,7 @@ class urlopen_FileTests(unittest.TestCase):
|
|||
self.returned_obj.close()
|
||||
|
||||
def test_info(self):
|
||||
self.assertTrue(isinstance(self.returned_obj.info(), mimetools.Message))
|
||||
self.assertIsInstance(self.returned_obj.info(), mimetools.Message)
|
||||
|
||||
def test_geturl(self):
|
||||
self.assertEqual(self.returned_obj.geturl(), self.pathname)
|
||||
|
@ -229,9 +228,9 @@ class urlretrieve_FileTests(unittest.TestCase):
|
|||
# a headers value is returned.
|
||||
result = urllib.urlretrieve("file:%s" % test_support.TESTFN)
|
||||
self.assertEqual(result[0], test_support.TESTFN)
|
||||
self.assertTrue(isinstance(result[1], mimetools.Message),
|
||||
"did not get a mimetools.Message instance as second "
|
||||
"returned value")
|
||||
self.assertIsInstance(result[1], mimetools.Message,
|
||||
"did not get a mimetools.Message instance as "
|
||||
"second returned value")
|
||||
|
||||
def test_copy(self):
|
||||
# Test that setting the filename argument works.
|
||||
|
@ -254,9 +253,9 @@ class urlretrieve_FileTests(unittest.TestCase):
|
|||
def test_reporthook(self):
|
||||
# Make sure that the reporthook works.
|
||||
def hooktester(count, block_size, total_size, count_holder=[0]):
|
||||
self.assertTrue(isinstance(count, int))
|
||||
self.assertTrue(isinstance(block_size, int))
|
||||
self.assertTrue(isinstance(total_size, int))
|
||||
self.assertIsInstance(count, int)
|
||||
self.assertIsInstance(block_size, int)
|
||||
self.assertIsInstance(total_size, int)
|
||||
self.assertEqual(count, count_holder[0])
|
||||
count_holder[0] = count_holder[0] + 1
|
||||
second_temp = "%s.2" % test_support.TESTFN
|
||||
|
|
|
@ -580,12 +580,12 @@ class OpenerDirectorTests(unittest.TestCase):
|
|||
# *_request
|
||||
self.assertEqual((handler, name), calls[i])
|
||||
self.assertEqual(len(args), 1)
|
||||
self.assertTrue(isinstance(args[0], Request))
|
||||
self.assertIsInstance(args[0], Request)
|
||||
else:
|
||||
# *_response
|
||||
self.assertEqual((handler, name), calls[i])
|
||||
self.assertEqual(len(args), 2)
|
||||
self.assertTrue(isinstance(args[0], Request))
|
||||
self.assertIsInstance(args[0], Request)
|
||||
# response from opener.open is None, because there's no
|
||||
# handler that defines http_open to handle it
|
||||
self.assertTrue(args[1] is None or
|
||||
|
|
|
@ -457,9 +457,9 @@ class TestUrlopen(BaseTestCase):
|
|||
try:
|
||||
open_url = urllib2.urlopen("http://localhost:%s" % handler.port)
|
||||
info_obj = open_url.info()
|
||||
self.assertTrue(isinstance(info_obj, mimetools.Message),
|
||||
"object returned by 'info' is not an instance of "
|
||||
"mimetools.Message")
|
||||
self.assertIsInstance(info_obj, mimetools.Message,
|
||||
"object returned by 'info' is not an "
|
||||
"instance of mimetools.Message")
|
||||
self.assertEqual(info_obj.getsubtype(), "plain")
|
||||
finally:
|
||||
self.server.stop()
|
||||
|
|
|
@ -176,7 +176,7 @@ class OtherNetworkTests(unittest.TestCase):
|
|||
if expected_err:
|
||||
msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" %
|
||||
(expected_err, url, req, type(err), err))
|
||||
self.assertTrue(isinstance(err, expected_err), msg)
|
||||
self.assertIsInstance(err, expected_err, msg)
|
||||
else:
|
||||
with test_support.transient_internet():
|
||||
buf = f.read()
|
||||
|
|
|
@ -71,10 +71,10 @@ class urlopenNetworkTests(unittest.TestCase):
|
|||
# Test both readline and readlines.
|
||||
open_url = self.urlopen("http://www.python.org/")
|
||||
try:
|
||||
self.assertTrue(isinstance(open_url.readline(), basestring),
|
||||
"readline did not return a string")
|
||||
self.assertTrue(isinstance(open_url.readlines(), list),
|
||||
"readlines did not return a list")
|
||||
self.assertIsInstance(open_url.readline(), basestring,
|
||||
"readline did not return a string")
|
||||
self.assertIsInstance(open_url.readlines(), list,
|
||||
"readlines did not return a list")
|
||||
finally:
|
||||
open_url.close()
|
||||
|
||||
|
@ -85,9 +85,9 @@ class urlopenNetworkTests(unittest.TestCase):
|
|||
info_obj = open_url.info()
|
||||
finally:
|
||||
open_url.close()
|
||||
self.assertTrue(isinstance(info_obj, mimetools.Message),
|
||||
"object returned by 'info' is not an instance of "
|
||||
"mimetools.Message")
|
||||
self.assertIsInstance(info_obj, mimetools.Message,
|
||||
"object returned by 'info' is not an "
|
||||
"instance of mimetools.Message")
|
||||
self.assertEqual(info_obj.getsubtype(), "html")
|
||||
|
||||
def test_geturl(self):
|
||||
|
@ -175,8 +175,8 @@ class urlretrieveNetworkTests(unittest.TestCase):
|
|||
# Make sure header returned as 2nd value from urlretrieve is good.
|
||||
file_location, header = self.urlretrieve("http://www.python.org/")
|
||||
os.unlink(file_location)
|
||||
self.assertTrue(isinstance(header, mimetools.Message),
|
||||
"header is not an instance of mimetools.Message")
|
||||
self.assertIsInstance(header, mimetools.Message,
|
||||
"header is not an instance of mimetools.Message")
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -39,8 +39,8 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol):
|
|||
self.assertEqual(UserDict.UserDict.fromkeys('one two'.split(), 1), d5)
|
||||
self.assertEqual(UserDict.UserDict().fromkeys('one two'.split(), 1), d5)
|
||||
self.assertTrue(u1.fromkeys('one two'.split()) is not u1)
|
||||
self.assertTrue(isinstance(u1.fromkeys('one two'.split()), UserDict.UserDict))
|
||||
self.assertTrue(isinstance(u2.fromkeys('one two'.split()), UserDict.IterableUserDict))
|
||||
self.assertIsInstance(u1.fromkeys('one two'.split()), UserDict.UserDict)
|
||||
self.assertIsInstance(u2.fromkeys('one two'.split()), UserDict.IterableUserDict)
|
||||
|
||||
# Test __repr__
|
||||
self.assertEqual(str(u0), str(d0))
|
||||
|
|
|
@ -114,7 +114,7 @@ class MutableStringTest(UserStringTest):
|
|||
s = self.type2test("foobar")
|
||||
s2 = s.immutable()
|
||||
self.assertEqual(s, s2)
|
||||
self.assertTrue(isinstance(s2, UserString))
|
||||
self.assertIsInstance(s2, UserString)
|
||||
|
||||
def test_iadd(self):
|
||||
s = self.type2test("foo")
|
||||
|
|
|
@ -179,10 +179,10 @@ class UtilityTests(TestCase):
|
|||
# Check defaulting when empty
|
||||
env = {}
|
||||
util.setup_testing_defaults(env)
|
||||
if isinstance(value,StringIO):
|
||||
self.assertTrue(isinstance(env[key],StringIO))
|
||||
if isinstance(value, StringIO):
|
||||
self.assertIsInstance(env[key], StringIO)
|
||||
else:
|
||||
self.assertEqual(env[key],value)
|
||||
self.assertEqual(env[key], value)
|
||||
|
||||
# Check existing value
|
||||
env = {key:alt}
|
||||
|
|
|
@ -81,11 +81,11 @@ class XMLRPCTestCase(unittest.TestCase):
|
|||
d = xmlrpclib.DateTime()
|
||||
((new_d,), dummy) = xmlrpclib.loads(xmlrpclib.dumps((d,),
|
||||
methodresponse=True))
|
||||
self.assertTrue(isinstance(new_d.value, str))
|
||||
self.assertIsInstance(new_d.value, str)
|
||||
|
||||
# Check that the output of dumps() is still an 8-bit string
|
||||
s = xmlrpclib.dumps((new_d,), methodresponse=True)
|
||||
self.assertTrue(isinstance(s, str))
|
||||
self.assertIsInstance(s, str)
|
||||
|
||||
def test_newstyle_class(self):
|
||||
class T(object):
|
||||
|
@ -175,10 +175,10 @@ class XMLRPCTestCase(unittest.TestCase):
|
|||
items = d.items()
|
||||
if have_unicode:
|
||||
self.assertEquals(s, u"abc \x95")
|
||||
self.assertTrue(isinstance(s, unicode))
|
||||
self.assertIsInstance(s, unicode)
|
||||
self.assertEquals(items, [(u"def \x96", u"ghi \x97")])
|
||||
self.assertTrue(isinstance(items[0][0], unicode))
|
||||
self.assertTrue(isinstance(items[0][1], unicode))
|
||||
self.assertIsInstance(items[0][0], unicode)
|
||||
self.assertIsInstance(items[0][1], unicode)
|
||||
else:
|
||||
self.assertEquals(s, "abc \xc2\x95")
|
||||
self.assertEquals(items, [("def \xc2\x96", "ghi \xc2\x97")])
|
||||
|
|
|
@ -593,7 +593,7 @@ class OtherTests(unittest.TestCase):
|
|||
with zipfile.ZipFile(TESTFN, "w") as zf:
|
||||
zf.writestr(u"foo.txt", "Test for unicode filename")
|
||||
zf.writestr(u"\xf6.txt", "Test for unicode filename")
|
||||
self.assertTrue(isinstance(zf.infolist()[0].filename, unicode))
|
||||
self.assertIsInstance(zf.infolist()[0].filename, unicode)
|
||||
|
||||
with zipfile.ZipFile(TESTFN, "r") as zf:
|
||||
self.assertEqual(zf.filelist[0].filename, "foo.txt")
|
||||
|
|
Loading…
Reference in New Issue