-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_test_py3_cases.py
More file actions
26 lines (21 loc) · 813 Bytes
/
_test_py3_cases.py
File metadata and controls
26 lines (21 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def test_async_frequency():
# for python3.6+ only
from asyncio import ensure_future, get_event_loop
from time import time
from frequency_controller import AsyncFrequency
async def test_async():
frequency = AsyncFrequency(2, 1)
async def task():
async with frequency:
return time()
now = time()
tasks = [ensure_future(task()) for _ in range(5)]
result = [await task for task in tasks]
assert result[0] - now < 1
assert result[1] - now < 1
assert result[2] - now > 1
assert result[3] - now > 1
assert result[4] - now > 2
assert frequency.to_dict() == {'n': 2, 'interval': 1}
assert frequency.to_list() == [2, 1]
get_event_loop().run_until_complete(test_async())