-
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.
- Loading branch information
Showing
12 changed files
with
248 additions
and
261 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
Final, | ||
Iterable, | ||
List, | ||
Optional, | ||
Tuple, | ||
Union, | ||
) | ||
|
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,50 +1,51 @@ | ||
import asyncio | ||
import unittest | ||
|
||
from eventkit import Event | ||
|
||
array = list(range(10)) | ||
|
||
|
||
class TestAggregate: | ||
async def test_min(self): | ||
res = await Event.sequence(array).min().list() | ||
assert res == [0] * 10 | ||
class AggregateTest(unittest.TestCase): | ||
def test_min(self): | ||
event = Event.sequence(array).min() | ||
self.assertEqual(event.run(), [0] * 10) | ||
|
||
async def test_max(self): | ||
res = await Event.sequence(array).max().list() | ||
assert res == array | ||
def test_max(self): | ||
event = Event.sequence(array).max() | ||
self.assertEqual(event.run(), array) | ||
|
||
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_sum(self): | ||
event = Event.sequence(array).sum() | ||
self.assertEqual(event.run(), [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]) | ||
|
||
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_product(self): | ||
event = Event.sequence(array[1:]).product() | ||
self.assertEqual(event.run(), [1, 2, 6, 24, 120, 720, 5040, 40320, 362880]) | ||
|
||
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_any(self): | ||
event = Event.sequence(array).any() | ||
self.assertEqual( | ||
event.run(), [False, True, True, True, True, True, True, True, True, True] | ||
) | ||
|
||
async def test_all(self): | ||
def test_all(self): | ||
x = [True] * 10 + [False] * 10 | ||
res = await Event.sequence(x).all().list() | ||
assert res == x | ||
event = Event.sequence(x).all() | ||
self.assertEqual(event.run(), x) | ||
|
||
async def test_pairwaise(self): | ||
res = await Event.sequence(array).pairwise().list() | ||
assert res == list(zip(array, array[1:])) | ||
def test_pairwaise(self): | ||
event = Event.sequence(array).pairwise() | ||
self.assertEqual(event.run(), list(zip(array, array[1:]))) | ||
|
||
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_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_chunkwith(self): | ||
def test_chunkwith(self): | ||
timer = Event.timer(0.029, 10) | ||
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) | ||
event = Event.sequence(array, 0.01).chunkwith(timer) | ||
self.assertEqual(event.run(), [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]) | ||
|
||
async def test_array(self): | ||
res = await Event.sequence(array).array(5).last().list() | ||
assert list(res[0]) == array[-5:] | ||
def test_array(self): | ||
event = Event.sequence(array).array(5).last() | ||
self.assertEqual(list(event.run()[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,32 +1,31 @@ | ||
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 TestCreate: | ||
"""test create""" | ||
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]) | ||
|
||
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): | ||
def test_aiterate(self): | ||
async def ait(): | ||
await asyncio.sleep(0) | ||
for i in array1: | ||
yield i | ||
|
||
res = await Event.aiterate(ait()).list() | ||
assert res == array1 | ||
event = Event.aiterate(ait()) | ||
self.assertEqual(event.run(), array1) | ||
|
||
async def test_marble(self): | ||
def test_marble(self): | ||
s = " a b c d e f" | ||
res = await Event.marble(s, interval=0.001).list() | ||
assert res == [c for c in "abcdef"] | ||
event = Event.marble(s, interval=0.001) | ||
self.assertEqual(event.run(), [c for c in "abcdef"]) |
Oops, something went wrong.