Skip to content

Commit

Permalink
* moved to tox.ini
Browse files Browse the repository at this point in the history
* improved data file discovery
  • Loading branch information
verybadsoldier committed Jan 12, 2020
1 parent ff78d8c commit 2d237b5
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ backtrader_plotting.egg-info
/tests/.pytest_cache
/.idea
/.pytest_cache
/.tox
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest
11 changes: 6 additions & 5 deletions tests/test_backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 5 additions & 1 deletion tests/test_issue10.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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),
)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_issue30.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import backtrader_plotting
from backtrader_plotting.schemes import Tradimo

from testcommon import getdatadir


class MyStrategy(bt.Strategy):
def __init__(self):
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions tests/testcommon.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tox]
envlist = py36,py37,p38

[testenv]

deps = -r{toxinidir}/requirements-test.txt

commands =
pytest

0 comments on commit 2d237b5

Please sign in to comment.