-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
quiet_logs now works. for realz. with tests.
- Loading branch information
1 parent
dd4732f
commit 0f7e14c
Showing
15 changed files
with
162 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
|
||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
class TestPandasBacktest: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import datetime | ||
import logging | ||
|
||
from lumibot.example_strategies.lifecycle_logger import LifecycleLogger | ||
from lumibot.backtesting import YahooDataBacktesting | ||
|
||
|
||
class TestLogging: | ||
|
||
def test_logging(self, caplog): | ||
caplog.set_level(logging.INFO) | ||
logger = logging.getLogger() | ||
logger.info("This is an info message") | ||
assert "This is an info message" in caplog.text | ||
|
||
def test_backtest_produces_no_logs_by_default(self, caplog): | ||
caplog.set_level(logging.INFO) | ||
backtesting_start = datetime.datetime(2023, 1, 2) | ||
backtesting_end = datetime.datetime(2023, 1, 4) | ||
|
||
LifecycleLogger.backtest( | ||
YahooDataBacktesting, | ||
backtesting_start, | ||
backtesting_end, | ||
parameters={"sleeptime": "1D", "market": "NYSE"}, | ||
show_plot=False, | ||
save_tearsheet=False, | ||
show_tearsheet=False, | ||
show_indicators=False, | ||
save_logfile=False, | ||
) | ||
# count that this contains 3 new lines. Its an easy proxy for the number of log messages and avoids | ||
# the issue where the datetime is always gonna be different. | ||
assert caplog.text.count("\n") == 3 | ||
assert "Starting backtest...\n" in caplog.text | ||
assert "Backtesting starting...\n" in caplog.text | ||
assert "Backtesting finished\n" in caplog.text | ||
|
||
def test_run_backtest_produces_no_logs_by_default(self, caplog): | ||
caplog.set_level(logging.INFO) | ||
backtesting_start = datetime.datetime(2023, 1, 2) | ||
backtesting_end = datetime.datetime(2023, 1, 4) | ||
|
||
LifecycleLogger.run_backtest( | ||
YahooDataBacktesting, | ||
backtesting_start, | ||
backtesting_end, | ||
parameters={"sleeptime": "1D", "market": "NYSE"}, | ||
show_plot=False, | ||
save_tearsheet=False, | ||
show_tearsheet=False, | ||
show_indicators=False, | ||
save_logfile=False, | ||
) | ||
# count that this contains 3 new lines. Its an easy proxy for the number of log messages and avoids | ||
# the issue where the datetime is always gonna be different. | ||
assert caplog.text.count("\n") == 3 | ||
assert "Starting backtest...\n" in caplog.text | ||
assert "Backtesting starting...\n" in caplog.text | ||
assert "Backtesting finished\n" in caplog.text | ||
|
||
def test_backtest_produces_no_logs_when_quiet_logs_is_true(self, caplog): | ||
caplog.set_level(logging.INFO) | ||
backtesting_start = datetime.datetime(2023, 1, 2) | ||
backtesting_end = datetime.datetime(2023, 1, 4) | ||
|
||
LifecycleLogger.backtest( | ||
YahooDataBacktesting, | ||
backtesting_start, | ||
backtesting_end, | ||
parameters={"sleeptime": "1D", "market": "NYSE"}, | ||
show_plot=False, | ||
save_tearsheet=False, | ||
show_tearsheet=False, | ||
show_indicators=False, | ||
save_logfile=False, | ||
show_progress_bar=True, | ||
quiet_logs=True, | ||
) | ||
# count that this contains 3 new lines. Its an easy proxy for the number of log messages and avoids | ||
# the issue where the datetime is always gonna be different. | ||
assert caplog.text.count("\n") == 3 | ||
assert "Starting backtest...\n" in caplog.text | ||
assert "Backtesting starting...\n" in caplog.text | ||
assert "Backtesting finished\n" in caplog.text | ||
|
||
def test_backtest_produces_logs_when_quiet_logs_is_false(self, caplog): | ||
caplog.set_level(logging.INFO) | ||
backtesting_start = datetime.datetime(2023, 1, 2) | ||
backtesting_end = datetime.datetime(2023, 1, 4) | ||
|
||
LifecycleLogger.backtest( | ||
YahooDataBacktesting, | ||
backtesting_start, | ||
backtesting_end, | ||
parameters={"sleeptime": "1D", "market": "NYSE"}, | ||
show_plot=False, | ||
save_tearsheet=False, | ||
show_tearsheet=False, | ||
show_indicators=False, | ||
save_logfile=False, | ||
show_progress_bar=False, | ||
quiet_logs=False, | ||
) | ||
|
||
assert caplog.text.count("\n") == 9 | ||
assert "Starting backtest...\n" in caplog.text | ||
assert "Backtesting starting...\n" in caplog.text | ||
assert "before_market_opens called\n" in caplog.text | ||
assert "before_starting_trading called\n" in caplog.text | ||
assert "on_trading_iteration called\n" in caplog.text | ||
assert "before_market_closes called\n" in caplog.text | ||
assert "after_market_closes called\n" in caplog.text | ||
assert "Backtesting finished\n" in caplog.text |