Skip to content

Commit add941d

Browse files
committed
Add checkpoint tests
1 parent b487036 commit add941d

5 files changed

Lines changed: 38 additions & 55 deletions

File tree

tests/app/backtesting/test_run_backtest.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,11 @@ class Test(TestCase):
2929
Collection of tests for backtest report operations
3030
"""
3131
def setUp(self) -> None:
32-
self.resource_directory = os.path.abspath(
33-
os.path.join(
34-
os.path.join(
35-
os.path.join(
36-
os.path.join(
37-
os.path.realpath(__file__),
38-
os.pardir
39-
),
40-
os.pardir
41-
),
42-
os.pardir
43-
),
44-
"resources"
45-
)
32+
# RESOURCE_DIRECTORY should always point to the parent directory/resources
33+
# Resource directory should point to /tests/resources
34+
# Resource directory is two levels up from the current file
35+
self.resource_directory = os.path.join(
36+
os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'resources'
4637
)
4738

4839
def tearDown(self) -> None:

tests/app/reporting/test_backtest_report.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,23 @@ def test_save_without_algorithm(self):
8282
# Check if the report was saved correctly
8383
self.assertTrue(os.path.exists(output_path))
8484

85-
# Check if the strategy directory was created
86-
strategy_dir = os.path.join(output_path, "strategies")
87-
self.assertTrue(os.path.exists(strategy_dir))
88-
89-
# Check if the strategy.py file exists within the strategy directory
90-
strategy_file_path = os.path.join(strategy_dir, "strategy_one.py")
91-
self.assertTrue(os.path.exists(strategy_file_path))
92-
93-
# Check if the metrics JSON file exists
94-
metrics_json_path = os.path.join(output_path, "metrics.json")
95-
self.assertTrue(os.path.exists(metrics_json_path))
85+
# Check if the runs directory exists
86+
runs_dir = os.path.join(output_path, "runs")
87+
self.assertTrue(os.path.exists(runs_dir))
9688

89+
# Check if the backtest run directory exists
90+
backtest_run_dir = os.path.join(
91+
runs_dir, "backtest_EUR_20230807_20231201"
92+
)
93+
self.assertTrue(os.path.exists(backtest_run_dir))
9794

9895
# Check if the results were saved correctly
99-
self.assertTrue(os.path.exists(os.path.join(output_path, "results.json")))
100-
self.assertTrue(os.path.exists(os.path.join(output_path, "strategies")))
96+
self.assertTrue(
97+
os.path.exists(os.path.join(backtest_run_dir, "run.json"))
98+
)
99+
self.assertTrue(
100+
os.path.exists(os.path.join(backtest_run_dir, "metrics.json"))
101+
)
101102

102103
def test_save_with_strategies_directory(self):
103104
"""
@@ -156,10 +157,6 @@ def test_save_with_strategies_directory(self):
156157
max_daily_drawdown=0.05
157158
)
158159
)
159-
data_files = [
160-
"tests/resources/market_data_sources_for_testing/OHLCV_BTC-EUR_BINANCE_2h_2023-08-07-07-59_2023-12-02-00-00.csv",
161-
"tests/resources/market_data_sources_for_testing/OHLCV_BTC-EUR_BINANCE_15m_2023-12-14-22-00_2023-12-25-00-00.csv",
162-
]
163160

164161
backtest = Backtest(
165162
algorithm_id="alg-025",
@@ -169,21 +166,26 @@ def test_save_with_strategies_directory(self):
169166
output_path = os.path.join(self.resource_dir, "backtest_report")
170167
backtest.save(output_path)
171168

169+
print(output_path)
170+
172171
# Check if the report was saved correctly
173172
self.assertTrue(os.path.exists(output_path))
174173

175-
# Check if the strategy directory was created
176-
strategy_dir = os.path.join(output_path, "strategies")
177-
self.assertTrue(os.path.exists(strategy_dir))
174+
# Check if the runs directory exists
175+
runs_dir = os.path.join(output_path, "runs")
176+
self.assertTrue(os.path.exists(runs_dir))
178177

179-
# Check if the strategy.py file exists within the strategy directory
180-
strategy_file_path = os.path.join(strategy_dir, "strategy_one.py")
181-
self.assertTrue(os.path.exists(strategy_file_path))
182-
183-
# Check if the metrics JSON file exists
184-
metrics_json_path = os.path.join(output_path, "metrics.json")
185-
self.assertTrue(os.path.exists(metrics_json_path))
178+
# Check if the backtest run directory exists
179+
backtest_run_dir = os.path.join(
180+
runs_dir, "backtest_EUR_20230807_20231201"
181+
)
182+
self.assertTrue(os.path.exists(backtest_run_dir))
186183

187184
# Check if the results were saved correctly
188-
self.assertTrue(os.path.exists(os.path.join(output_path, "results.json")))
189-
self.assertTrue(os.path.exists(os.path.join(output_path, "strategies")))
185+
self.assertTrue(
186+
os.path.exists(os.path.join(backtest_run_dir, "run.json"))
187+
)
188+
self.assertTrue(
189+
os.path.exists(os.path.join(backtest_run_dir, "metrics.json"))
190+
)
191+

tests/scenarios/vectorized_backtests/test_use_backtest_storage_directory.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,6 @@ def test_run_with_backtest_storage_directory(self):
249249
dict(zip(param_options.keys(), values))
250250
for values in product(*param_options.values())
251251
]
252-
print(
253-
f"Total parameter combinations to evaluate: {len(param_variations)}")
254252

255253
# RESOURCE_DIRECTORY should always point to the parent directory/resources
256254
# Resource directory should point to /tests/resources

tests/scenarios/vectorized_backtests/test_use_checkpoints.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ def test_run_with_checkpoints_multiple_backtest_ranges(self):
241241
# Resource directory should point to /tests/resources
242242
# Resource directory is two levels up from the current file
243243
resource_directory = os.path.join(
244-
os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'resources'
244+
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
245+
'resources'
245246
)
246247
config = {RESOURCE_DIRECTORY: resource_directory}
247248
app = create_app(name="GoldenCrossStrategy", config=config)

tests/scenarios/vectorized_backtests/test_with_show_progress.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,6 @@ def test_run_with_show_output(self):
340340
# Get the captured output as a string
341341
output = captured_output.getvalue()
342342

343-
# Print the captured output (optional - for debugging)
344-
print(output)
345-
346343
# Verify that checkpointing message appears
347344
self.assertTrue(
348345
"Using checkpoints to skip completed backtests" in output or
@@ -368,9 +365,3 @@ def test_run_with_show_output(self):
368365
self.assertTrue(
369366
"Applying final filter function" in output
370367
)
371-
372-
# Verify that filtered-out backtests are marked in metadata
373-
# (not deleted from storage)
374-
if "Marked backtest" in output and "as filtered out" in output:
375-
print("✓ Filtered-out backtests were marked in metadata "
376-
"(preserved in storage)")

0 commit comments

Comments
 (0)