Merged revisions 77727 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r77727 | ezio.melotti | 2010-01-24 18:58:36 +0200 (Sun, 24 Jan 2010) | 1 line use assert[Not]IsInstance where appropriate ........
This commit is contained in:
parent
f41d29a8eb
commit
e96159335f
|
@ -435,15 +435,13 @@ class TestMappingProtocol(BasicTestMappingProtocol):
|
|||
self.assertEqual(dictlike().fromkeys('a'), {'a':None})
|
||||
self.assertTrue(dictlike.fromkeys('a').__class__ is dictlike)
|
||||
self.assertTrue(dictlike().fromkeys('a').__class__ is dictlike)
|
||||
# FIXME: the following won't work with UserDict, because it's an old style class
|
||||
# self.assertTrue(type(dictlike.fromkeys('a')) is dictlike)
|
||||
self.assertTrue(type(dictlike.fromkeys('a')) is dictlike)
|
||||
class mydict(self.type2test):
|
||||
def __new__(cls):
|
||||
return collections.UserDict()
|
||||
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, collections.UserDict))
|
||||
self.assertIsInstance(ud, collections.UserDict)
|
||||
self.assertRaises(TypeError, dict.fromkeys)
|
||||
|
||||
class Exc(Exception): pass
|
||||
|
@ -473,7 +471,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):
|
||||
|
@ -571,7 +569,7 @@ class TestHashMappingProtocol(TestMappingProtocol):
|
|||
return collections.UserDict()
|
||||
ud = mydict.fromkeys('ab')
|
||||
self.assertEqual(ud, {'a':None, 'b':None})
|
||||
self.assertTrue(isinstance(ud, collections.UserDict))
|
||||
self.assertIsInstance(ud, collections.UserDict)
|
||||
|
||||
def test_pop(self):
|
||||
TestMappingProtocol.test_pop(self)
|
||||
|
|
|
@ -832,7 +832,7 @@ class AbstractPickleTests(unittest.TestCase):
|
|||
x = dict.fromkeys(range(n))
|
||||
for proto in protocols:
|
||||
s = self.dumps(x, proto)
|
||||
assert isinstance(s, bytes_types)
|
||||
self.assertIsInstance(s, bytes_types)
|
||||
y = self.loads(s)
|
||||
self.assertEqual(x, y)
|
||||
num_setitems = count_opcode(pickle.SETITEMS, s)
|
||||
|
|
|
@ -76,20 +76,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(metaclass=abc.ABCMeta):
|
||||
|
@ -107,16 +107,16 @@ class TestABC(unittest.TestCase):
|
|||
class A(metaclass=abc.ABCMeta):
|
||||
pass
|
||||
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(str)
|
||||
class C(str): pass
|
||||
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)
|
||||
self.assertEqual(issubclass(C, A), True)
|
||||
|
@ -175,8 +175,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(metaclass=abc.ABCMeta):
|
||||
|
|
|
@ -201,10 +201,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))
|
||||
self.assertTrue(isinstance(bi[1], int))
|
||||
self.assertIsInstance(bi[0], int)
|
||||
self.assertIsInstance(bi[1], int)
|
||||
self.assertEqual(bi[1], len(a))
|
||||
|
||||
def test_byteswap(self):
|
||||
|
|
|
@ -88,7 +88,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)
|
||||
|
||||
|
@ -103,7 +103,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)
|
||||
|
||||
|
|
|
@ -221,15 +221,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):
|
||||
|
|
|
@ -1017,7 +1017,7 @@ class SubclassTest(unittest.TestCase):
|
|||
|
||||
def test_basic(self):
|
||||
self.assertTrue(issubclass(self.subclass2test, self.type2test))
|
||||
self.assertTrue(isinstance(self.subclass2test(), self.type2test))
|
||||
self.assertIsInstance(self.subclass2test(), self.type2test)
|
||||
|
||||
a, b = b"abcd", b"efgh"
|
||||
_a, _b = self.subclass2test(a), self.subclass2test(b)
|
||||
|
|
|
@ -29,7 +29,7 @@ class MixInCheckStateHandling:
|
|||
d = codecs.getincrementaldecoder(encoding)()
|
||||
part1 = d.decode(s[:i])
|
||||
state = d.getstate()
|
||||
self.assertTrue(isinstance(state[1], int))
|
||||
self.assertIsInstance(state[1], int)
|
||||
# Check that the condition stated in the documentation for
|
||||
# IncrementalDecoder.getstate() holds
|
||||
if not state[1]:
|
||||
|
|
|
@ -103,7 +103,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
|
||||
|
@ -236,7 +236,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
# Check some non-hashables
|
||||
non_samples = [bytearray(), 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,
|
||||
|
@ -246,7 +246,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
int, list, object, type, bytes()
|
||||
]
|
||||
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
|
||||
|
@ -261,7 +261,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 = [bytes(), str(),
|
||||
|
@ -271,7 +271,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):
|
||||
|
@ -284,7 +284,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
def test_Iterator(self):
|
||||
non_samples = [None, 42, 3.14, 1j, b"", "", (), [], {}, 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(bytes()), iter(str()),
|
||||
iter(tuple()), iter(list()), iter(dict()),
|
||||
|
@ -295,7 +295,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__')
|
||||
|
||||
|
@ -305,14 +305,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 = [bytes(), 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__')
|
||||
|
||||
|
@ -322,14 +322,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 = [bytes(), 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__')
|
||||
|
||||
|
@ -340,7 +340,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,
|
||||
|
@ -348,7 +348,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,23 +457,23 @@ 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, bytes, str]:
|
||||
self.assertTrue(isinstance(sample(), Sequence))
|
||||
self.assertIsInstance(sample(), Sequence)
|
||||
self.assertTrue(issubclass(sample, Sequence))
|
||||
self.assertTrue(isinstance(range(10), Sequence))
|
||||
self.assertIsInstance(range(10), Sequence)
|
||||
self.assertTrue(issubclass(range, Sequence))
|
||||
self.assertTrue(issubclass(str, Sequence))
|
||||
self.validate_abstract_methods(Sequence, '__contains__', '__iter__', '__len__',
|
||||
|
@ -481,20 +481,20 @@ class TestCollectionABCs(ABCTestCase):
|
|||
|
||||
def test_ByteString(self):
|
||||
for sample in [bytes, bytearray]:
|
||||
self.assertTrue(isinstance(sample(), ByteString))
|
||||
self.assertIsInstance(sample(), ByteString)
|
||||
self.assertTrue(issubclass(sample, ByteString))
|
||||
for sample in [str, list, tuple]:
|
||||
self.assertFalse(isinstance(sample(), ByteString))
|
||||
self.assertNotIsInstance(sample(), ByteString)
|
||||
self.assertFalse(issubclass(sample, ByteString))
|
||||
self.assertFalse(isinstance(memoryview(b""), ByteString))
|
||||
self.assertNotIsInstance(memoryview(b""), ByteString)
|
||||
self.assertFalse(issubclass(memoryview, ByteString))
|
||||
|
||||
def test_MutableSequence(self):
|
||||
for sample in [tuple, str, bytes]:
|
||||
self.assertFalse(isinstance(sample(), MutableSequence))
|
||||
self.assertNotIsInstance(sample(), MutableSequence)
|
||||
self.assertFalse(issubclass(sample, MutableSequence))
|
||||
for sample in [list, bytearray]:
|
||||
self.assertTrue(isinstance(sample(), MutableSequence))
|
||||
self.assertIsInstance(sample(), MutableSequence)
|
||||
self.assertTrue(issubclass(sample, MutableSequence))
|
||||
self.assertFalse(issubclass(str, MutableSequence))
|
||||
self.validate_abstract_methods(MutableSequence, '__contains__', '__iter__',
|
||||
|
@ -506,8 +506,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)
|
||||
|
|
|
@ -192,8 +192,8 @@ if 1:
|
|||
self.fail("How many bits *does* this machine have???")
|
||||
# Verify treatment of contant folding on -(sys.maxsize+1)
|
||||
# i.e. -2147483648 on 32 bit platforms. Should return int, not long.
|
||||
self.assertTrue(isinstance(eval("%s" % (-sys.maxsize - 1)), int))
|
||||
self.assertTrue(isinstance(eval("%s" % (-sys.maxsize - 2)), int))
|
||||
self.assertIsInstance(eval("%s" % (-sys.maxsize - 1)), int)
|
||||
self.assertIsInstance(eval("%s" % (-sys.maxsize - 2)), int)
|
||||
|
||||
if sys.maxsize == 9223372036854775807:
|
||||
def test_32_63_bit_values(self):
|
||||
|
@ -208,7 +208,7 @@ if 1:
|
|||
|
||||
for variable in self.test_32_63_bit_values.__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
|
||||
|
|
|
@ -79,7 +79,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)
|
||||
|
@ -88,7 +88,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")
|
||||
|
@ -109,14 +109,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')
|
||||
|
@ -382,9 +382,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))
|
||||
|
@ -895,9 +895,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):
|
||||
|
@ -1881,9 +1881,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):
|
||||
|
@ -2251,7 +2251,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')
|
||||
|
||||
|
@ -2478,8 +2478,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')
|
||||
|
||||
|
|
|
@ -515,7 +515,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'))
|
||||
|
||||
|
@ -1579,8 +1579,8 @@ 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.assertTrue(not isinstance(Decimal(0), numbers.Real))
|
||||
self.assertIsInstance(Decimal(0), numbers.Number)
|
||||
self.assertNotIsInstance(Decimal(0), numbers.Real)
|
||||
|
||||
def test_pickle(self):
|
||||
d = Decimal('-3.141590000')
|
||||
|
|
|
@ -384,11 +384,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):
|
||||
|
@ -401,7 +401,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
|
||||
|
@ -1095,7 +1095,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)
|
||||
|
@ -1781,7 +1781,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)
|
||||
|
@ -3407,10 +3407,10 @@ order (MRO) for bases """
|
|||
d = D(None)
|
||||
self.assertEqual(d.foo, None)
|
||||
d = C(1)
|
||||
self.assertEqual(isinstance(d, D), True)
|
||||
self.assertIsInstance(d, D)
|
||||
self.assertEqual(d.foo, 1)
|
||||
d = D(1)
|
||||
self.assertEqual(isinstance(d, D), True)
|
||||
self.assertIsInstance(d, D)
|
||||
self.assertEqual(d.foo, 1)
|
||||
|
||||
def test_imul_bug(self):
|
||||
|
@ -3902,29 +3902,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...
|
||||
|
|
|
@ -216,7 +216,7 @@ class DictTest(unittest.TestCase):
|
|||
return collections.UserDict()
|
||||
ud = mydict.fromkeys('ab')
|
||||
self.assertEqual(ud, {'a':None, 'b':None})
|
||||
self.assertTrue(isinstance(ud, collections.UserDict))
|
||||
self.assertIsInstance(ud, collections.UserDict)
|
||||
self.assertRaises(TypeError, dict.fromkeys)
|
||||
|
||||
class Exc(Exception): pass
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -319,18 +319,18 @@ class ExceptionTests(unittest.TestCase):
|
|||
tb = sys.exc_info()[2]
|
||||
|
||||
e = BaseException().with_traceback(tb)
|
||||
self.assertTrue(isinstance(e, BaseException))
|
||||
self.assertIsInstance(e, BaseException)
|
||||
self.assertEqual(e.__traceback__, tb)
|
||||
|
||||
e = IndexError(5).with_traceback(tb)
|
||||
self.assertTrue(isinstance(e, IndexError))
|
||||
self.assertIsInstance(e, IndexError)
|
||||
self.assertEqual(e.__traceback__, tb)
|
||||
|
||||
class MyException(Exception):
|
||||
pass
|
||||
|
||||
e = MyException().with_traceback(tb)
|
||||
self.assertTrue(isinstance(e, MyException))
|
||||
self.assertIsInstance(e, MyException)
|
||||
self.assertEqual(e.__traceback__, tb)
|
||||
|
||||
def testInvalidTraceback(self):
|
||||
|
|
|
@ -592,36 +592,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()
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ class FunctionPropertiesTest(FuncAttrsTest):
|
|||
a = 12
|
||||
def f(): print(a)
|
||||
c = f.__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 = ''", {}, scope)
|
||||
self.assertTrue(isinstance(scope["x"], str))
|
||||
self.assertIsInstance(scope["x"], str)
|
||||
|
||||
|
||||
def test_main():
|
||||
|
|
|
@ -9,7 +9,7 @@ from . import support
|
|||
class TestMultipleFeatures(unittest.TestCase):
|
||||
|
||||
def test_unicode_literals(self):
|
||||
self.assertTrue(isinstance("", str))
|
||||
self.assertIsInstance("", str)
|
||||
|
||||
def test_print_function(self):
|
||||
with 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, str))
|
||||
self.assertIsInstance(value.gr_name, str)
|
||||
self.assertEqual(value[1], value.gr_passwd)
|
||||
self.assertTrue(isinstance(value.gr_passwd, str))
|
||||
self.assertIsInstance(value.gr_passwd, str)
|
||||
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()
|
||||
|
|
|
@ -91,11 +91,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
|
||||
|
|
|
@ -53,15 +53,15 @@ class IntTestCases(unittest.TestCase):
|
|||
s = repr(-1-sys.maxsize)
|
||||
x = int(s)
|
||||
self.assertEqual(x+1, -sys.maxsize)
|
||||
self.assertTrue(isinstance(x, int))
|
||||
# should return long
|
||||
self.assertIsInstance(x, int)
|
||||
# should return int
|
||||
self.assertEqual(int(s[1:]), sys.maxsize+1)
|
||||
|
||||
# should return long
|
||||
# should return int
|
||||
x = int(1e100)
|
||||
self.assertTrue(isinstance(x, int))
|
||||
self.assertIsInstance(x, int)
|
||||
x = int(-1e100)
|
||||
self.assertTrue(isinstance(x, int))
|
||||
self.assertIsInstance(x, int)
|
||||
|
||||
|
||||
# SF bug 434186: 0x80000000/2 != 0x80000000>>1.
|
||||
|
@ -79,7 +79,8 @@ class IntTestCases(unittest.TestCase):
|
|||
self.assertRaises(ValueError, int, '123\x00 245', 20)
|
||||
|
||||
x = int('1' * 600)
|
||||
self.assertTrue(isinstance(x, int))
|
||||
self.assertIsInstance(x, int)
|
||||
|
||||
|
||||
self.assertRaises(TypeError, int, 1, 12)
|
||||
|
||||
|
|
|
@ -2351,27 +2351,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
|
||||
|
|
|
@ -21,16 +21,16 @@ class TestBase(unittest.TestCase):
|
|||
|
||||
def _check_sample(self, msg):
|
||||
# Inspect a mailbox.Message representation of the sample message
|
||||
self.assertTrue(isinstance(msg, email.message.Message))
|
||||
self.assertTrue(isinstance(msg, mailbox.Message))
|
||||
self.assertIsInstance(msg, email.message.Message)
|
||||
self.assertIsInstance(msg, mailbox.Message)
|
||||
for key, value in _sample_headers.items():
|
||||
self.assertIn(value, msg.get_all(key))
|
||||
self.assertTrue(msg.is_multipart())
|
||||
self.assertEqual(len(msg.get_payload()), len(_sample_payloads))
|
||||
for i, payload in enumerate(_sample_payloads):
|
||||
part = msg.get_payload(i)
|
||||
self.assertTrue(isinstance(part, email.message.Message))
|
||||
self.assertFalse(isinstance(part, mailbox.Message))
|
||||
self.assertIsInstance(part, email.message.Message)
|
||||
self.assertNotIsInstance(part, mailbox.Message)
|
||||
self.assertEqual(part.get_payload(), payload)
|
||||
|
||||
def _delete_recursively(self, target):
|
||||
|
@ -149,7 +149,7 @@ class TestMailbox(TestBase):
|
|||
key0 = self._box.add(self._template % 0)
|
||||
key1 = self._box.add(_sample_message)
|
||||
msg0 = self._box.get_message(key0)
|
||||
self.assertTrue(isinstance(msg0, mailbox.Message))
|
||||
self.assertIsInstance(msg0, mailbox.Message)
|
||||
self.assertEqual(msg0['from'], 'foo')
|
||||
self.assertEqual(msg0.get_payload(), '0')
|
||||
self._check_sample(self._box.get_message(key1))
|
||||
|
@ -476,7 +476,7 @@ class TestMaildir(TestMailbox):
|
|||
msg.set_flags('RF')
|
||||
key = self._box.add(msg)
|
||||
msg_returned = self._box.get_message(key)
|
||||
self.assertTrue(isinstance(msg_returned, mailbox.MaildirMessage))
|
||||
self.assertIsInstance(msg_returned, mailbox.MaildirMessage)
|
||||
self.assertEqual(msg_returned.get_subdir(), 'cur')
|
||||
self.assertEqual(msg_returned.get_flags(), 'FR')
|
||||
|
||||
|
@ -516,7 +516,7 @@ class TestMaildir(TestMailbox):
|
|||
box = mailbox.Maildir(self._path, factory=FakeMessage)
|
||||
box.colon = self._box.colon
|
||||
msg2 = box.get_message(key)
|
||||
self.assertTrue(isinstance(msg2, FakeMessage))
|
||||
self.assertIsInstance(msg2, FakeMessage)
|
||||
|
||||
def test_initialize_new(self):
|
||||
# Initialize a non-existent mailbox
|
||||
|
@ -1082,9 +1082,9 @@ class TestMessage(TestBase):
|
|||
# Initialize without arguments
|
||||
msg = self._factory()
|
||||
self._post_initialize_hook(msg)
|
||||
self.assertTrue(isinstance(msg, email.message.Message))
|
||||
self.assertTrue(isinstance(msg, mailbox.Message))
|
||||
self.assertTrue(isinstance(msg, self._factory))
|
||||
self.assertIsInstance(msg, email.message.Message)
|
||||
self.assertIsInstance(msg, mailbox.Message)
|
||||
self.assertIsInstance(msg, self._factory)
|
||||
self.assertEqual(msg.keys(), [])
|
||||
self.assertFalse(msg.is_multipart())
|
||||
self.assertEqual(msg.get_payload(), None)
|
||||
|
|
|
@ -623,7 +623,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__)
|
||||
|
@ -667,9 +667,9 @@ class CStringIOTest(PyStringIOTest):
|
|||
memio = self.ioclass()
|
||||
state = memio.__getstate__()
|
||||
self.assertEqual(len(state), 4)
|
||||
self.assert_(isinstance(state[0], str))
|
||||
self.assert_(isinstance(state[1], str))
|
||||
self.assert_(isinstance(state[2], int))
|
||||
self.assertIsInstance(state[0], str)
|
||||
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"))
|
||||
|
@ -119,7 +119,7 @@ class AbstractMemoryTests:
|
|||
expected = b"".join(
|
||||
self.getitem_type(bytes([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:
|
||||
|
|
|
@ -133,7 +133,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)
|
||||
|
|
|
@ -174,6 +174,7 @@ class TestNtpath(unittest.TestCase):
|
|||
tester("ntpath.normpath('C:////a/b')", r'C:\a\b')
|
||||
tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b')
|
||||
|
||||
|
||||
def test_expandvars(self):
|
||||
with support.EnvironmentVarGuard() as env:
|
||||
env.clear()
|
||||
|
|
|
@ -60,7 +60,7 @@ class OpcodeTest(unittest.TestCase):
|
|||
|
||||
try: raise DClass(a)
|
||||
except DClass as v:
|
||||
self.assertTrue(isinstance(v, DClass))
|
||||
self.assertIsInstance(v, DClass)
|
||||
else:
|
||||
self.fail("no exception")
|
||||
|
||||
|
|
|
@ -338,7 +338,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")
|
||||
|
|
|
@ -34,7 +34,7 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
|
|||
code = suite.compile()
|
||||
scope = {}
|
||||
exec(code, {}, scope)
|
||||
self.assertTrue(isinstance(scope["x"], str))
|
||||
self.assertIsInstance(scope["x"], str)
|
||||
|
||||
def check_suite(self, s):
|
||||
self.roundtrip(parser.suite, s)
|
||||
|
|
|
@ -132,7 +132,7 @@ class PosixTester(unittest.TestCase):
|
|||
fp = open(support.TESTFN)
|
||||
try:
|
||||
fd = posix.dup(fp.fileno())
|
||||
self.assertTrue(isinstance(fd, int))
|
||||
self.assertIsInstance(fd, int)
|
||||
os.close(fd)
|
||||
finally:
|
||||
fp.close()
|
||||
|
@ -260,7 +260,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):
|
||||
|
|
|
@ -402,8 +402,8 @@ class PosixPathTest(unittest.TestCase):
|
|||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
self.assertTrue(isinstance(posixpath.expanduser("~/"), str))
|
||||
self.assertTrue(isinstance(posixpath.expanduser(b"~/"), bytes))
|
||||
self.assertIsInstance(posixpath.expanduser("~/"), str)
|
||||
self.assertIsInstance(posixpath.expanduser(b"~/"), bytes)
|
||||
# if home directory == root directory, this test makes no sense
|
||||
if posixpath.expanduser("~") != '/':
|
||||
self.assertEqual(
|
||||
|
@ -414,10 +414,10 @@ class PosixPathTest(unittest.TestCase):
|
|||
posixpath.expanduser(b"~") + b"/",
|
||||
posixpath.expanduser(b"~/")
|
||||
)
|
||||
self.assertTrue(isinstance(posixpath.expanduser("~root/"), str))
|
||||
self.assertTrue(isinstance(posixpath.expanduser("~foo/"), str))
|
||||
self.assertTrue(isinstance(posixpath.expanduser(b"~root/"), bytes))
|
||||
self.assertTrue(isinstance(posixpath.expanduser(b"~foo/"), bytes))
|
||||
self.assertIsInstance(posixpath.expanduser("~root/"), str)
|
||||
self.assertIsInstance(posixpath.expanduser("~foo/"), str)
|
||||
self.assertIsInstance(posixpath.expanduser(b"~root/"), bytes)
|
||||
self.assertIsInstance(posixpath.expanduser(b"~foo/"), bytes)
|
||||
|
||||
with support.EnvironmentVarGuard() as env:
|
||||
env['HOME'] = '/'
|
||||
|
|
|
@ -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, str))
|
||||
self.assertIsInstance(e.pw_name, str)
|
||||
self.assertEqual(e[1], e.pw_passwd)
|
||||
self.assertTrue(isinstance(e.pw_passwd, str))
|
||||
self.assertIsInstance(e.pw_passwd, str)
|
||||
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, str))
|
||||
self.assertIsInstance(e.pw_gecos, str)
|
||||
self.assertEqual(e[5], e.pw_dir)
|
||||
self.assertTrue(isinstance(e.pw_dir, str))
|
||||
self.assertIsInstance(e.pw_dir, str)
|
||||
self.assertEqual(e[6], e.pw_shell)
|
||||
self.assertTrue(isinstance(e.pw_shell, str))
|
||||
self.assertIsInstance(e.pw_shell, str)
|
||||
|
||||
# The following won't work, because of duplicate entries
|
||||
# for one uid
|
||||
|
|
|
@ -84,12 +84,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, type))
|
||||
self.assertIsInstance(py_item, type)
|
||||
if py_item.__module__ != moduleName:
|
||||
continue # skip classes that came from somewhere else
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ class TestCause(unittest.TestCase):
|
|||
try:
|
||||
raise IndexError from KeyError
|
||||
except IndexError as e:
|
||||
self.assertTrue(isinstance(e.__cause__, KeyError))
|
||||
self.assertIsInstance(e.__cause__, KeyError)
|
||||
else:
|
||||
self.fail("No exception raised")
|
||||
|
||||
|
@ -166,7 +166,7 @@ class TestTraceback(unittest.TestCase):
|
|||
try:
|
||||
raise IndexError()
|
||||
except IndexError as e:
|
||||
self.assertTrue(isinstance(e.__traceback__, types.TracebackType))
|
||||
self.assertIsInstance(e.__traceback__, types.TracebackType)
|
||||
else:
|
||||
self.fail("No exception raised")
|
||||
|
||||
|
@ -203,7 +203,7 @@ class TestContext(unittest.TestCase):
|
|||
raise OSError()
|
||||
except OSError as e:
|
||||
self.assertNotEqual(e.__context__, context)
|
||||
self.assertTrue(isinstance(e.__context__, context))
|
||||
self.assertIsInstance(e.__context__, context)
|
||||
else:
|
||||
self.fail("No exception raised")
|
||||
|
||||
|
@ -216,7 +216,7 @@ class TestContext(unittest.TestCase):
|
|||
raise OSError
|
||||
except OSError as e:
|
||||
self.assertNotEqual(e.__context__, context)
|
||||
self.assertTrue(isinstance(e.__context__, context))
|
||||
self.assertIsInstance(e.__context__, context)
|
||||
else:
|
||||
self.fail("No exception raised")
|
||||
|
||||
|
@ -227,7 +227,7 @@ class TestContext(unittest.TestCase):
|
|||
except:
|
||||
raise OSError
|
||||
except OSError as e:
|
||||
self.assertTrue(isinstance(e.__context__, ZeroDivisionError))
|
||||
self.assertIsInstance(e.__context__, ZeroDivisionError)
|
||||
else:
|
||||
self.fail("No exception raised")
|
||||
|
||||
|
@ -238,7 +238,7 @@ class TestContext(unittest.TestCase):
|
|||
except:
|
||||
xyzzy
|
||||
except NameError as e:
|
||||
self.assertTrue(isinstance(e.__context__, ZeroDivisionError))
|
||||
self.assertIsInstance(e.__context__, ZeroDivisionError)
|
||||
else:
|
||||
self.fail("No exception raised")
|
||||
|
||||
|
@ -260,7 +260,7 @@ class TestContext(unittest.TestCase):
|
|||
finally:
|
||||
raise OSError
|
||||
except OSError as e:
|
||||
self.assertTrue(isinstance(e.__context__, ZeroDivisionError))
|
||||
self.assertIsInstance(e.__context__, ZeroDivisionError)
|
||||
else:
|
||||
self.fail("No exception raised")
|
||||
|
||||
|
@ -274,7 +274,7 @@ class TestContext(unittest.TestCase):
|
|||
with ContextManager():
|
||||
1/0
|
||||
except NameError as e:
|
||||
self.assertTrue(isinstance(e.__context__, ZeroDivisionError))
|
||||
self.assertIsInstance(e.__context__, ZeroDivisionError)
|
||||
else:
|
||||
self.fail("No exception raised")
|
||||
|
||||
|
@ -320,7 +320,7 @@ class TestContext(unittest.TestCase):
|
|||
del g
|
||||
raise KeyError
|
||||
except Exception as e:
|
||||
self.assertTrue(isinstance(e.__context__, ValueError))
|
||||
self.assertIsInstance(e.__context__, ValueError)
|
||||
|
||||
f()
|
||||
|
||||
|
@ -344,7 +344,7 @@ class TestContext(unittest.TestCase):
|
|||
raise TypeError
|
||||
except Exception as e:
|
||||
self.assertNotEqual(e.__context__, None)
|
||||
self.assertTrue(isinstance(e.__context__, AttributeError))
|
||||
self.assertIsInstance(e.__context__, AttributeError)
|
||||
|
||||
with support.captured_output("stderr"):
|
||||
f()
|
||||
|
|
|
@ -143,7 +143,7 @@ class SysModuleTest(unittest.TestCase):
|
|||
def test_getdefaultencoding(self):
|
||||
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
|
||||
|
@ -227,13 +227,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_call_tracing(self):
|
||||
self.assertRaises(TypeError, sys.call_tracing, type, 2)
|
||||
|
@ -261,7 +261,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)
|
||||
|
@ -357,13 +357,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, str))
|
||||
self.assertTrue(isinstance(sys.exec_prefix, str))
|
||||
self.assertTrue(isinstance(sys.executable, str))
|
||||
self.assertIsInstance(sys.builtin_module_names, tuple)
|
||||
self.assertIsInstance(sys.copyright, str)
|
||||
self.assertIsInstance(sys.exec_prefix, str)
|
||||
self.assertIsInstance(sys.executable, str)
|
||||
self.assertEqual(len(sys.float_info), 11)
|
||||
self.assertEqual(sys.float_info.radix, 2)
|
||||
self.assertEqual(len(sys.int_info), 2)
|
||||
|
@ -371,25 +371,25 @@ class SysModuleTest(unittest.TestCase):
|
|||
self.assertTrue(sys.int_info.sizeof_digit >= 1)
|
||||
self.assertEqual(type(sys.int_info.bits_per_digit), int)
|
||||
self.assertEqual(type(sys.int_info.sizeof_digit), int)
|
||||
self.assertTrue(isinstance(sys.hexversion, int))
|
||||
self.assertTrue(isinstance(sys.maxsize, int))
|
||||
self.assertTrue(isinstance(sys.maxunicode, int))
|
||||
self.assertTrue(isinstance(sys.platform, str))
|
||||
self.assertTrue(isinstance(sys.prefix, str))
|
||||
self.assertTrue(isinstance(sys.version, str))
|
||||
self.assertIsInstance(sys.hexversion, int)
|
||||
self.assertIsInstance(sys.maxsize, int)
|
||||
self.assertIsInstance(sys.maxunicode, int)
|
||||
self.assertIsInstance(sys.platform, str)
|
||||
self.assertIsInstance(sys.prefix, str)
|
||||
self.assertIsInstance(sys.version, str)
|
||||
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)
|
||||
|
|
|
@ -142,8 +142,7 @@ class test__candidate_tempdir_list(TC):
|
|||
|
||||
self.assertFalse(len(cand) == 0)
|
||||
for c in cand:
|
||||
self.assertTrue(isinstance(c, str),
|
||||
"%s is not a string" % c)
|
||||
self.assertIsInstance(c, str)
|
||||
|
||||
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
|
||||
|
@ -326,7 +325,7 @@ class test_gettempprefix(TC):
|
|||
# gettempprefix returns a nonempty prefix string
|
||||
p = tempfile.gettempprefix()
|
||||
|
||||
self.assertTrue(isinstance(p, str))
|
||||
self.assertIsInstance(p, str)
|
||||
self.assertTrue(len(p) > 0)
|
||||
|
||||
def test_usable_template(self):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -149,12 +149,12 @@ class TypesTests(unittest.TestCase):
|
|||
(prod, type(prod)))
|
||||
|
||||
x = sys.maxsize
|
||||
self.assertTrue(isinstance(x + 1, int),
|
||||
"(sys.maxsize + 1) should have returned int")
|
||||
self.assertTrue(isinstance(-x - 1, int),
|
||||
"(-sys.maxsize - 1) should have returned int")
|
||||
self.assertTrue(isinstance(-x - 2, int),
|
||||
"(-sys.maxsize - 2) should have returned int")
|
||||
self.assertIsInstance(x + 1, int,
|
||||
"(sys.maxsize + 1) should have returned int")
|
||||
self.assertIsInstance(-x - 1, int,
|
||||
"(-sys.maxsize - 1) should have returned int")
|
||||
self.assertIsInstance(-x - 2, int,
|
||||
"(-sys.maxsize - 2) should have returned int")
|
||||
|
||||
try: 5 << -5
|
||||
except ValueError: pass
|
||||
|
|
|
@ -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()
|
||||
|
@ -1808,7 +1808,7 @@ class Test_FunctionTestCase(TestCase):
|
|||
def test_id(self):
|
||||
test = unittest.FunctionTestCase(lambda: None)
|
||||
|
||||
self.assertTrue(isinstance(test.id(), str))
|
||||
self.assertIsInstance(test.id(), str)
|
||||
|
||||
# "Returns a one-line description of the test, or None if no description
|
||||
# has been provided. The default implementation of this method returns
|
||||
|
@ -1996,7 +1996,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)"
|
||||
# ...
|
||||
|
@ -2046,7 +2046,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
|
||||
################################################################
|
||||
|
@ -2437,7 +2437,8 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
|
|||
def runTest(self):
|
||||
pass
|
||||
|
||||
self.assertTrue(isinstance(Foo().id(), str))
|
||||
self.assertIsInstance(Foo().id(), str)
|
||||
|
||||
|
||||
# "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
|
||||
|
@ -2859,7 +2860,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):
|
||||
|
|
|
@ -85,8 +85,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")
|
||||
|
@ -97,7 +96,7 @@ class urlopen_FileTests(unittest.TestCase):
|
|||
self.returned_obj.close()
|
||||
|
||||
def test_info(self):
|
||||
self.assertTrue(isinstance(self.returned_obj.info(), email.message.Message))
|
||||
self.assertIsInstance(self.returned_obj.info(), email.message.Message)
|
||||
|
||||
def test_geturl(self):
|
||||
self.assertEqual(self.returned_obj.geturl(), self.pathname)
|
||||
|
@ -250,9 +249,9 @@ class urlretrieve_FileTests(unittest.TestCase):
|
|||
# a headers value is returned.
|
||||
result = urllib.request.urlretrieve("file:%s" % support.TESTFN)
|
||||
self.assertEqual(result[0], support.TESTFN)
|
||||
self.assertTrue(isinstance(result[1], email.message.Message),
|
||||
"did not get a email.message.Message instance as second "
|
||||
"returned value")
|
||||
self.assertIsInstance(result[1], email.message.Message,
|
||||
"did not get a email.message.Message instance "
|
||||
"as second returned value")
|
||||
|
||||
def test_copy(self):
|
||||
# Test that setting the filename argument works.
|
||||
|
@ -275,9 +274,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" % support.TESTFN
|
||||
|
|
|
@ -589,12 +589,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
|
||||
|
|
|
@ -459,9 +459,9 @@ class TestUrlopen(BaseTestCase):
|
|||
open_url = urllib.request.urlopen(
|
||||
"http://localhost:%s" % handler.port)
|
||||
info_obj = open_url.info()
|
||||
self.assertTrue(isinstance(info_obj, email.message.Message),
|
||||
"object returned by 'info' is not an instance of "
|
||||
"email.message.Message")
|
||||
self.assertIsInstance(info_obj, email.message.Message,
|
||||
"object returned by 'info' is not an "
|
||||
"instance of email.message.Message")
|
||||
self.assertEqual(info_obj.get_content_subtype(), "plain")
|
||||
finally:
|
||||
self.server.stop()
|
||||
|
|
|
@ -172,7 +172,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 support.time_out, \
|
||||
support.socket_peer_reset, \
|
||||
|
|
|
@ -73,10 +73,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(), bytes),
|
||||
"readline did not return bytes")
|
||||
self.assertTrue(isinstance(open_url.readlines(), list),
|
||||
"readlines did not return a list")
|
||||
self.assertIsInstance(open_url.readline(), bytes,
|
||||
"readline did not return a string")
|
||||
self.assertIsInstance(open_url.readlines(), list,
|
||||
"readlines did not return a list")
|
||||
finally:
|
||||
open_url.close()
|
||||
|
||||
|
@ -87,9 +87,9 @@ class urlopenNetworkTests(unittest.TestCase):
|
|||
info_obj = open_url.info()
|
||||
finally:
|
||||
open_url.close()
|
||||
self.assertTrue(isinstance(info_obj, email.message.Message),
|
||||
"object returned by 'info' is not an instance of "
|
||||
"email.message.Message")
|
||||
self.assertIsInstance(info_obj, email.message.Message,
|
||||
"object returned by 'info' is not an "
|
||||
"instance of email.message.Message")
|
||||
self.assertEqual(info_obj.get_content_subtype(), "html")
|
||||
|
||||
def test_geturl(self):
|
||||
|
@ -177,8 +177,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, email.message.Message),
|
||||
"header is not an instance of email.message.Message")
|
||||
self.assertIsInstance(header, email.message.Message,
|
||||
"header is not an instance of email.message.Message")
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -39,8 +39,8 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol):
|
|||
self.assertEqual(collections.UserDict.fromkeys('one two'.split(), 1), d5)
|
||||
self.assertEqual(collections.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()), collections.UserDict))
|
||||
self.assertTrue(isinstance(u2.fromkeys('one two'.split()), collections.UserDict))
|
||||
self.assertIsInstance(u1.fromkeys('one two'.split()), collections.UserDict)
|
||||
self.assertIsInstance(u2.fromkeys('one two'.split()), collections.UserDict)
|
||||
|
||||
# Test __repr__
|
||||
self.assertEqual(str(u0), str(d0))
|
||||
|
|
|
@ -211,12 +211,12 @@ 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)
|
||||
elif isinstance(value,BytesIO):
|
||||
self.assertTrue(isinstance(env[key],BytesIO))
|
||||
self.assertIsInstance(env[key],BytesIO)
|
||||
else:
|
||||
self.assertEqual(env[key],value)
|
||||
self.assertEqual(env[key], value)
|
||||
|
||||
# Check existing value
|
||||
env = {key:alt}
|
||||
|
|
|
@ -75,11 +75,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):
|
||||
|
@ -146,6 +146,7 @@ class XMLRPCTestCase(unittest.TestCase):
|
|||
[('Authorization', 'Basic dXNlcg==')], {}))
|
||||
|
||||
|
||||
|
||||
class HelperTestCase(unittest.TestCase):
|
||||
def test_escape(self):
|
||||
self.assertEqual(xmlrpclib.escape("a&b"), "a&b")
|
||||
|
|
|
@ -595,6 +595,7 @@ class OtherTests(unittest.TestCase):
|
|||
with zipfile.ZipFile(TESTFN, "w") as zf:
|
||||
zf.writestr("foo.txt", "Test for unicode filename")
|
||||
zf.writestr("\xf6.txt", "Test for unicode filename")
|
||||
self.assertIsInstance(zf.infolist()[0].filename, str)
|
||||
|
||||
with zipfile.ZipFile(TESTFN, "r") as zf:
|
||||
self.assertEqual(zf.filelist[0].filename, "foo.txt")
|
||||
|
|
|
@ -174,7 +174,7 @@ class CompressObjectTestCase(unittest.TestCase):
|
|||
|
||||
decombuf = zlib.decompress(combuf)
|
||||
# Test type of return value
|
||||
self.assertTrue(isinstance(decombuf, bytes))
|
||||
self.assertIsInstance(decombuf, bytes)
|
||||
|
||||
self.assertEqual(data, decombuf)
|
||||
|
||||
|
@ -373,7 +373,7 @@ class CompressObjectTestCase(unittest.TestCase):
|
|||
data = HAMLET_SCENE
|
||||
comp = zlib.compress(data)
|
||||
# Test type of return value
|
||||
self.assertTrue(isinstance(comp, bytes))
|
||||
self.assertIsInstance(comp, bytes)
|
||||
|
||||
d0 = zlib.decompressobj()
|
||||
bufs0 = []
|
||||
|
|
Loading…
Reference in New Issue