MCPcopy Index your code
hub / github.com/python/cpython / test_Iterable

Method test_Iterable

Lib/test/test_collections.py:969–1001  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

967 self.validate_abstract_methods(AsyncIterator, '__anext__')
968
969 def test_Iterable(self):
970 # Check some non-iterables
971 non_samples = [None, 42, 3.14, 1j]
972 for x in non_samples:
973 self.assertNotIsInstance(x, Iterable)
974 self.assertNotIsSubclass(type(x), Iterable)
975 # Check some iterables
976 samples = [bytes(), str(),
977 tuple(), list(), set(), frozenset(), dict(),
978 dict().keys(), dict().items(), dict().values(),
979 _test_gen(),
980 (x for x in []),
981 ]
982 for x in samples:
983 self.assertIsInstance(x, Iterable)
984 self.assertIsSubclass(type(x), Iterable)
985 # Check direct subclassing
986 class I(Iterable):
987 def __iter__(self):
988 return super().__iter__()
989 self.assertEqual(list(I()), [])
990 self.assertNotIsSubclass(str, I)
991 self.validate_abstract_methods(Iterable, '__iter__')
992 self.validate_isinstance(Iterable, '__iter__')
993 # Check None blocking
994 class It:
995 def __iter__(self): return iter([])
996 class ItBlocked(It):
997 __iter__ = None
998 self.assertIsSubclass(It, Iterable)
999 self.assertIsInstance(It(), Iterable)
1000 self.assertNotIsSubclass(ItBlocked, Iterable)
1001 self.assertNotIsInstance(ItBlocked(), Iterable)
1002
1003 def test_Reversible(self):
1004 # Check some non-reversibles

Callers

nothing calls this directly

Calls 15

strFunction · 0.85
listClass · 0.85
setFunction · 0.85
_test_genFunction · 0.85
ItBlockedClass · 0.85
assertNotIsInstanceMethod · 0.80
assertNotIsSubclassMethod · 0.80
assertIsInstanceMethod · 0.80
assertIsSubclassMethod · 0.80
validate_isinstanceMethod · 0.80
IClass · 0.70

Tested by

no test coverage detected