mirror of https://github.com/python/cpython.git
Issue #24286: Forward port dict view abstract base class tests.
This commit is contained in:
parent
395f92d471
commit
c074e9d765
|
@ -1867,6 +1867,13 @@ def test_sizeof(self):
|
|||
od = OrderedDict(**d)
|
||||
self.assertGreater(sys.getsizeof(od), sys.getsizeof(d))
|
||||
|
||||
def test_views(self):
|
||||
# See http://bugs.python.org/issue24286
|
||||
s = 'the quick brown fox jumped over a lazy dog yesterday before dawn'.split()
|
||||
od = OrderedDict.fromkeys(s)
|
||||
self.assertEqual(od.keys(), dict(od).keys())
|
||||
self.assertEqual(od.items(), dict(od).items())
|
||||
|
||||
def test_override_update(self):
|
||||
# Verify that subclasses can override update() without breaking __init__()
|
||||
class MyOD(OrderedDict):
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import collections
|
||||
import unittest
|
||||
|
||||
class DictSetTest(unittest.TestCase):
|
||||
|
@ -197,6 +198,27 @@ def test_recursive_repr(self):
|
|||
d[42] = d.values()
|
||||
self.assertRaises(RuntimeError, repr, d)
|
||||
|
||||
def test_abc_registry(self):
|
||||
d = dict(a=1)
|
||||
|
||||
self.assertIsInstance(d.keys(), collections.KeysView)
|
||||
self.assertIsInstance(d.keys(), collections.MappingView)
|
||||
self.assertIsInstance(d.keys(), collections.Set)
|
||||
self.assertIsInstance(d.keys(), collections.Sized)
|
||||
self.assertIsInstance(d.keys(), collections.Iterable)
|
||||
self.assertIsInstance(d.keys(), collections.Container)
|
||||
|
||||
self.assertIsInstance(d.values(), collections.ValuesView)
|
||||
self.assertIsInstance(d.values(), collections.MappingView)
|
||||
self.assertIsInstance(d.values(), collections.Sized)
|
||||
|
||||
self.assertIsInstance(d.items(), collections.ItemsView)
|
||||
self.assertIsInstance(d.items(), collections.MappingView)
|
||||
self.assertIsInstance(d.items(), collections.Set)
|
||||
self.assertIsInstance(d.items(), collections.Sized)
|
||||
self.assertIsInstance(d.items(), collections.Iterable)
|
||||
self.assertIsInstance(d.items(), collections.Container)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue