From 73378d3cf6430a16352dfdb47b31289e4e0ae08f Mon Sep 17 00:00:00 2001 From: Ewald de Wit Date: Sun, 20 Sep 2020 14:55:40 +0200 Subject: [PATCH] Beginning of a test suite added --- requirements-dev.txt | 2 ++ tests/conftest.py | 20 ++++++++++++++++++++ tests/test_requests.py | 17 +++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 requirements-dev.txt create mode 100644 tests/conftest.py create mode 100644 tests/test_requests.py diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 000000000..ee4ba0186 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,2 @@ +pytest +pytest-asyncio diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 000000000..07c2aa893 --- /dev/null +++ b/tests/conftest.py @@ -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() diff --git a/tests/test_requests.py b/tests/test_requests.py new file mode 100644 index 000000000..5bb82394b --- /dev/null +++ b/tests/test_requests.py @@ -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