From 49453310931276767c87a41919f18679d05b49ec Mon Sep 17 00:00:00 2001 From: Jean-Baptiste LE STANG Date: Sat, 30 Dec 2017 15:43:22 +0100 Subject: [PATCH 1/2] Fixing the positional parameter naming + unit tests updated --- freqtrade/main.py | 2 +- freqtrade/tests/test_misc.py | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/freqtrade/main.py b/freqtrade/main.py index 18bc04e6f..4a88806c7 100755 --- a/freqtrade/main.py +++ b/freqtrade/main.py @@ -379,7 +379,7 @@ def main() -> None: throttle( _process, min_secs=_CONF['internals'].get('process_throttle_secs', 10), - dynamic_whitelist=args.dynamic_whitelist, + nb_assets=args.dynamic_whitelist, ) old_state = new_state except KeyboardInterrupt: diff --git a/freqtrade/tests/test_misc.py b/freqtrade/tests/test_misc.py index 962c833e4..cc75fa01c 100644 --- a/freqtrade/tests/test_misc.py +++ b/freqtrade/tests/test_misc.py @@ -16,15 +16,33 @@ def test_throttle(): return 42 start = time.time() - result = throttle(func, 0.1) + result = throttle(func, min_secs = 0.1) end = time.time() assert result == 42 assert end - start > 0.1 - result = throttle(func, -1) + result = throttle(func, min_secs = -1) assert result == 42 +def test_throttle_with_assets(): + + def func(nb_assets = -1): + return nb_assets + + start = time.time() + result = throttle(func, min_secs = 0.1, nb_assets = 666) + end = time.time() + + assert result == 666 + + start = time.time() + result = throttle(func, min_secs = 0.1) + end = time.time() + + assert result == -1 + + def test_parse_args_defaults(): args = parse_args([]) From 68f81b2abbe0021603a7b22b736dd8f46dd71e15 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste LE STANG Date: Sat, 30 Dec 2017 15:55:49 +0100 Subject: [PATCH 2/2] autopep8 is going to be my new friend --- freqtrade/tests/test_misc.py | 40 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/freqtrade/tests/test_misc.py b/freqtrade/tests/test_misc.py index cc75fa01c..cd529039a 100644 --- a/freqtrade/tests/test_misc.py +++ b/freqtrade/tests/test_misc.py @@ -16,34 +16,28 @@ def test_throttle(): return 42 start = time.time() - result = throttle(func, min_secs = 0.1) + result = throttle(func, min_secs=0.1) end = time.time() assert result == 42 assert end - start > 0.1 - result = throttle(func, min_secs = -1) + result = throttle(func, min_secs=-1) assert result == 42 + def test_throttle_with_assets(): - def func(nb_assets = -1): + def func(nb_assets=-1): return nb_assets - start = time.time() - result = throttle(func, min_secs = 0.1, nb_assets = 666) - end = time.time() - + result = throttle(func, min_secs=0.1, nb_assets=666) assert result == 666 - start = time.time() - result = throttle(func, min_secs = 0.1) - end = time.time() - + result = throttle(func, min_secs=0.1) assert result == -1 - def test_parse_args_defaults(): args = parse_args([]) assert args is not None @@ -91,7 +85,8 @@ def test_parse_args_dynamic_whitelist_invalid_values(): def test_parse_args_backtesting(mocker): - backtesting_mock = mocker.patch('freqtrade.optimize.backtesting.start', MagicMock()) + backtesting_mock = mocker.patch( + 'freqtrade.optimize.backtesting.start', MagicMock()) args = parse_args(['backtesting']) assert args is None assert backtesting_mock.call_count == 1 @@ -114,7 +109,8 @@ def test_parse_args_backtesting_invalid(): def test_parse_args_backtesting_custom(mocker): - backtesting_mock = mocker.patch('freqtrade.optimize.backtesting.start', MagicMock()) + backtesting_mock = mocker.patch( + 'freqtrade.optimize.backtesting.start', MagicMock()) args = parse_args([ '-c', 'test_conf.json', 'backtesting', @@ -135,7 +131,8 @@ def test_parse_args_backtesting_custom(mocker): def test_parse_args_hyperopt(mocker): - hyperopt_mock = mocker.patch('freqtrade.optimize.hyperopt.start', MagicMock()) + hyperopt_mock = mocker.patch( + 'freqtrade.optimize.hyperopt.start', MagicMock()) args = parse_args(['hyperopt']) assert args is None assert hyperopt_mock.call_count == 1 @@ -148,7 +145,8 @@ def test_parse_args_hyperopt(mocker): def test_parse_args_hyperopt_custom(mocker): - hyperopt_mock = mocker.patch('freqtrade.optimize.hyperopt.start', MagicMock()) + hyperopt_mock = mocker.patch( + 'freqtrade.optimize.hyperopt.start', MagicMock()) args = parse_args(['-c', 'test_conf.json', 'hyperopt', '--epochs', '20']) assert args is None assert hyperopt_mock.call_count == 1 @@ -173,7 +171,10 @@ def test_load_config(default_conf, mocker): def test_load_config_invalid_pair(default_conf, mocker): conf = deepcopy(default_conf) conf['exchange']['pair_whitelist'].append('BTC-ETH') - mocker.patch('freqtrade.misc.open', mocker.mock_open(read_data=json.dumps(conf))) + mocker.patch( + 'freqtrade.misc.open', + mocker.mock_open( + read_data=json.dumps(conf))) with pytest.raises(ValidationError, match=r'.*does not match.*'): load_config('somefile') @@ -181,6 +182,9 @@ def test_load_config_invalid_pair(default_conf, mocker): def test_load_config_missing_attributes(default_conf, mocker): conf = deepcopy(default_conf) conf.pop('exchange') - mocker.patch('freqtrade.misc.open', mocker.mock_open(read_data=json.dumps(conf))) + mocker.patch( + 'freqtrade.misc.open', + mocker.mock_open( + read_data=json.dumps(conf))) with pytest.raises(ValidationError, match=r'.*\'exchange\' is a required property.*'): load_config('somefile')