-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- functools.cache is out - pytest-async plugin in - I had to rewrite all tests so they don't use unittest, so now all test are on pytest - All test pass, except when they are run with pytest-xdist, poetry run pytest -vs -n auto gives a warning. It's a warning, not an error > task: <Task pending name='Task-18' coro=<Aiterate._looper() done, defined at ~/Documents/dev/eventkit/eventkit/ops/create.py:42> wait_for=> - updated Event.repeat, as the parameters where in the wrong position. it should be Ok now. - update Aiterate and Wait to use tasks. removed __del__ method from Aiterate as it causes warnings. we can put it back and live with warnings on tests, which is not bad. - right now everything is task based, except timing module which uses loop.call_soon and loop.call_at
- Loading branch information
Showing
11 changed files
with
254 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,50 @@ | ||
import unittest | ||
import asyncio | ||
|
||
from eventkit import Event | ||
|
||
array = list(range(10)) | ||
|
||
|
||
class AggregateTest(unittest.TestCase): | ||
def test_min(self): | ||
event = Event.sequence(array).min() | ||
self.assertEqual(event.run(), [0] * 10) | ||
class TestAggregate: | ||
async def test_min(self): | ||
res = await Event.sequence(array).min().list() | ||
assert res == [0] * 10 | ||
|
||
def test_max(self): | ||
event = Event.sequence(array).max() | ||
self.assertEqual(event.run(), array) | ||
async def test_max(self): | ||
res = await Event.sequence(array).max().list() | ||
assert res == array | ||
|
||
def test_sum(self): | ||
event = Event.sequence(array).sum() | ||
self.assertEqual(event.run(), [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]) | ||
async def test_sum(self): | ||
res = await Event.sequence(array).sum().list() | ||
assert res == [0, 1, 3, 6, 10, 15, 21, 28, 36, 45] | ||
|
||
def test_product(self): | ||
event = Event.sequence(array[1:]).product() | ||
self.assertEqual(event.run(), [1, 2, 6, 24, 120, 720, 5040, 40320, 362880]) | ||
async def test_product(self): | ||
res = await Event.sequence(array[1:]).product().list() | ||
assert res == [1, 2, 6, 24, 120, 720, 5040, 40320, 362880] | ||
|
||
def test_any(self): | ||
event = Event.sequence(array).any() | ||
self.assertEqual( | ||
event.run(), [False, True, True, True, True, True, True, True, True, True] | ||
) | ||
async def test_any(self): | ||
res = await Event.sequence(array).any().list() | ||
assert res == [False, True, True, True, True, True, True, True, True, True] | ||
|
||
def test_all(self): | ||
async def test_all(self): | ||
x = [True] * 10 + [False] * 10 | ||
event = Event.sequence(x).all() | ||
self.assertEqual(event.run(), x) | ||
res = await Event.sequence(x).all().list() | ||
assert res == x | ||
|
||
def test_pairwaise(self): | ||
event = Event.sequence(array).pairwise() | ||
self.assertEqual(event.run(), list(zip(array, array[1:]))) | ||
async def test_pairwaise(self): | ||
res = await Event.sequence(array).pairwise().list() | ||
assert res == list(zip(array, array[1:])) | ||
|
||
def test_chunk(self): | ||
event = Event.sequence(array).chunk(3) | ||
self.assertEqual(event.run(), [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]) | ||
async def test_chunk(self): | ||
res = await Event.sequence(array).chunk(3).list() | ||
assert res == [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]] | ||
|
||
def test_chunkwith(self): | ||
async def test_chunkwith(self): | ||
timer = Event.timer(0.029, 10) | ||
event = Event.sequence(array, 0.01).chunkwith(timer) | ||
self.assertEqual(event.run(), [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]) | ||
res = await Event.sequence(array, 0.01).chunkwith(timer).list() | ||
assert res == [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]] | ||
await asyncio.sleep(0.5) | ||
|
||
def test_array(self): | ||
event = Event.sequence(array).array(5).last() | ||
self.assertEqual(list(event.run()[0]), array[-5:]) | ||
async def test_array(self): | ||
res = await Event.sequence(array).array(5).last().list() | ||
assert list(res[0]) == array[-5:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
import asyncio | ||
import unittest | ||
|
||
from eventkit import Event | ||
from eventkit.util import get_event_loop | ||
|
||
array1 = list(range(10)) | ||
array2 = list(range(100, 110)) | ||
|
||
|
||
class CreateTest(unittest.TestCase): | ||
def test_wait(self): | ||
loop = get_event_loop() | ||
fut = asyncio.Future(loop=loop) | ||
loop.call_later(0.001, fut.set_result, 42) | ||
event = Event.wait(fut) | ||
self.assertEqual(event.run(), [42]) | ||
class TestCreate: | ||
"""test create""" | ||
|
||
def test_aiterate(self): | ||
async def test_wait(self): | ||
async def coro(): | ||
await asyncio.sleep(0) | ||
return 42 | ||
|
||
res = await Event.wait(coro()) | ||
assert res == 42 | ||
|
||
async def test_aiterate(self): | ||
async def ait(): | ||
await asyncio.sleep(0) | ||
for i in array1: | ||
yield i | ||
|
||
event = Event.aiterate(ait()) | ||
self.assertEqual(event.run(), array1) | ||
res = await Event.aiterate(ait()).list() | ||
assert res == array1 | ||
|
||
def test_marble(self): | ||
async def test_marble(self): | ||
s = " a b c d e f" | ||
event = Event.marble(s, interval=0.001) | ||
self.assertEqual(event.run(), [c for c in "abcdef"]) | ||
res = await Event.marble(s, interval=0.001).list() | ||
assert res == [c for c in "abcdef"] |
Oops, something went wrong.