Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_create_autospec_on_coroutine_with_return_value(self):
mock = asynctest.mock.create_autospec(Test.a_coroutine,
return_value="PROBE")
self.assertEqual("PROBE", run_coroutine(mock(None)))
if _using_await:
mock = asynctest.mock.create_autospec(Test.an_async_coroutine,
return_value="PROBE")
self.assertEqual("PROBE", run_coroutine(mock(None)))
def test_autospec_of_coroutine_function_is_coroutinefunction(self):
mock = asynctest.mock.create_autospec(Test.a_function)
self.assertFalse(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_classmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_staticmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
if _using_await:
mock = asynctest.mock.create_autospec(Test.an_async_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.an_async_classmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.an_async_staticmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
def test_autospec_of_coroutine_function_is_coroutinefunction(self):
mock = asynctest.mock.create_autospec(Test.a_function)
self.assertFalse(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_classmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_staticmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
if _using_await:
mock = asynctest.mock.create_autospec(Test.an_async_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.an_async_classmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.an_async_staticmethod_coroutine)
def test_autospec_of_coroutine_function_is_coroutinefunction(self):
mock = asynctest.mock.create_autospec(Test.a_function)
self.assertFalse(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_classmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_staticmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
if _using_await:
mock = asynctest.mock.create_autospec(Test.an_async_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.an_async_classmethod_coroutine)
def test_create_autospec_on_coroutine_with_coroutine_side_effect(self):
coroutines = [Test.a_coroutine]
if _using_await:
coroutines.append(Test.an_async_coroutine)
for a_coroutine in coroutines:
mock = asynctest.mock.create_autospec(
a_coroutine, side_effect=asyncio.coroutine(lambda r: r))
self.assertEqual("PROBE", run_coroutine(mock("PROBE")))
self.assertFalse(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_classmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_staticmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
if _using_await:
mock = asynctest.mock.create_autospec(Test.an_async_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.an_async_classmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.an_async_staticmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
def test_create_autospec_on_coroutine_with_instance_raises_RuntimeError(self):
with self.assertRaises(RuntimeError):
asynctest.mock.create_autospec(Test.a_coroutine, instance=True)
def test_autospec_of_coroutine_function_is_coroutinefunction(self):
mock = asynctest.mock.create_autospec(Test.a_function)
self.assertFalse(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_classmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.a_staticmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
if _using_await:
mock = asynctest.mock.create_autospec(Test.an_async_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.an_async_classmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
mock = asynctest.mock.create_autospec(Test.an_async_staticmethod_coroutine)
self.assertTrue(asyncio.iscoroutinefunction(mock))
def test_returns_replay_storage(self):
replay = mock.create_autospec(ReplayMarkerStorage)()
result = Client.create_replay_storage(replay)
self.assertIs(result, replay)
def test_create_autospec_on_coroutine_with_exception_side_effect(self):
coroutines = [Test.a_coroutine]
if _using_await:
coroutines.append(Test.an_async_coroutine)
for a_coroutine in coroutines:
mock = asynctest.mock.create_autospec(a_coroutine,
side_effect=ProbeException)
with self.assertRaises(ProbeException):
run_coroutine(mock(None))