From 2d237b5239b49255b18a06da5acfa92231a517bd Mon Sep 17 00:00:00 2001 From: verybadsoldier Date: Sun, 12 Jan 2020 12:10:37 +0100 Subject: [PATCH] * moved to tox.ini * improved data file discovery --- .gitignore | 1 + .travis.yml | 8 ++++---- requirements-test.txt | 1 + tests/test_backtest.py | 11 ++++++----- tests/test_issue10.py | 6 +++++- tests/test_issue30.py | 4 +++- tests/testcommon.py | 10 ++++++++++ tox.ini | 9 +++++++++ 8 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 requirements-test.txt create mode 100644 tests/testcommon.py create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 4e3fa69..a092c10 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ backtrader_plotting.egg-info /tests/.pytest_cache /.idea /.pytest_cache +/.tox diff --git a/.travis.yml b/.travis.yml index 70652f7..7cab305 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,8 @@ python: - "3.7" - "3.8" - "3.8-dev" - - "nightly" + # - "nightly" -script: - - cd tests - - pytest +install: pip install tox-travis + +script: tox diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..e079f8a --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1 @@ +pytest diff --git a/tests/test_backtest.py b/tests/test_backtest.py index 711d158..2df79d0 100644 --- a/tests/test_backtest.py +++ b/tests/test_backtest.py @@ -5,8 +5,9 @@ import backtrader_plotting.bokeh.bokeh from backtrader_plotting import Bokeh, OptBrowser -from tests.strategies.togglestrategy import ToggleStrategy -from tests.asserts.asserts import assert_num_tabs, assert_num_figures +from strategies.togglestrategy import ToggleStrategy +from asserts.asserts import assert_num_tabs, assert_num_figures +from testcommon import getdatadir # set to 'show' for debugging _output_mode = 'memory' @@ -16,7 +17,7 @@ def cerebro() -> bt.Cerebro: cerebro = bt.Cerebro() - datapath = 'datas/orcl-1995-2014.txt' + datapath = getdatadir('orcl-1995-2014.txt') data = bt.feeds.YahooFinanceCSVData( dataname=datapath, fromdate=datetime.datetime(1998, 1, 1), @@ -37,7 +38,7 @@ def cerebro() -> bt.Cerebro: def cerebro_no_optreturn() -> bt.Cerebro: cerebro = bt.Cerebro(optreturn=False) - datapath = 'datas/orcl-1995-2014.txt' + datapath = getdatadir('orcl-1995-2014.txt') data = bt.feeds.YahooFinanceCSVData( dataname=datapath, fromdate=datetime.datetime(1998, 1, 1), @@ -82,7 +83,7 @@ def test_std_backtest(cerebro: bt.Cerebro): def test_std_backtest_2datas(cerebro: bt.Cerebro): - datapath = 'datas/nvda-1999-2014.txt' + datapath = getdatadir('nvda-1999-2014.txt') data = bt.feeds.YahooFinanceCSVData( dataname=datapath, fromdate=datetime.datetime(1998, 1, 1), diff --git a/tests/test_issue10.py b/tests/test_issue10.py index 413f9d6..0467dda 100644 --- a/tests/test_issue10.py +++ b/tests/test_issue10.py @@ -2,8 +2,12 @@ # Import the backtrader platform import backtrader as bt + import backtrader_plotting +from testcommon import getdatadir + + # Create a Stratey class MACDStrategy(bt.Strategy): params = ( @@ -97,7 +101,7 @@ def bokeh_plot(data): def test_github_issue10(): data = bt.feeds.YahooFinanceCSVData( - dataname="./datas/orcl-1995-2014.txt", + dataname=getdatadir("orcl-1995-2014.txt"), fromdate=datetime.datetime(2000, 1, 1), todate=datetime.datetime(2001, 2, 28), ) diff --git a/tests/test_issue30.py b/tests/test_issue30.py index ecc0afc..f757d76 100644 --- a/tests/test_issue30.py +++ b/tests/test_issue30.py @@ -3,6 +3,8 @@ import backtrader_plotting from backtrader_plotting.schemes import Tradimo +from testcommon import getdatadir + class MyStrategy(bt.Strategy): def __init__(self): @@ -24,7 +26,7 @@ def test_github_issue30(): cerebro.addstrategy(MyStrategy) data = bt.feeds.YahooFinanceCSVData( - dataname="datas/orcl-1995-2014.txt", + dataname=getdatadir("orcl-1995-2014.txt"), fromdate=datetime.datetime(2000, 1, 1), todate=datetime.datetime(2001, 2, 28), reverse=False, diff --git a/tests/testcommon.py b/tests/testcommon.py new file mode 100644 index 0000000..6610052 --- /dev/null +++ b/tests/testcommon.py @@ -0,0 +1,10 @@ +import os +import os.path + + +modpath = os.path.dirname(os.path.abspath(__file__)) +dataspath = 'datas' + + +def getdatadir(filename): + return os.path.join(modpath, dataspath, filename) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..36ec0be --- /dev/null +++ b/tox.ini @@ -0,0 +1,9 @@ +[tox] +envlist = py36,py37,p38 + +[testenv] + +deps = -r{toxinidir}/requirements-test.txt + +commands = + pytest