How to use the asynctest.mock.create_autospec function in asynctest

To help you get started, we’ve selected a few asynctest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Martiusweb / asynctest / test / test_mock.py View on Github external
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)))
github Martiusweb / asynctest / test / test_mock.py View on Github external
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))
github Martiusweb / asynctest / test / test_mock.py View on Github external
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)
github Martiusweb / asynctest / test / test_mock.py View on Github external
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)
github Martiusweb / asynctest / test / test_mock.py View on Github external
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")))
github Martiusweb / asynctest / test / test_mock.py View on Github external
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))
github Martiusweb / asynctest / test / test_mock.py View on Github external
def test_create_autospec_on_coroutine_with_instance_raises_RuntimeError(self):
        with self.assertRaises(RuntimeError):
            asynctest.mock.create_autospec(Test.a_coroutine, instance=True)
github Martiusweb / asynctest / test / test_mock.py View on Github external
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))
github robertmrk / aiosfstream / tests / test_client.py View on Github external
def test_returns_replay_storage(self):
        replay = mock.create_autospec(ReplayMarkerStorage)()

        result = Client.create_replay_storage(replay)

        self.assertIs(result, replay)
github Martiusweb / asynctest / test / test_mock.py View on Github external
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))