diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2010-01-24 19:26:24 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2010-01-24 19:26:24 (GMT) |
commit | e96159335f6bb26615b57f880bf90440ed0123e4 (patch) | |
tree | 273325221fdef15629ebc63287c4772a3af40879 /Lib/test/test_collections.py | |
parent | f41d29a8ebc27aafc18b6850648f1faa918e0e5d (diff) | |
download | cpython-e96159335f6bb26615b57f880bf90440ed0123e4.zip cpython-e96159335f6bb26615b57f880bf90440ed0123e4.tar.gz cpython-e96159335f6bb26615b57f880bf90440ed0123e4.tar.bz2 |
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
........
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r-- | Lib/test/test_collections.py | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index cadac99..2dc7157 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -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) |