From 6c02cc59939c8355106e7ce64de5805d855fd10b Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 15 Dec 2018 14:10:45 +0100 Subject: [PATCH] Adjust test to pathlib --- freqtrade/data/history.py | 2 +- freqtrade/edge/__init__.py | 2 +- freqtrade/optimize/backtesting.py | 2 +- freqtrade/optimize/hyperopt.py | 2 +- freqtrade/tests/data/test_history.py | 13 +++++++------ 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/freqtrade/data/history.py b/freqtrade/data/history.py index 00dc8470b..793aee0d1 100644 --- a/freqtrade/data/history.py +++ b/freqtrade/data/history.py @@ -64,7 +64,7 @@ def trim_tickerlist(tickerlist: List[Dict], timerange: TimeRange) -> List[Dict]: def load_tickerdata_file( - datadir: Path, pair: str, + datadir: Optional[Path], pair: str, ticker_interval: str, timerange: Optional[TimeRange] = None) -> Optional[List[Dict]]: """ diff --git a/freqtrade/edge/__init__.py b/freqtrade/edge/__init__.py index 29f34ce27..72e234773 100644 --- a/freqtrade/edge/__init__.py +++ b/freqtrade/edge/__init__.py @@ -100,7 +100,7 @@ class Edge(): logger.info('Using local backtesting data (using whitelist in given config) ...') data = history.load_data( - Path(self.config.get('datadir')) if self.config.get('datadir') else None, + Path(self.config['datadir']) if self.config.get('datadir') else None, pairs=pairs, ticker_interval=self.ticker_interval, refresh_pairs=self._refresh_pairs, diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 1640adef4..4447df966 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -370,7 +370,7 @@ class Backtesting(object): timerange = Arguments.parse_timerange(None if self.config.get( 'timerange') is None else str(self.config.get('timerange'))) data = history.load_data( - Path(self.config.get('datadir')) if self.config.get('datadir') else None, + Path(self.config['datadir']) if self.config.get('datadir') else None, pairs=pairs, ticker_interval=self.ticker_interval, refresh_pairs=self.config.get('refresh_pairs', False), diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index a405217e9..2d08fec81 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -241,7 +241,7 @@ class Hyperopt(Backtesting): timerange = Arguments.parse_timerange(None if self.config.get( 'timerange') is None else str(self.config.get('timerange'))) data = load_data( - datadir=Path(self.config.get('datadir')) if self.config.get('datadir') else None, + datadir=Path(self.config['datadir']) if self.config.get('datadir') else None, pairs=self.config['exchange']['pair_whitelist'], ticker_interval=self.ticker_interval, timerange=timerange diff --git a/freqtrade/tests/data/test_history.py b/freqtrade/tests/data/test_history.py index 585e7e2a7..4f6d5d247 100644 --- a/freqtrade/tests/data/test_history.py +++ b/freqtrade/tests/data/test_history.py @@ -2,6 +2,7 @@ import json import os +from pathlib import Path import uuid from shutil import copyfile @@ -116,7 +117,7 @@ def test_load_data_with_new_pair_1min(ticker_history_list, mocker, caplog, defau def test_testdata_path() -> None: - assert os.path.join('freqtrade', 'tests', 'testdata') in make_testdata_path(None) + assert str(Path('freqtrade') / 'tests' / 'testdata') in str(make_testdata_path(None)) def test_download_pairs(ticker_history_list, mocker, default_conf) -> None: @@ -160,10 +161,10 @@ def test_download_pairs(ticker_history_list, mocker, default_conf) -> None: def test_load_cached_data_for_updating(mocker) -> None: - datadir = os.path.join(os.path.dirname(__file__), '..', 'testdata') + datadir = Path(__file__).parent.parent.joinpath('testdata') test_data = None - test_filename = os.path.join(datadir, 'UNITTEST_BTC-1m.json') + test_filename = datadir.joinpath('UNITTEST_BTC-1m.json') with open(test_filename, "rt") as file: test_data = json.load(file) @@ -238,7 +239,7 @@ def test_load_cached_data_for_updating(mocker) -> None: # no datafile exist # should return timestamp start time timerange = TimeRange('date', None, now_ts - 10000, 0) - data, start_ts = load_cached_data_for_updating(test_filename + 'unexist', + data, start_ts = load_cached_data_for_updating(test_filename.with_name('unexist'), '1m', timerange) assert data == [] @@ -247,7 +248,7 @@ def test_load_cached_data_for_updating(mocker) -> None: # same with 'line' timeframe num_lines = 30 timerange = TimeRange(None, 'line', 0, -num_lines) - data, start_ts = load_cached_data_for_updating(test_filename + 'unexist', + data, start_ts = load_cached_data_for_updating(test_filename.with_name('unexist'), '1m', timerange) assert data == [] @@ -255,7 +256,7 @@ def test_load_cached_data_for_updating(mocker) -> None: # no datafile exist, no timeframe is set # should return an empty array and None - data, start_ts = load_cached_data_for_updating(test_filename + 'unexist', + data, start_ts = load_cached_data_for_updating(test_filename.with_name('unexist'), '1m', None) assert data == []