Skip to content

Commit f49d20d

Browse files
authored
Update test_setcomps.py from 3.13.11 (#6425)
1 parent 9ccf4c1 commit f49d20d

File tree

1 file changed

+49
-16
lines changed

1 file changed

+49
-16
lines changed

Lib/test/test_setcomps.py

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import doctest
2+
import traceback
3+
import unittest
4+
5+
from test.support import BrokenIter
6+
7+
18
doctests = """
29
########### Tests mostly copied from test_listcomps.py ############
310
@@ -144,24 +151,50 @@
144151
145152
"""
146153

154+
class SetComprehensionTest(unittest.TestCase):
155+
@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: 'FrameSummary' object has no attribute 'end_lineno'
156+
def test_exception_locations(self):
157+
# The location of an exception raised from __init__ or
158+
# __next__ should should be the iterator expression
159+
160+
def init_raises():
161+
try:
162+
{x for x in BrokenIter(init_raises=True)}
163+
except Exception as e:
164+
return e
165+
166+
def next_raises():
167+
try:
168+
{x for x in BrokenIter(next_raises=True)}
169+
except Exception as e:
170+
return e
171+
172+
def iter_raises():
173+
try:
174+
{x for x in BrokenIter(iter_raises=True)}
175+
except Exception as e:
176+
return e
177+
178+
for func, expected in [(init_raises, "BrokenIter(init_raises=True)"),
179+
(next_raises, "BrokenIter(next_raises=True)"),
180+
(iter_raises, "BrokenIter(iter_raises=True)"),
181+
]:
182+
with self.subTest(func):
183+
exc = func()
184+
f = traceback.extract_tb(exc.__traceback__)[0]
185+
indent = 16
186+
co = func.__code__
187+
self.assertEqual(f.lineno, co.co_firstlineno + 2)
188+
self.assertEqual(f.end_lineno, co.co_firstlineno + 2)
189+
self.assertEqual(f.line[f.colno - indent : f.end_colno - indent],
190+
expected)
147191

148192
__test__ = {'doctests' : doctests}
149193

150-
def test_main(verbose=None):
151-
import sys
152-
from test import support
153-
from test import test_setcomps
154-
support.run_doctest(test_setcomps, verbose)
155-
156-
# verify reference counting
157-
if verbose and hasattr(sys, "gettotalrefcount"):
158-
import gc
159-
counts = [None] * 5
160-
for i in range(len(counts)):
161-
support.run_doctest(test_setcomps, verbose)
162-
gc.collect()
163-
counts[i] = sys.gettotalrefcount()
164-
print(counts)
194+
def load_tests(loader, tests, pattern):
195+
tests.addTest(doctest.DocTestSuite())
196+
return tests
197+
165198

166199
if __name__ == "__main__":
167-
test_main(verbose=True)
200+
unittest.main()

0 commit comments

Comments
 (0)