ez-a-sync 0.22.14__py3-none-any.whl → 0.22.15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ez-a-sync might be problematic. Click here for more details.
- a_sync/ENVIRONMENT_VARIABLES.py +4 -3
- a_sync/__init__.py +30 -12
- a_sync/_smart.py +132 -28
- a_sync/_typing.py +56 -12
- a_sync/a_sync/__init__.py +35 -10
- a_sync/a_sync/_descriptor.py +74 -26
- a_sync/a_sync/_flags.py +14 -6
- a_sync/a_sync/_helpers.py +8 -7
- a_sync/a_sync/_kwargs.py +3 -2
- a_sync/a_sync/_meta.py +120 -28
- a_sync/a_sync/abstract.py +102 -28
- a_sync/a_sync/base.py +34 -16
- a_sync/a_sync/config.py +47 -13
- a_sync/a_sync/decorator.py +239 -117
- a_sync/a_sync/function.py +416 -146
- a_sync/a_sync/method.py +197 -59
- a_sync/a_sync/modifiers/__init__.py +47 -5
- a_sync/a_sync/modifiers/cache/__init__.py +46 -17
- a_sync/a_sync/modifiers/cache/memory.py +86 -20
- a_sync/a_sync/modifiers/limiter.py +52 -22
- a_sync/a_sync/modifiers/manager.py +98 -16
- a_sync/a_sync/modifiers/semaphores.py +48 -15
- a_sync/a_sync/property.py +383 -82
- a_sync/a_sync/singleton.py +1 -0
- a_sync/aliases.py +0 -1
- a_sync/asyncio/__init__.py +4 -1
- a_sync/asyncio/as_completed.py +177 -49
- a_sync/asyncio/create_task.py +31 -17
- a_sync/asyncio/gather.py +72 -52
- a_sync/asyncio/utils.py +3 -3
- a_sync/exceptions.py +78 -23
- a_sync/executor.py +118 -71
- a_sync/future.py +575 -158
- a_sync/iter.py +110 -50
- a_sync/primitives/__init__.py +14 -2
- a_sync/primitives/_debug.py +13 -13
- a_sync/primitives/_loggable.py +5 -4
- a_sync/primitives/locks/__init__.py +5 -2
- a_sync/primitives/locks/counter.py +38 -36
- a_sync/primitives/locks/event.py +21 -7
- a_sync/primitives/locks/prio_semaphore.py +182 -62
- a_sync/primitives/locks/semaphore.py +78 -77
- a_sync/primitives/queue.py +560 -58
- a_sync/sphinx/__init__.py +0 -1
- a_sync/sphinx/ext.py +160 -50
- a_sync/task.py +262 -97
- a_sync/utils/__init__.py +12 -6
- a_sync/utils/iterators.py +127 -43
- {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.15.dist-info}/METADATA +1 -1
- ez_a_sync-0.22.15.dist-info/RECORD +74 -0
- {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.15.dist-info}/WHEEL +1 -1
- tests/conftest.py +1 -2
- tests/executor.py +112 -9
- tests/fixtures.py +61 -32
- tests/test_abstract.py +7 -4
- tests/test_as_completed.py +54 -21
- tests/test_base.py +66 -17
- tests/test_cache.py +31 -15
- tests/test_decorator.py +54 -28
- tests/test_executor.py +8 -13
- tests/test_future.py +45 -8
- tests/test_gather.py +8 -2
- tests/test_helpers.py +2 -0
- tests/test_iter.py +55 -13
- tests/test_limiter.py +5 -3
- tests/test_meta.py +23 -9
- tests/test_modified.py +4 -1
- tests/test_semaphore.py +15 -8
- tests/test_singleton.py +15 -10
- tests/test_task.py +126 -28
- ez_a_sync-0.22.14.dist-info/RECORD +0 -74
- {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.15.dist-info}/LICENSE.txt +0 -0
- {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.15.dist-info}/top_level.txt +0 -0
tests/test_cache.py
CHANGED
|
@@ -8,63 +8,79 @@ from tests.fixtures import _test_kwargs
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def test_decorator_async_with_cache_type():
|
|
11
|
-
@a_sync.a_sync(default=
|
|
11
|
+
@a_sync.a_sync(default="async", cache_type="memory")
|
|
12
12
|
async def some_test_fn() -> int:
|
|
13
13
|
return 2
|
|
14
|
+
|
|
14
15
|
start = time()
|
|
15
16
|
assert asyncio.get_event_loop().run_until_complete(some_test_fn()) == 2
|
|
16
17
|
assert asyncio.get_event_loop().run_until_complete(some_test_fn()) == 2
|
|
17
18
|
duration = time() - start
|
|
18
|
-
assert
|
|
19
|
-
|
|
19
|
+
assert (
|
|
20
|
+
duration < 1.5
|
|
21
|
+
), "There is a 1 second sleep in this function but it should only run once."
|
|
22
|
+
_test_kwargs(some_test_fn, "async")
|
|
23
|
+
|
|
20
24
|
|
|
21
25
|
def test_decorator_async_with_cache_maxsize():
|
|
22
|
-
@a_sync.a_sync(default=
|
|
26
|
+
@a_sync.a_sync(default="async", ram_cache_maxsize=100)
|
|
23
27
|
def some_test_fn() -> int:
|
|
24
28
|
sleep(1)
|
|
25
29
|
return 2
|
|
30
|
+
|
|
26
31
|
start = time()
|
|
27
32
|
assert asyncio.get_event_loop().run_until_complete(some_test_fn()) == 2
|
|
28
33
|
assert asyncio.get_event_loop().run_until_complete(some_test_fn()) == 2
|
|
29
34
|
duration = time() - start
|
|
30
|
-
assert
|
|
31
|
-
|
|
35
|
+
assert (
|
|
36
|
+
duration < 1.5
|
|
37
|
+
), "There is a 1 second sleep in this function but it should only run once."
|
|
38
|
+
_test_kwargs(some_test_fn, "async")
|
|
39
|
+
|
|
32
40
|
|
|
33
41
|
# This will never succeed due to some task the ttl kwargs creates
|
|
34
42
|
def test_decorator_async_with_cache_ttl():
|
|
35
|
-
@a_sync.a_sync(default=
|
|
43
|
+
@a_sync.a_sync(default="async", cache_type="memory", ram_cache_ttl=5)
|
|
36
44
|
async def some_test_fn() -> int:
|
|
37
45
|
return 2
|
|
46
|
+
|
|
38
47
|
assert asyncio.get_event_loop().run_until_complete(some_test_fn()) == 2
|
|
39
|
-
_test_kwargs(some_test_fn,
|
|
48
|
+
_test_kwargs(some_test_fn, "async")
|
|
40
49
|
|
|
41
50
|
|
|
42
51
|
def test_decorator_sync_with_cache_type():
|
|
43
52
|
# Fails
|
|
44
|
-
@a_sync.a_sync(default=
|
|
53
|
+
@a_sync.a_sync(default="sync", cache_type="memory")
|
|
45
54
|
async def some_test_fn() -> int:
|
|
46
55
|
sleep(1)
|
|
47
56
|
return 2
|
|
57
|
+
|
|
48
58
|
start = time()
|
|
49
59
|
assert some_test_fn() == 2
|
|
50
60
|
assert some_test_fn() == 2
|
|
51
61
|
assert some_test_fn() == 2
|
|
52
62
|
duration = time() - start
|
|
53
|
-
assert
|
|
54
|
-
|
|
63
|
+
assert (
|
|
64
|
+
duration < 1.5
|
|
65
|
+
), "There is a 1 second sleep in this function but it should only run once."
|
|
66
|
+
_test_kwargs(some_test_fn, "sync")
|
|
55
67
|
|
|
56
|
-
|
|
68
|
+
|
|
69
|
+
@pytest.mark.skipif(True, reason="skipped manually")
|
|
57
70
|
def test_decorator_sync_with_cache_maxsize():
|
|
58
71
|
# Fails
|
|
59
72
|
# TODO diagnose and fix
|
|
60
|
-
@a_sync.a_sync(default="sync", cache_type=
|
|
73
|
+
@a_sync.a_sync(default="sync", cache_type="memory")
|
|
61
74
|
def some_test_fn() -> int:
|
|
62
75
|
sleep(1)
|
|
63
76
|
return 2
|
|
77
|
+
|
|
64
78
|
start = time()
|
|
65
79
|
assert some_test_fn() == 2
|
|
66
80
|
assert some_test_fn() == 2
|
|
67
81
|
assert some_test_fn() == 2
|
|
68
82
|
duration = time() - start
|
|
69
|
-
assert
|
|
70
|
-
|
|
83
|
+
assert (
|
|
84
|
+
duration < 1.5
|
|
85
|
+
), "There is a 1 second sleep in this function but it should only run once."
|
|
86
|
+
_test_kwargs(some_test_fn, "sync")
|
tests/test_decorator.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import asyncio
|
|
3
2
|
import pytest
|
|
4
3
|
|
|
@@ -6,66 +5,79 @@ import a_sync
|
|
|
6
5
|
from tests.fixtures import _test_kwargs
|
|
7
6
|
|
|
8
7
|
|
|
9
|
-
|
|
10
8
|
# ASYNC DEF
|
|
11
9
|
def test_decorator_no_args():
|
|
12
10
|
@a_sync.a_sync
|
|
13
11
|
async def some_test_fn() -> int:
|
|
14
12
|
return 2
|
|
13
|
+
|
|
15
14
|
assert asyncio.get_event_loop().run_until_complete(some_test_fn()) == 2
|
|
16
15
|
_test_kwargs(some_test_fn, None)
|
|
17
|
-
|
|
16
|
+
|
|
18
17
|
@a_sync.a_sync()
|
|
19
18
|
async def some_test_fn() -> int:
|
|
20
19
|
return 2
|
|
20
|
+
|
|
21
21
|
assert asyncio.get_event_loop().run_until_complete(some_test_fn()) == 2
|
|
22
22
|
_test_kwargs(some_test_fn, None)
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
|
|
24
25
|
def test_decorator_default_none_arg():
|
|
25
26
|
@a_sync.a_sync(None)
|
|
26
27
|
async def some_test_fn() -> int:
|
|
27
28
|
return 2
|
|
29
|
+
|
|
28
30
|
assert asyncio.get_event_loop().run_until_complete(some_test_fn()) == 2
|
|
29
31
|
_test_kwargs(some_test_fn, None)
|
|
30
|
-
|
|
32
|
+
|
|
33
|
+
|
|
31
34
|
def test_decorator_default_none_kwarg():
|
|
32
35
|
@a_sync.a_sync(default=None)
|
|
33
36
|
async def some_test_fn() -> int:
|
|
34
37
|
return 2
|
|
38
|
+
|
|
35
39
|
assert asyncio.get_event_loop().run_until_complete(some_test_fn()) == 2
|
|
36
40
|
_test_kwargs(some_test_fn, None)
|
|
37
41
|
|
|
42
|
+
|
|
38
43
|
def test_decorator_default_sync_arg():
|
|
39
|
-
@a_sync.a_sync(
|
|
44
|
+
@a_sync.a_sync("sync")
|
|
40
45
|
async def some_test_fn() -> int:
|
|
41
46
|
return 2
|
|
47
|
+
|
|
42
48
|
with pytest.raises(TypeError):
|
|
43
49
|
asyncio.get_event_loop().run_until_complete(some_test_fn())
|
|
44
50
|
assert some_test_fn() == 2
|
|
45
|
-
_test_kwargs(some_test_fn,
|
|
51
|
+
_test_kwargs(some_test_fn, "sync")
|
|
52
|
+
|
|
46
53
|
|
|
47
54
|
def test_decorator_default_sync_kwarg():
|
|
48
|
-
@a_sync.a_sync(default=
|
|
55
|
+
@a_sync.a_sync(default="sync")
|
|
49
56
|
async def some_test_fn() -> int:
|
|
50
57
|
return 2
|
|
58
|
+
|
|
51
59
|
with pytest.raises(TypeError):
|
|
52
60
|
asyncio.get_event_loop().run_until_complete(some_test_fn())
|
|
53
61
|
assert some_test_fn() == 2
|
|
54
|
-
_test_kwargs(some_test_fn,
|
|
55
|
-
|
|
62
|
+
_test_kwargs(some_test_fn, "sync")
|
|
63
|
+
|
|
64
|
+
|
|
56
65
|
def test_decorator_default_async_arg():
|
|
57
|
-
@a_sync.a_sync(
|
|
66
|
+
@a_sync.a_sync("async")
|
|
58
67
|
async def some_test_fn() -> int:
|
|
59
68
|
return 2
|
|
69
|
+
|
|
60
70
|
assert asyncio.get_event_loop().run_until_complete(some_test_fn()) == 2
|
|
61
|
-
_test_kwargs(some_test_fn,
|
|
62
|
-
|
|
71
|
+
_test_kwargs(some_test_fn, "async")
|
|
72
|
+
|
|
73
|
+
|
|
63
74
|
def test_decorator_default_async_kwarg():
|
|
64
|
-
@a_sync.a_sync(default=
|
|
75
|
+
@a_sync.a_sync(default="async")
|
|
65
76
|
async def some_test_fn() -> int:
|
|
66
77
|
return 2
|
|
78
|
+
|
|
67
79
|
assert asyncio.get_event_loop().run_until_complete(some_test_fn()) == 2
|
|
68
|
-
_test_kwargs(some_test_fn,
|
|
80
|
+
_test_kwargs(some_test_fn, "async")
|
|
69
81
|
|
|
70
82
|
|
|
71
83
|
# SYNC DEF
|
|
@@ -73,53 +85,67 @@ def test_sync_decorator_no_args():
|
|
|
73
85
|
@a_sync.a_sync
|
|
74
86
|
def some_test_fn() -> int:
|
|
75
87
|
return 2
|
|
88
|
+
|
|
76
89
|
assert some_test_fn() == 2
|
|
77
90
|
_test_kwargs(some_test_fn, None)
|
|
78
|
-
|
|
91
|
+
|
|
79
92
|
@a_sync.a_sync()
|
|
80
93
|
def some_test_fn() -> int:
|
|
81
94
|
return 2
|
|
95
|
+
|
|
82
96
|
assert some_test_fn() == 2
|
|
83
97
|
_test_kwargs(some_test_fn, None)
|
|
84
|
-
|
|
98
|
+
|
|
99
|
+
|
|
85
100
|
def test_sync_decorator_default_none_arg():
|
|
86
101
|
@a_sync.a_sync(None)
|
|
87
102
|
def some_test_fn() -> int:
|
|
88
103
|
return 2
|
|
104
|
+
|
|
89
105
|
assert some_test_fn() == 2
|
|
90
106
|
_test_kwargs(some_test_fn, None)
|
|
91
|
-
|
|
107
|
+
|
|
108
|
+
|
|
92
109
|
def test_sync_decorator_default_none_kwarg():
|
|
93
110
|
@a_sync.a_sync(default=None)
|
|
94
111
|
def some_test_fn() -> int:
|
|
95
112
|
return 2
|
|
113
|
+
|
|
96
114
|
assert some_test_fn() == 2
|
|
97
115
|
_test_kwargs(some_test_fn, None)
|
|
98
116
|
|
|
117
|
+
|
|
99
118
|
def test_sync_decorator_default_sync_arg():
|
|
100
|
-
@a_sync.a_sync(
|
|
119
|
+
@a_sync.a_sync("sync")
|
|
101
120
|
def some_test_fn() -> int:
|
|
102
121
|
return 2
|
|
122
|
+
|
|
103
123
|
assert some_test_fn() == 2
|
|
104
|
-
_test_kwargs(some_test_fn,
|
|
124
|
+
_test_kwargs(some_test_fn, "sync")
|
|
125
|
+
|
|
105
126
|
|
|
106
127
|
def test_sync_decorator_default_sync_kwarg():
|
|
107
|
-
@a_sync.a_sync(default=
|
|
128
|
+
@a_sync.a_sync(default="sync")
|
|
108
129
|
def some_test_fn() -> int:
|
|
109
130
|
return 2
|
|
131
|
+
|
|
110
132
|
assert some_test_fn() == 2
|
|
111
|
-
_test_kwargs(some_test_fn,
|
|
112
|
-
|
|
133
|
+
_test_kwargs(some_test_fn, "sync")
|
|
134
|
+
|
|
135
|
+
|
|
113
136
|
def test_sync_decorator_default_async_arg():
|
|
114
|
-
@a_sync.a_sync(
|
|
137
|
+
@a_sync.a_sync("async")
|
|
115
138
|
def some_test_fn() -> int:
|
|
116
139
|
return 2
|
|
140
|
+
|
|
117
141
|
assert asyncio.get_event_loop().run_until_complete(some_test_fn()) == 2
|
|
118
|
-
_test_kwargs(some_test_fn,
|
|
119
|
-
|
|
142
|
+
_test_kwargs(some_test_fn, "async")
|
|
143
|
+
|
|
144
|
+
|
|
120
145
|
def test_sync_decorator_default_async_kwarg():
|
|
121
|
-
@a_sync.a_sync(default=
|
|
146
|
+
@a_sync.a_sync(default="async")
|
|
122
147
|
def some_test_fn() -> int:
|
|
123
148
|
return 2
|
|
149
|
+
|
|
124
150
|
assert asyncio.get_event_loop().run_until_complete(some_test_fn()) == 2
|
|
125
|
-
_test_kwargs(some_test_fn,
|
|
151
|
+
_test_kwargs(some_test_fn, "async")
|
tests/test_executor.py
CHANGED
|
@@ -3,15 +3,15 @@ import time
|
|
|
3
3
|
|
|
4
4
|
import pytest
|
|
5
5
|
|
|
6
|
-
from a_sync.executor import
|
|
7
|
-
ProcessPoolExecutor)
|
|
6
|
+
from a_sync.executor import AsyncProcessPoolExecutor, ProcessPoolExecutor
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
def do_work(i, kwarg=None):
|
|
11
10
|
time.sleep(i)
|
|
12
11
|
if kwarg:
|
|
13
12
|
assert kwarg == i
|
|
14
|
-
|
|
13
|
+
|
|
14
|
+
|
|
15
15
|
def test_executor():
|
|
16
16
|
executor = ProcessPoolExecutor(1)
|
|
17
17
|
assert isinstance(executor, AsyncProcessPoolExecutor)
|
|
@@ -21,20 +21,15 @@ def test_executor():
|
|
|
21
21
|
fut = executor.submit(do_work, 3)
|
|
22
22
|
assert isinstance(fut, asyncio.Future), fut.__dict__
|
|
23
23
|
asyncio.get_event_loop().run_until_complete(fut)
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
# asyncio implementation cant handle kwargs :(
|
|
26
26
|
with pytest.raises(TypeError):
|
|
27
27
|
asyncio.get_event_loop().run_until_complete(
|
|
28
28
|
asyncio.get_event_loop().run_in_executor(executor, do_work, 3, kwarg=3)
|
|
29
29
|
)
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
# but our clean implementation can :)
|
|
32
32
|
fut = executor.submit(do_work, 3, kwarg=3)
|
|
33
|
-
|
|
34
|
-
asyncio.get_event_loop().run_until_complete(
|
|
35
|
-
|
|
36
|
-
)
|
|
37
|
-
asyncio.get_event_loop().run_until_complete(
|
|
38
|
-
fut
|
|
39
|
-
)
|
|
40
|
-
|
|
33
|
+
|
|
34
|
+
asyncio.get_event_loop().run_until_complete(executor.run(do_work, 3, kwarg=3))
|
|
35
|
+
asyncio.get_event_loop().run_until_complete(fut)
|
tests/test_future.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
from a_sync.future import ASyncFuture
|
|
3
2
|
|
|
4
3
|
|
|
@@ -8,90 +7,129 @@ class StuffDoer:
|
|
|
8
7
|
raise ValueError
|
|
9
8
|
return 1
|
|
10
9
|
|
|
10
|
+
|
|
11
11
|
async def dct():
|
|
12
|
-
return {1:2}
|
|
12
|
+
return {1: 2}
|
|
13
|
+
|
|
13
14
|
|
|
14
15
|
async def one() -> int:
|
|
15
16
|
return 1
|
|
16
17
|
|
|
18
|
+
|
|
17
19
|
async def two() -> int:
|
|
18
20
|
return 2
|
|
19
21
|
|
|
22
|
+
|
|
20
23
|
async def zero():
|
|
21
24
|
return 0
|
|
22
25
|
|
|
26
|
+
|
|
23
27
|
def test_result():
|
|
24
28
|
assert ASyncFuture(one()).result() == 1
|
|
29
|
+
|
|
30
|
+
|
|
25
31
|
def test_add():
|
|
26
32
|
assert ASyncFuture(one()) + ASyncFuture(two()) == 3
|
|
27
33
|
assert ASyncFuture(one()) + 2 == 3
|
|
28
34
|
assert 1 + ASyncFuture(two()) == 3
|
|
35
|
+
|
|
36
|
+
|
|
29
37
|
def test_sum():
|
|
30
38
|
assert sum([ASyncFuture(one()), ASyncFuture(two())]) == 3
|
|
31
39
|
assert sum([ASyncFuture(one()), 2]) == 3
|
|
32
40
|
assert sum([1, ASyncFuture(two())]) == 3
|
|
41
|
+
|
|
42
|
+
|
|
33
43
|
def test_sub():
|
|
34
44
|
assert ASyncFuture(one()) - ASyncFuture(two()) == -1
|
|
35
45
|
assert ASyncFuture(one()) - 2 == -1
|
|
36
46
|
assert 1 - ASyncFuture(two()) == -1
|
|
47
|
+
|
|
48
|
+
|
|
37
49
|
def test_mul():
|
|
38
50
|
assert ASyncFuture(one()) * ASyncFuture(two()) == 2
|
|
39
51
|
assert ASyncFuture(one()) * 2 == 2
|
|
40
52
|
assert 1 * ASyncFuture(two()) == 2
|
|
53
|
+
|
|
54
|
+
|
|
41
55
|
def test_pow():
|
|
42
56
|
assert ASyncFuture(two()) ** ASyncFuture(two()) == 4
|
|
43
57
|
assert ASyncFuture(two()) ** 2 == 4
|
|
44
58
|
assert 2 ** ASyncFuture(two()) == 4
|
|
59
|
+
|
|
60
|
+
|
|
45
61
|
def test_realdiv():
|
|
46
62
|
assert ASyncFuture(one()) / ASyncFuture(two()) == 0.5
|
|
47
63
|
assert ASyncFuture(one()) / 2 == 0.5
|
|
48
64
|
assert 1 / ASyncFuture(two()) == 0.5
|
|
65
|
+
|
|
66
|
+
|
|
49
67
|
def test_floordiv():
|
|
50
68
|
assert ASyncFuture(one()) // ASyncFuture(two()) == 0
|
|
51
69
|
assert ASyncFuture(one()) // 2 == 0
|
|
52
70
|
assert 1 // ASyncFuture(two()) == 0
|
|
71
|
+
|
|
72
|
+
|
|
53
73
|
def test_gt():
|
|
54
74
|
assert not ASyncFuture(one()) > ASyncFuture(two())
|
|
55
75
|
assert ASyncFuture(two()) > ASyncFuture(one())
|
|
56
76
|
assert not ASyncFuture(one()) > ASyncFuture(one())
|
|
77
|
+
|
|
78
|
+
|
|
57
79
|
def test_gte():
|
|
58
80
|
assert not ASyncFuture(one()) >= ASyncFuture(two())
|
|
59
81
|
assert ASyncFuture(two()) >= ASyncFuture(one())
|
|
60
82
|
assert ASyncFuture(one()) >= ASyncFuture(one())
|
|
83
|
+
|
|
84
|
+
|
|
61
85
|
def test_lt():
|
|
62
86
|
assert ASyncFuture(one()) < ASyncFuture(two())
|
|
63
87
|
assert not ASyncFuture(two()) < ASyncFuture(one())
|
|
64
88
|
assert not ASyncFuture(one()) < ASyncFuture(one())
|
|
89
|
+
|
|
90
|
+
|
|
65
91
|
def test_lte():
|
|
66
92
|
assert ASyncFuture(one()) <= ASyncFuture(two())
|
|
67
93
|
assert not ASyncFuture(two()) <= ASyncFuture(one())
|
|
68
94
|
assert ASyncFuture(one()) <= ASyncFuture(one())
|
|
95
|
+
|
|
96
|
+
|
|
69
97
|
def test_bool():
|
|
70
98
|
assert bool(ASyncFuture(one())) == True
|
|
71
99
|
assert bool(ASyncFuture(zero())) == False
|
|
100
|
+
|
|
101
|
+
|
|
72
102
|
def test_float():
|
|
73
103
|
assert float(ASyncFuture(one())) == float(1)
|
|
104
|
+
|
|
105
|
+
|
|
74
106
|
def test_str():
|
|
75
107
|
assert str(ASyncFuture(one())) == "1"
|
|
76
108
|
|
|
109
|
+
|
|
77
110
|
def test_getitem():
|
|
78
111
|
assert ASyncFuture(dct())[1] == 2
|
|
79
112
|
|
|
113
|
+
|
|
80
114
|
# NOTE: does not work
|
|
81
115
|
def test_setitem():
|
|
82
116
|
meta = ASyncFuture(dct())
|
|
83
117
|
print(meta)
|
|
84
118
|
meta[3] = 4
|
|
85
|
-
assert meta == {1:2, 3:4}
|
|
119
|
+
assert meta == {1: 2, 3: 4}
|
|
86
120
|
assert meta[3] == 4
|
|
87
|
-
|
|
121
|
+
|
|
122
|
+
|
|
88
123
|
async def stuff_doer():
|
|
89
124
|
return StuffDoer()
|
|
90
125
|
|
|
126
|
+
|
|
91
127
|
def test_getattr():
|
|
92
128
|
assert ASyncFuture(stuff_doer()).do_stuff()
|
|
93
129
|
|
|
94
|
-
|
|
130
|
+
|
|
131
|
+
import pytest
|
|
132
|
+
|
|
95
133
|
|
|
96
134
|
def test_multi_maths():
|
|
97
135
|
some_cool_evm_value = ASyncFuture(two())
|
|
@@ -100,8 +138,8 @@ def test_multi_maths():
|
|
|
100
138
|
other = ASyncFuture(two())
|
|
101
139
|
stuff = ASyncFuture(two())
|
|
102
140
|
idrk = ASyncFuture(one())
|
|
103
|
-
output0 = some_cool_evm_value / scale
|
|
104
|
-
output1 = other + stuff - idrk
|
|
141
|
+
output0 = some_cool_evm_value / scale**some # 2
|
|
142
|
+
output1 = other + stuff - idrk # 3
|
|
105
143
|
output = output0 * output1
|
|
106
144
|
assert output0 < output1
|
|
107
145
|
assert not output0 > output1
|
|
@@ -113,4 +151,3 @@ def test_multi_maths():
|
|
|
113
151
|
assert output == 6
|
|
114
152
|
with pytest.raises(ValueError):
|
|
115
153
|
ASyncFuture(stuff_doer()).do_stuff(6)
|
|
116
|
-
|
tests/test_gather.py
CHANGED
|
@@ -10,32 +10,38 @@ async def sample_task(number):
|
|
|
10
10
|
await asyncio.sleep(0.1)
|
|
11
11
|
return number * 2
|
|
12
12
|
|
|
13
|
+
|
|
13
14
|
@pytest.mark.asyncio_cooperative
|
|
14
15
|
async def test_gather_with_awaitables():
|
|
15
16
|
results = await gather(sample_task(1), sample_task(2), sample_task(3))
|
|
16
17
|
assert results == [2, 4, 6]
|
|
17
18
|
|
|
19
|
+
|
|
18
20
|
@pytest.mark.asyncio_cooperative
|
|
19
21
|
async def test_gather_with_awaitables_and_tqdm():
|
|
20
22
|
results = await gather(sample_task(1), sample_task(2), sample_task(3), tqdm=True)
|
|
21
23
|
assert results == [2, 4, 6]
|
|
22
24
|
|
|
25
|
+
|
|
23
26
|
@pytest.mark.asyncio_cooperative
|
|
24
27
|
async def test_gather_with_mapping_and_tqdm():
|
|
25
|
-
tasks = {
|
|
28
|
+
tasks = {"a": sample_task(1), "b": sample_task(2), "c": sample_task(3)}
|
|
26
29
|
results = await gather(tasks, tqdm=True)
|
|
27
|
-
assert results == {
|
|
30
|
+
assert results == {"a": 2, "b": 4, "c": 6}
|
|
31
|
+
|
|
28
32
|
|
|
29
33
|
@pytest.mark.asyncio_cooperative
|
|
30
34
|
async def test_gather_with_exceptions():
|
|
31
35
|
with pytest.raises(ValueError):
|
|
32
36
|
await gather(sample_exc(None))
|
|
33
37
|
|
|
38
|
+
|
|
34
39
|
@pytest.mark.asyncio_cooperative
|
|
35
40
|
async def test_gather_with_return_exceptions():
|
|
36
41
|
results = await gather(sample_exc(None), return_exceptions=True)
|
|
37
42
|
assert isinstance(results[0], ValueError)
|
|
38
43
|
|
|
44
|
+
|
|
39
45
|
@pytest.mark.asyncio_cooperative
|
|
40
46
|
async def test_gather_with_return_exceptions_and_tqdm():
|
|
41
47
|
results = await gather(sample_exc(None), return_exceptions=True, tqdm=True)
|
tests/test_helpers.py
CHANGED
|
@@ -6,8 +6,10 @@ from a_sync.asyncio import get_event_loop
|
|
|
6
6
|
def test_get_event_loop():
|
|
7
7
|
assert get_event_loop() == asyncio.get_event_loop()
|
|
8
8
|
|
|
9
|
+
|
|
9
10
|
def test_get_event_loop_in_thread():
|
|
10
11
|
def task():
|
|
11
12
|
assert get_event_loop() == asyncio.get_event_loop()
|
|
13
|
+
|
|
12
14
|
loop = get_event_loop()
|
|
13
15
|
loop.run_until_complete(loop.run_in_executor(None, task))
|