From 067267f4cfc7a0442c4ae400c05be8a47d693333 Mon Sep 17 00:00:00 2001 From: hroff-1902 Date: Sat, 23 Nov 2019 12:20:41 +0300 Subject: [PATCH] Log messages improved (plural/singular) --- freqtrade/optimize/hyperopt.py | 7 ++++--- tests/optimize/test_hyperopt.py | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index e536960c4..836309a62 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -23,7 +23,7 @@ from skopt import Optimizer from skopt.space import Dimension from freqtrade.data.history import get_timeframe, trim_dataframe -from freqtrade.misc import round_dict +from freqtrade.misc import plural, round_dict from freqtrade.optimize.backtesting import Backtesting # Import IHyperOpt and IHyperOptLoss to allow unpickling classes from these modules from freqtrade.optimize.hyperopt_interface import IHyperOpt # noqa: F4 @@ -140,11 +140,12 @@ class Hyperopt: """ num_trials = len(self.trials) if num_trials > self.num_trials_saved: - logger.info(f"Saving {num_trials} epochs.") + logger.info(f"Saving {num_trials} {plural(num_trials, 'epoch')}.") dump(self.trials, self.trials_file) self.num_trials_saved = num_trials if final: - logger.info(f"{num_trials} epochs were saved to '{self.trials_file}'.") + logger.info(f"{num_trials} {plural(num_trials, 'epoch')} " + f"saved to '{self.trials_file}'.") def read_trials(self) -> List: """ diff --git a/tests/optimize/test_hyperopt.py b/tests/optimize/test_hyperopt.py index 00477f790..2ec9f5664 100644 --- a/tests/optimize/test_hyperopt.py +++ b/tests/optimize/test_hyperopt.py @@ -384,10 +384,11 @@ def test_save_trials_saves_trials(mocker, hyperopt, testdatadir, caplog) -> None trials = create_trials(mocker, hyperopt, testdatadir) mock_dump = mocker.patch('freqtrade.optimize.hyperopt.dump', return_value=None) hyperopt.trials = trials - hyperopt.save_trials() + hyperopt.save_trials(final=True) trials_file = testdatadir / 'optimize' / 'ut_trials.pickle' - assert log_has("Saving 1 epochs.", caplog) + assert log_has("Saving 1 epoch.", caplog) + assert log_has(f"1 epoch saved to '{trials_file}'.", caplog) mock_dump.assert_called_once()