diff options
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r-- | Lib/test/test_collections.py | 144 |
1 files changed, 72 insertions, 72 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 8387564..ded8b70 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -44,9 +44,9 @@ class TestNamedTuple(unittest.TestCase): namedtuple('_', 'a b c') # Test leading underscores in a typename nt = namedtuple('nt', 'the quick brown fox') # check unicode input - self.assert_("u'" not in repr(nt._fields)) + self.assertTrue("u'" not in repr(nt._fields)) nt = namedtuple('nt', ('the', 'quick')) # check unicode input - self.assert_("u'" not in repr(nt._fields)) + self.assertTrue("u'" not in repr(nt._fields)) self.assertRaises(TypeError, Point._make, [11]) # catch too few args self.assertRaises(TypeError, Point._make, [11, 22, 33]) # catch too many args @@ -75,8 +75,8 @@ class TestNamedTuple(unittest.TestCase): self.assertRaises(TypeError, eval, 'Point(XXX=1, y=2)', locals()) # wrong keyword argument self.assertRaises(TypeError, eval, 'Point(x=1)', locals()) # missing keyword argument self.assertEqual(repr(p), 'Point(x=11, y=22)') - self.assert_('__dict__' not in dir(p)) # verify instance has no dict - self.assert_('__weakref__' not in dir(p)) + self.assertTrue('__dict__' not in dir(p)) # verify instance has no dict + self.assertTrue('__weakref__' not in dir(p)) self.assertEqual(p, Point._make([11, 22])) # test _make classmethod self.assertEqual(p._fields, ('x', 'y')) # test _fields attribute self.assertEqual(p._replace(x=1), (1, 22)) # test _replace method @@ -103,7 +103,7 @@ class TestNamedTuple(unittest.TestCase): Point = namedtuple('Point', 'x y') p = Point(11, 22) - self.assert_(isinstance(p, tuple)) + self.assertTrue(isinstance(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,8 +236,8 @@ class TestOneTrickPonyABCs(ABCTestCase): # Check some non-hashables non_samples = [bytearray(), list(), set(), dict()] for x in non_samples: - self.failIf(isinstance(x, Hashable), repr(x)) - self.failIf(issubclass(type(x), Hashable), repr(type(x))) + self.assertFalse(isinstance(x, Hashable), repr(x)) + self.assertFalse(issubclass(type(x), Hashable), repr(type(x))) # Check some hashables samples = [None, int(), float(), complex(), @@ -246,23 +246,23 @@ class TestOneTrickPonyABCs(ABCTestCase): int, list, object, type, bytes() ] for x in samples: - self.failUnless(isinstance(x, Hashable), repr(x)) - self.failUnless(issubclass(type(x), Hashable), repr(type(x))) + self.assertTrue(isinstance(x, Hashable), repr(x)) + self.assertTrue(issubclass(type(x), Hashable), repr(type(x))) self.assertRaises(TypeError, Hashable) # Check direct subclassing class H(Hashable): def __hash__(self): return super().__hash__() self.assertEqual(hash(H()), 0) - self.failIf(issubclass(int, H)) + self.assertFalse(issubclass(int, H)) self.validate_abstract_methods(Hashable, '__hash__') def test_Iterable(self): # Check some non-iterables non_samples = [None, 42, 3.14, 1j] for x in non_samples: - self.failIf(isinstance(x, Iterable), repr(x)) - self.failIf(issubclass(type(x), Iterable), repr(type(x))) + self.assertFalse(isinstance(x, Iterable), repr(x)) + self.assertFalse(issubclass(type(x), Iterable), repr(type(x))) # Check some iterables samples = [bytes(), str(), tuple(), list(), set(), frozenset(), dict(), @@ -271,21 +271,21 @@ class TestOneTrickPonyABCs(ABCTestCase): (x for x in []), ] for x in samples: - self.failUnless(isinstance(x, Iterable), repr(x)) - self.failUnless(issubclass(type(x), Iterable), repr(type(x))) + self.assertTrue(isinstance(x, Iterable), repr(x)) + self.assertTrue(issubclass(type(x), Iterable), repr(type(x))) # Check direct subclassing class I(Iterable): def __iter__(self): return super().__iter__() self.assertEqual(list(I()), []) - self.failIf(issubclass(str, I)) + self.assertFalse(issubclass(str, I)) self.validate_abstract_methods(Iterable, '__iter__') def test_Iterator(self): non_samples = [None, 42, 3.14, 1j, b"", "", (), [], {}, set()] for x in non_samples: - self.failIf(isinstance(x, Iterator), repr(x)) - self.failIf(issubclass(type(x), Iterator), repr(type(x))) + self.assertFalse(isinstance(x, Iterator), repr(x)) + self.assertFalse(issubclass(type(x), Iterator), repr(type(x))) samples = [iter(bytes()), iter(str()), iter(tuple()), iter(list()), iter(dict()), iter(set()), iter(frozenset()), @@ -295,8 +295,8 @@ class TestOneTrickPonyABCs(ABCTestCase): (x for x in []), ] for x in samples: - self.failUnless(isinstance(x, Iterator), repr(x)) - self.failUnless(issubclass(type(x), Iterator), repr(type(x))) + self.assertTrue(isinstance(x, Iterator), repr(x)) + self.assertTrue(issubclass(type(x), Iterator), repr(type(x))) self.validate_abstract_methods(Iterator, '__next__') def test_Sized(self): @@ -305,15 +305,15 @@ class TestOneTrickPonyABCs(ABCTestCase): (x for x in []), ] for x in non_samples: - self.failIf(isinstance(x, Sized), repr(x)) - self.failIf(issubclass(type(x), Sized), repr(type(x))) + self.assertFalse(isinstance(x, Sized), repr(x)) + 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.failUnless(isinstance(x, Sized), repr(x)) - self.failUnless(issubclass(type(x), Sized), repr(type(x))) + self.assertTrue(isinstance(x, Sized), repr(x)) + self.assertTrue(issubclass(type(x), Sized), repr(type(x))) self.validate_abstract_methods(Sized, '__len__') def test_Container(self): @@ -322,15 +322,15 @@ class TestOneTrickPonyABCs(ABCTestCase): (x for x in []), ] for x in non_samples: - self.failIf(isinstance(x, Container), repr(x)) - self.failIf(issubclass(type(x), Container), repr(type(x))) + self.assertFalse(isinstance(x, Container), repr(x)) + 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.failUnless(isinstance(x, Container), repr(x)) - self.failUnless(issubclass(type(x), Container), repr(type(x))) + self.assertTrue(isinstance(x, Container), repr(x)) + self.assertTrue(issubclass(type(x), Container), repr(type(x))) self.validate_abstract_methods(Container, '__contains__') def test_Callable(self): @@ -340,32 +340,32 @@ class TestOneTrickPonyABCs(ABCTestCase): (x for x in []), ] for x in non_samples: - self.failIf(isinstance(x, Callable), repr(x)) - self.failIf(issubclass(type(x), Callable), repr(type(x))) + self.assertFalse(isinstance(x, Callable), repr(x)) + self.assertFalse(issubclass(type(x), Callable), repr(type(x))) samples = [lambda: None, type, int, object, len, list.append, [].append, ] for x in samples: - self.failUnless(isinstance(x, Callable), repr(x)) - self.failUnless(issubclass(type(x), Callable), repr(type(x))) + self.assertTrue(isinstance(x, Callable), repr(x)) + self.assertTrue(issubclass(type(x), Callable), repr(type(x))) self.validate_abstract_methods(Callable, '__call__') def test_direct_subclassing(self): for B in Hashable, Iterable, Iterator, Sized, Container, Callable: class C(B): pass - self.failUnless(issubclass(C, B)) - self.failIf(issubclass(int, C)) + self.assertTrue(issubclass(C, B)) + self.assertFalse(issubclass(int, C)) def test_registration(self): for B in Hashable, Iterable, Iterator, Sized, Container, Callable: class C: __hash__ = None # Make sure it isn't hashable by default - self.failIf(issubclass(C, B), B.__name__) + self.assertFalse(issubclass(C, B), B.__name__) B.register(C) - self.failUnless(issubclass(C, B)) + self.assertTrue(issubclass(C, B)) class WithSet(MutableSet): @@ -395,8 +395,8 @@ class TestCollectionABCs(ABCTestCase): def test_Set(self): for sample in [set, frozenset]: - self.failUnless(isinstance(sample(), Set)) - self.failUnless(issubclass(sample, Set)) + self.assertTrue(isinstance(sample(), Set)) + self.assertTrue(issubclass(sample, Set)) self.validate_abstract_methods(Set, '__contains__', '__iter__', '__len__') def test_hash_Set(self): @@ -412,13 +412,13 @@ class TestCollectionABCs(ABCTestCase): def __hash__(self): return self._hash() a, b = OneTwoThreeSet(), OneTwoThreeSet() - self.failUnless(hash(a) == hash(b)) + self.assertTrue(hash(a) == hash(b)) def test_MutableSet(self): - self.failUnless(isinstance(set(), MutableSet)) - self.failUnless(issubclass(set, MutableSet)) - self.failIf(isinstance(frozenset(), MutableSet)) - self.failIf(issubclass(frozenset, MutableSet)) + self.assertTrue(isinstance(set(), MutableSet)) + self.assertTrue(issubclass(set, MutableSet)) + self.assertFalse(isinstance(frozenset(), MutableSet)) + self.assertFalse(issubclass(frozenset, MutableSet)) self.validate_abstract_methods(MutableSet, '__contains__', '__iter__', '__len__', 'add', 'discard') @@ -457,46 +457,46 @@ class TestCollectionABCs(ABCTestCase): def test_Mapping(self): for sample in [dict]: - self.failUnless(isinstance(sample(), Mapping)) - self.failUnless(issubclass(sample, Mapping)) + self.assertTrue(isinstance(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.failUnless(isinstance(sample(), MutableMapping)) - self.failUnless(issubclass(sample, MutableMapping)) + self.assertTrue(isinstance(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.failUnless(isinstance(sample(), Sequence)) - self.failUnless(issubclass(sample, Sequence)) - self.failUnless(isinstance(range(10), Sequence)) - self.failUnless(issubclass(range, Sequence)) - self.failUnless(issubclass(str, Sequence)) + self.assertTrue(isinstance(sample(), Sequence)) + self.assertTrue(issubclass(sample, Sequence)) + self.assertTrue(isinstance(range(10), Sequence)) + self.assertTrue(issubclass(range, Sequence)) + self.assertTrue(issubclass(str, Sequence)) self.validate_abstract_methods(Sequence, '__contains__', '__iter__', '__len__', '__getitem__') def test_ByteString(self): for sample in [bytes, bytearray]: - self.failUnless(isinstance(sample(), ByteString)) - self.failUnless(issubclass(sample, ByteString)) + self.assertTrue(isinstance(sample(), ByteString)) + self.assertTrue(issubclass(sample, ByteString)) for sample in [str, list, tuple]: - self.failIf(isinstance(sample(), ByteString)) - self.failIf(issubclass(sample, ByteString)) - self.failIf(isinstance(memoryview(b""), ByteString)) - self.failIf(issubclass(memoryview, ByteString)) + self.assertFalse(isinstance(sample(), ByteString)) + self.assertFalse(issubclass(sample, ByteString)) + self.assertFalse(isinstance(memoryview(b""), ByteString)) + self.assertFalse(issubclass(memoryview, ByteString)) def test_MutableSequence(self): for sample in [tuple, str, bytes]: - self.failIf(isinstance(sample(), MutableSequence)) - self.failIf(issubclass(sample, MutableSequence)) + self.assertFalse(isinstance(sample(), MutableSequence)) + self.assertFalse(issubclass(sample, MutableSequence)) for sample in [list, bytearray]: - self.failUnless(isinstance(sample(), MutableSequence)) - self.failUnless(issubclass(sample, MutableSequence)) - self.failIf(issubclass(str, MutableSequence)) + self.assertTrue(isinstance(sample(), MutableSequence)) + self.assertTrue(issubclass(sample, MutableSequence)) + self.assertFalse(issubclass(str, MutableSequence)) self.validate_abstract_methods(MutableSequence, '__contains__', '__iter__', '__len__', '__getitem__', '__setitem__', '__delitem__', 'insert') @@ -506,10 +506,10 @@ 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.assert_(isinstance(c, dict)) - self.assert_(isinstance(c, Mapping)) - self.assert_(issubclass(Counter, dict)) - self.assert_(issubclass(Counter, Mapping)) + self.assertTrue(isinstance(c, dict)) + self.assertTrue(isinstance(c, Mapping)) + self.assertTrue(issubclass(Counter, dict)) + self.assertTrue(issubclass(Counter, Mapping)) self.assertEqual(len(c), 3) self.assertEqual(sum(c.values()), 6) self.assertEqual(sorted(c.values()), [1, 2, 3]) @@ -581,7 +581,7 @@ class TestCounter(unittest.TestCase): Counter(words), ]): msg = (i, dup, words) - self.assert_(dup is not words) + self.assertTrue(dup is not words) self.assertEquals(dup, words) self.assertEquals(len(dup), len(words)) self.assertEquals(type(dup), type(words)) @@ -597,7 +597,7 @@ class TestCounter(unittest.TestCase): def test_invariant_for_the_in_operator(self): c = Counter(a=10, b=-2, c=0) for elem in c: - self.assert_(elem in c) + self.assertTrue(elem in c) def test_multiset_operations(self): # Verify that adding a zero counter will strip zeros and negatives @@ -622,7 +622,7 @@ class TestCounter(unittest.TestCase): self.assertEqual(numberop(p[x], q[x]), result[x], (counterop, x, p, q)) # verify that results exclude non-positive counts - self.assert_(x>0 for x in result.values()) + self.assertTrue(x>0 for x in result.values()) elements = 'abcdef' for i in range(100): @@ -697,7 +697,7 @@ class TestOrderedDict(unittest.TestCase): pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)] od = OrderedDict(pairs) del od['a'] - self.assert_('a' not in od) + self.assertTrue('a' not in od) with self.assertRaises(KeyError): del od['a'] self.assertEqual(list(od.items()), pairs[:2] + pairs[3:]) @@ -778,7 +778,7 @@ class TestOrderedDict(unittest.TestCase): update_test, OrderedDict(od), ]): - self.assert_(dup is not od) + self.assertTrue(dup is not od) self.assertEquals(dup, od) self.assertEquals(list(dup.items()), list(od.items())) self.assertEquals(len(dup), len(od)) @@ -791,7 +791,7 @@ class TestOrderedDict(unittest.TestCase): od = OrderedDict(pairs) # yaml.dump(od) --> # '!!python/object/apply:__main__.OrderedDict\n- - [a, 1]\n - [b, 2]\n' - self.assert_(all(type(pair)==list for pair in od.__reduce__()[1])) + self.assertTrue(all(type(pair)==list for pair in od.__reduce__()[1])) def test_reduce_not_too_fat(self): # do not save instance dictionary if not needed |