Skip to content

Instantly share code, notes, and snippets.

@Tinche
Created May 3, 2015 01:28
Show Gist options
  • Select an option

  • Save Tinche/dcfe90292b8fb94f89e7 to your computer and use it in GitHub Desktop.

Select an option

Save Tinche/dcfe90292b8fb94f89e7 to your computer and use it in GitHub Desktop.
import asyncio
import pytest
import serial
def test_some_interaction(monkeypatch, mocker):
# create a queue
q = asyncio.LifoQueue(maxsize=1)
# stub out the call to serial.Serial in the EsploraSerial class __init__
mocker.patch('serial.Serial')
# instantiate the Esplora Serial class
#create a mock return for the queue "get"
def mockreturn(get):
return '/abc'
# monkey patch the lifo get to return "/abc"
monkeypatch.setattr(asyncio.LifoQueue, 'get', mockreturn)
resp = q.get()
assert resp == "/abc"
@pytest.mark.asyncio
def test_some_interaction2(monkeypatch, mocker):
# create a queue
q = asyncio.LifoQueue(maxsize=1)
# stub out the call to serial.Serial in the EsploraSerial class __init__
mocker.patch('serial.Serial')
# instantiate the Esplora Serial class
#create a mock return for the queue "get"
@asyncio.coroutine
def mockreturn(get):
return '/abc'
# monkey patch the lifo get to return "/abc"
monkeypatch.setattr(asyncio.LifoQueue, 'get', mockreturn)
resp = yield from q.get()
assert resp == "/abc"
@pytest.mark.asyncio
def test_some_interaction3(monkeypatch, mocker):
# create a queue
q = asyncio.LifoQueue(maxsize=1)
# stub out the call to serial.Serial in the EsploraSerial class __init__
mocker.patch('serial.Serial')
# instantiate the Esplora Serial class
#create a mock return for the queue "get"
@asyncio.coroutine
def mockreturn(get):
return '/abc'
# monkey patch the lifo get to return "/abc"
monkeypatch.setattr(asyncio.LifoQueue, 'get', mockreturn)
resp = yield from q.get()
assert resp == "/abc"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment