Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: fix race condition in output #17681

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions mypyc/test-data/run-generators.test
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def generator() -> Generator[int, None, Union[int, None]]:
yield 2
yield 3
except Exception as e:
print_tb(wrapsys.exc_info()[2])
print_tb(wrapsys.exc_info()[2], file=wrapsys.stdout)
s = str(e)
if s:
print('caught exception with value ' + s)
Expand Down Expand Up @@ -294,6 +294,7 @@ from typing import Any
import sys
def exc_info() -> Any:
return sys.exc_info() # type: ignore
stdout: Any = sys.stdout # type: ignore

[file driver.py]
import sys
Expand Down Expand Up @@ -348,24 +349,24 @@ with ctx_manager() as c:
[out]
File "native.py", line 10, in generator
yield 3
caught exception without value
File "native.py", line 9, in generator
yield 2
caught exception with value some string
File "native.py", line 8, in generator
yield 1
File "driver.py", line 31, in <module>
raise Exception
caught exception with value some other string
File "native.py", line 10, in generator
yield 3
File "native.py", line 31, in wrapper
return (yield from x)
caught exception without value
File "native.py", line 9, in generator
yield 2
File "native.py", line 31, in wrapper
return (yield from x)
caught exception without value
caught exception with value some string
caught exception with value some other string
caught exception without value
caught exception with value some string
exception
goodbye
Expand Down
49 changes: 7 additions & 42 deletions mypyc/test-data/run-loops.test
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def iterate_over_tuple(iterable: Tuple[int, int, int]) -> None:

[file driver.py]
from native import iterate_over_any, iterate_over_iterable, iterate_and_delete, sum_over_values, sum_over_even_values, sum_over_two_values, iterate_over_tuple
import traceback
import sys, traceback
def broken_generator(n):
num = 0
while num < n:
Expand All @@ -338,61 +338,35 @@ print(sum_over_two_values(d))
try:
iterate_over_any(5)
except TypeError:
traceback.print_exc()
traceback.print_exc(file=sys.stdout)
try:
iterate_over_iterable(broken_generator(5))
except Exception:
traceback.print_exc()
traceback.print_exc(file=sys.stdout)
try:
iterate_and_delete(d)
except RuntimeError:
traceback.print_exc()
traceback.print_exc(file=sys.stdout)

iterate_over_tuple((1, 2, 3))
[out]
15
6
3
Traceback (most recent call last):
File "driver.py", line 16, in <module>
iterate_over_any(5)
File "native.py", line 6, in iterate_over_any
for element in a:
TypeError: 'int' object is not iterable
Traceback (most recent call last):
File "driver.py", line 20, in <module>
iterate_over_iterable(broken_generator(5))
File "native.py", line 10, in iterate_over_iterable
for element in iterable:
File "driver.py", line 8, in broken_generator
raise Exception('Exception Manually Raised')
Exception: Exception Manually Raised
Traceback (most recent call last):
File "driver.py", line 24, in <module>
iterate_and_delete(d)
File "native.py", line 14, in iterate_and_delete
for key in d:
RuntimeError: dictionary changed size during iteration
15
6
3
0
1
2
3
4
1
2
3
[out version>=3.13]
Traceback (most recent call last):
File "driver.py", line 16, in <module>
iterate_over_any(5)
~~~~~~~~~~~~~~~~^^^
File "native.py", line 6, in iterate_over_any
for element in a:
TypeError: 'int' object is not iterable
Traceback (most recent call last):
File "driver.py", line 20, in <module>
iterate_over_iterable(broken_generator(5))
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
File "native.py", line 10, in iterate_over_iterable
for element in iterable:
File "driver.py", line 8, in broken_generator
Expand All @@ -401,18 +375,9 @@ Exception: Exception Manually Raised
Traceback (most recent call last):
File "driver.py", line 24, in <module>
iterate_and_delete(d)
~~~~~~~~~~~~~~~~~~^^^
File "native.py", line 14, in iterate_and_delete
for key in d:
RuntimeError: dictionary changed size during iteration
15
6
3
0
1
2
3
4
1
2
3
Expand Down
Loading