Created
May 3, 2015 01:28
-
-
Save Tinche/dcfe90292b8fb94f89e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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