Comments on: Comment mocker une coroutine ? http://sametmax.com/comment-mocker-une-coroutine/ Du code, du cul Mon, 28 Oct 2019 11:54:55 +0000 hourly 1 https://wordpress.org/?v=4.9.7 By: polux http://sametmax.com/comment-mocker-une-coroutine/#comment-174935 Wed, 27 Jan 2016 10:07:50 +0000 http://sametmax.com/?p=17976#comment-174935 C’est quoi un mock ?

]]>
By: Sam http://sametmax.com/comment-mocker-une-coroutine/#comment-174867 Tue, 26 Jan 2016 10:13:16 +0000 http://sametmax.com/?p=17976#comment-174867 Arrête de te mocker !

]]>
By: vlmath http://sametmax.com/comment-mocker-une-coroutine/#comment-174846 Mon, 25 Jan 2016 22:33:48 +0000 http://sametmax.com/?p=17976#comment-174846 “pour gérer gérer les coroutines” : bègue ? :P

]]>
By: boblinux http://sametmax.com/comment-mocker-une-coroutine/#comment-174841 Mon, 25 Jan 2016 22:03:42 +0000 http://sametmax.com/?p=17976#comment-174841 i understand nothing.

]]>
By: Sam http://sametmax.com/comment-mocker-une-coroutine/#comment-174835 Mon, 25 Jan 2016 15:50:49 +0000 http://sametmax.com/?p=17976#comment-174835 Hi. It’s cool but I don’t get how it helps me:

    >>> loop = asyncio.get_event_loop()
    >>> async def foo():
    ...     b = await CoroutineMock()
    ...     print(b)
  
    >>> loop.run_until_complete(foo())
    Traceback (most recent call last):
      File "", line 1, in 
      File "/usr/lib/python3.5/asyncio/base_events.py", line 337, in run_until_complete
        return future.result()
      File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
        raise self._exception
      File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
        result = coro.send(None)
      File "", line 2, in foo
    TypeError: object CoroutineMock can't be used in 'await' expression
    object CoroutineMock can't be used in 'await' expression

    >>> async def foo():
    ...     b = await asyncio.ensure_future(CoroutineMock())
    ...   
    ...     print(b)

    >>> loop.run_until_complete(foo())
    Traceback (most recent call last):
      File "", line 1, in 
      File "/usr/lib/python3.5/asyncio/base_events.py", line 337, in run_until_complete
        return future.result()
      File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
        raise self._exception
      File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
        result = coro.send(None)
      File "", line 2, in foo
      File "/usr/lib/python3.5/asyncio/tasks.py", line 546, in ensure_future
        raise TypeError('A Future, a coroutine or an awaitable is required')
    TypeError: A Future, a coroutine or an awaitable is required
    A Future, a coroutine or an awaitable is required

  

If I can’t use it anywhere I would use a regular coroutine, what’s the point of mocking it ?

Did I use it wrong ?

]]>
By: Martius http://sametmax.com/comment-mocker-une-coroutine/#comment-174834 Mon, 25 Jan 2016 15:20:43 +0000 http://sametmax.com/?p=17976#comment-174834 J’écris une bibliothèque qui s’appelle asynctest (aussi sur github et Pypi).

Elle surcharge le paquet standard unittest pour ajouter des fonctionnalités permettant de tester du code asyncio. Elle inclue des outils pour facilement faire des mocks de coroutines (y compris avec de l’auto-mocking ou patch()). Elle permet aussi d’utiliser directement des coroutines dans les fonctions de setup, teardown, test ou cleanup (ce qui fait économiser pas mal de boilerplate).

]]>