Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 03ae245

Browse files
committedMar 16, 2023
closes #176
1 parent ef95434 commit 03ae245

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed
 

‎Loops/Fix infinite execution/task-info.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ files:
1414
visible: false
1515
- name: stop_run.png
1616
visible: false
17+
- name: tests/decorated_test_function.py
18+
visible: false
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import wrapt_timeout_decorator
2+
import contextlib
3+
import io
4+
5+
from infinite import should_not_be_infinite
6+
7+
timeoutlimit = 5
8+
9+
10+
@wrapt_timeout_decorator.timeout(timeoutlimit)
11+
def test_that_can_take_too_long():
12+
f = io.StringIO()
13+
with contextlib.redirect_stdout(f):
14+
should_not_be_infinite()
15+
output = f.getvalue().split('\n')
16+
try:
17+
if ['Hello, World!', 'Hello, World!', 'Hello, World!', 'Hello, World!', 'Hello, World!', ''] == output:
18+
return
19+
else:
20+
raise AssertionError
21+
except AssertionError as e:
22+
return str(e)
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import unittest
2-
import contextlib
3-
import io
2+
from tests.decorated_test_function import test_that_can_take_too_long
43

5-
import wrapt_timeout_decorator
6-
7-
from infinite import should_not_be_infinite
8-
9-
10-
class TestCaseWithTimeouts(unittest.TestCase):
11-
@wrapt_timeout_decorator.timeout(2)
12-
def test_that_can_take_too_long(self):
13-
f = io.StringIO()
14-
with contextlib.redirect_stdout(f):
15-
should_not_be_infinite()
16-
output = f.getvalue().split('\n')
17-
18-
self.assertEqual(['Hello, World!', 'Hello, World!', 'Hello, World!', 'Hello, World!', 'Hello, World!', ''], output)
4+
timeoutlimit = 5
195

206

7+
class TestCase(unittest.TestCase):
8+
def test_infinite(self):
9+
try:
10+
err = test_that_can_take_too_long()
11+
if err:
12+
self.fail(msg=err)
13+
except TimeoutError as e:
14+
self.fail(
15+
msg=f"TimeoutError after {timeoutlimit} seconds. Your method's execution does not seem to end in a "
16+
"reasonable amount of time.")

0 commit comments

Comments
 (0)
Please sign in to comment.