Skip to content

Commit

Permalink
Beginning of a test suite added
Browse files Browse the repository at this point in the history
  • Loading branch information
erdewit committed Sep 20, 2020
1 parent 8eca0d1 commit 73378d3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
pytest-asyncio
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import asyncio

import pytest

import ib_insync as ibi


@pytest.fixture(scope='session')
def event_loop():
loop = asyncio.get_event_loop()
yield loop
loop.close()


@pytest.fixture(scope='session')
async def ib():
ib = ibi.IB()
await ib.connectAsync()
yield ib
ib.disconnect()
17 changes: 17 additions & 0 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

import ib_insync as ibi


@pytest.mark.asyncio
async def test_request_error_raised(ib):
contract = ibi.Stock('MMM', 'SMART', 'USD')
order = ibi.MarketOrder('BUY', 100)
orderState = await ib.whatIfOrderAsync(contract, order)
assert orderState.commission > 0

ib.RaiseRequestErrors = True
badContract = ibi.Stock('XXX')
with pytest.raises(ibi.RequestError) as exc_info:
await ib.whatIfOrderAsync(badContract, order)
assert exc_info.value.code == 321

0 comments on commit 73378d3

Please sign in to comment.