Skip to content

Commit cf43b7c

Browse files
Add test for running function which takes no parameters with Scheduler
1 parent 4e65ec2 commit cf43b7c

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

test/test_scheduler.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@
2727

2828
from scheduler.Scheduler import Scheduler
2929
from scheduler.Task import Task
30-
from test.utils import _long_task, _get_input_output, assert_results, _func, _funcq
30+
from test.utils import (
31+
_long_task,
32+
_get_input_output,
33+
assert_results,
34+
_func,
35+
_funcq,
36+
_func_no_params,
37+
)
3138

3239

3340
def test_add_process():
@@ -61,6 +68,23 @@ def test_add():
6168
assert scheduler.finished
6269

6370

71+
def test_run_no_params():
72+
"""Tests whether `run()` works correctly on a function with no parameters."""
73+
scheduler = Scheduler()
74+
75+
expected = _func_no_params()
76+
for a in range(50):
77+
scheduler.add(target=_func_no_params)
78+
79+
loop = asyncio.get_event_loop()
80+
results: List = loop.run_until_complete(scheduler.run())
81+
82+
for r in results:
83+
assert r == expected
84+
85+
assert scheduler.finished
86+
87+
6488
def test_multiprocess():
6589
"""Tests whether `add()` works correctly with `multiprocess` instead of `multiprocessing`."""
6690
scheduler = Scheduler()
@@ -97,15 +121,16 @@ def test_run_blocking():
97121

98122

99123
def test_run_async():
124+
"""Tests whether `run()` works correctly."""
100125
scheduler = Scheduler()
101126

102127
args, expected = _get_input_output()
103128
for a in args:
104129
scheduler.add(target=_func, args=a)
105130

106131
loop = asyncio.get_event_loop()
107-
108132
results: List[Tuple[int, int, int]] = loop.run_until_complete(scheduler.run())
133+
109134
assert_results(expected, results)
110135

111136
assert scheduler.finished

test/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def assert_results(expected, results):
5555
assert expected[i] != results[i + 1]
5656

5757

58+
def _func_no_params() -> float:
59+
return 3.1415
60+
61+
5862
def _func(x, y, z) -> Tuple:
5963
return x ** 2, y ** 3, z ** 4
6064

0 commit comments

Comments
 (0)