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

Method test_exception_locations

Lib/test/test_iter.py:1148–1185  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1146 self.assertRaises(ZeroDivisionError, iter, BadIterableClass())
1147
1148 def test_exception_locations(self):
1149 # The location of an exception raised from __init__ or
1150 # __next__ should be the iterator expression
1151
1152 def init_raises():
1153 try:
1154 for x in BrokenIter(init_raises=True):
1155 pass
1156 except Exception as e:
1157 return e
1158
1159 def next_raises():
1160 try:
1161 for x in BrokenIter(next_raises=True):
1162 pass
1163 except Exception as e:
1164 return e
1165
1166 def iter_raises():
1167 try:
1168 for x in BrokenIter(iter_raises=True):
1169 pass
1170 except Exception as e:
1171 return e
1172
1173 for func, expected in [(init_raises, "BrokenIter(init_raises=True)"),
1174 (next_raises, "BrokenIter(next_raises=True)"),
1175 (iter_raises, "BrokenIter(iter_raises=True)"),
1176 ]:
1177 with self.subTest(func):
1178 exc = func()
1179 f = traceback.extract_tb(exc.__traceback__)[0]
1180 indent = 16
1181 co = func.__code__
1182 self.assertEqual(f.lineno, co.co_firstlineno + 2)
1183 self.assertEqual(f.end_lineno, co.co_firstlineno + 2)
1184 self.assertEqual(f.line[f.colno - indent : f.end_colno - indent],
1185 expected)
1186
1187
1188

Callers

nothing calls this directly

Calls 3

subTestMethod · 0.95
assertEqualMethod · 0.95
funcFunction · 0.70

Tested by

no test coverage detected