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

Method test_zip

Lib/test/test_builtin.py:2150–2192  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2148 return items
2149
2150 def test_zip(self):
2151 a = (1, 2, 3)
2152 b = (4, 5, 6)
2153 t = [(1, 4), (2, 5), (3, 6)]
2154 self.assertEqual(list(zip(a, b)), t)
2155 b = [4, 5, 6]
2156 self.assertEqual(list(zip(a, b)), t)
2157 b = (4, 5, 6, 7)
2158 self.assertEqual(list(zip(a, b)), t)
2159 class I:
2160 def __getitem__(self, i):
2161 if i < 0 or i > 2: raise IndexError
2162 return i + 4
2163 self.assertEqual(list(zip(a, I())), t)
2164 self.assertEqual(list(zip()), [])
2165 self.assertEqual(list(zip(*[])), [])
2166 self.assertRaises(TypeError, zip, None)
2167 class G:
2168 pass
2169 self.assertRaises(TypeError, zip, a, G())
2170 self.assertRaises(RuntimeError, zip, a, TestFailingIter())
2171
2172 # Make sure zip doesn't try to allocate a billion elements for the
2173 # result list when one of its arguments doesn't say how long it is.
2174 # A MemoryError is the most likely failure mode.
2175 class SequenceWithoutALength:
2176 def __getitem__(self, i):
2177 if i == 5:
2178 raise IndexError
2179 else:
2180 return i
2181 self.assertEqual(
2182 list(zip(SequenceWithoutALength(), range(2**30))),
2183 list(enumerate(range(5)))
2184 )
2185
2186 class BadSeq:
2187 def __getitem__(self, i):
2188 if i == 5:
2189 raise ValueError
2190 else:
2191 return i
2192 self.assertRaises(ValueError, list, zip(BadSeq(), BadSeq()))
2193
2194 def test_zip_pickle(self):
2195 a = (1, 2, 3)

Callers

nothing calls this directly

Calls 9

listClass · 0.85
enumerateFunction · 0.85
IClass · 0.70
GClass · 0.70
TestFailingIterClass · 0.70
BadSeqClass · 0.70
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected