Refactor coroutine provider tests

This commit is contained in:
Roman Mogylatov 2018-10-16 17:56:15 +03:00
parent 06526d9457
commit 891e356197

View File

@ -1,9 +1,6 @@
"""Dependency injector coroutine providers unit tests."""
try:
import asyncio
except ImportError:
asyncio = None
import asyncio
import unittest2 as unittest
@ -13,24 +10,21 @@ from dependency_injector import (
)
if asyncio:
@asyncio.coroutine
def _example(arg1, arg2, arg3, arg4):
@asyncio.coroutine
def _example(arg1, arg2, arg3, arg4):
future = asyncio.Future()
future.set_result(None)
yield from future
return arg1, arg2, arg3, arg4
def _run(coro):
def _run(coro):
loop = asyncio.get_event_loop()
return loop.run_until_complete(coro)
else:
_example = None
class CoroutineTests(unittest.TestCase):
if asyncio:
def test_init_with_coroutine(self):
self.assertTrue(providers.Coroutine(_example))
@ -197,7 +191,6 @@ class CoroutineTests(unittest.TestCase):
class DelegatedCoroutineTests(unittest.TestCase):
if asyncio:
def test_inheritance(self):
self.assertIsInstance(providers.DelegatedCoroutine(_example),
providers.Coroutine)
@ -222,7 +215,6 @@ class DelegatedCoroutineTests(unittest.TestCase):
class AbstractCoroutineTests(unittest.TestCase):
if asyncio:
def test_inheritance(self):
self.assertIsInstance(providers.AbstractCoroutine(_example),
providers.Coroutine)
@ -277,7 +269,6 @@ class AbstractCoroutineTests(unittest.TestCase):
class CoroutineDelegateTests(unittest.TestCase):
if asyncio:
def setUp(self):
self.delegated = providers.Coroutine(_example)
self.delegate = providers.CoroutineDelegate(self.delegated)