[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Commit a missing file
commit dc6a98c30566184eb60cfccfca7fca5ca494869d
Author: Illia Volochii <illia.volochii@xxxxxxxxx>
Date: Mon Apr 27 19:18:24 2020 +0300
Commit a missing file
---
test/unit/async_util.py | 26 ++++++++++++++++++++++++++
test/unit/connection/authentication.py | 2 +-
test/unit/connection/connect.py | 2 +-
test/unit/control/controller.py | 2 +-
4 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/test/unit/async_util.py b/test/unit/async_util.py
new file mode 100644
index 00000000..aa8a6dd0
--- /dev/null
+++ b/test/unit/async_util.py
@@ -0,0 +1,26 @@
+import asyncio
+import functools
+
+
+def async_test(func):
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ loop = asyncio.new_event_loop()
+ try:
+ result = loop.run_until_complete(func(*args, **kwargs))
+ finally:
+ loop.close()
+ return result
+ return wrapper
+
+
+def coro_func_returning_value(return_value):
+ async def coroutine_func(*args, **kwargs):
+ return return_value
+ return coroutine_func
+
+
+def coro_func_raising_exc(exc):
+ async def coroutine_func(*args, **kwargs):
+ raise exc
+ return coroutine_func
diff --git a/test/unit/connection/authentication.py b/test/unit/connection/authentication.py
index 596fa50c..8df38c8f 100644
--- a/test/unit/connection/authentication.py
+++ b/test/unit/connection/authentication.py
@@ -18,7 +18,7 @@ from unittest.mock import patch
from stem.response import ControlMessage
from stem.util import log
-from test.unit.util.asynchronous import (
+from test.unit.async_util import (
async_test,
coro_func_raising_exc,
coro_func_returning_value,
diff --git a/test/unit/connection/connect.py b/test/unit/connection/connect.py
index d2a22f18..aa91736b 100644
--- a/test/unit/connection/connect.py
+++ b/test/unit/connection/connect.py
@@ -11,7 +11,7 @@ import stem.socket
from unittest.mock import Mock, patch
-from test.unit.util.asynchronous import coro_func_raising_exc, coro_func_returning_value
+from test.unit.async_util import coro_func_raising_exc, coro_func_returning_value
class TestConnect(unittest.TestCase):
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index d09b5ca8..99bd5f19 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -21,7 +21,7 @@ from stem import ControllerError, DescriptorUnavailable, InvalidArguments, Inval
from stem.control import MALFORMED_EVENTS, _parse_circ_path, Listener, Controller, EventType
from stem.response import ControlMessage
from stem.exit_policy import ExitPolicy
-from test.unit.util.asynchronous import (
+from test.unit.async_util import (
async_test,
coro_func_raising_exc,
coro_func_returning_value,
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits