From 2fd8b89503116f561a07b054e091caf79a5a34ef Mon Sep 17 00:00:00 2001 From: marcvanduyn Date: Wed, 11 Mar 2026 13:22:39 +0100 Subject: [PATCH] fix: use existing OHLCV data files and make paths Windows-compatible in tests/domain (#371) - test_backtest.py: Replace hardcoded forward-slash path to non-existent backtest_data/ CSV with os.path.join to existing test_data/ohlcv/ file - test_polars.py: Update datetime64[ns] assertion to datetime64[us] for newer pandas compatibility - test_backtest_save.py: Fix test_save_without_metrics to assert metrics.json is NOT created when no pre-computed metrics are provided (matching actual BacktestRun.save() behavior) --- tests/domain/backtests/test_backtest_save.py | 4 ++-- tests/domain/models/backtesting/test_backtest.py | 5 +++-- tests/domain/utils/test_polars.py | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/domain/backtests/test_backtest_save.py b/tests/domain/backtests/test_backtest_save.py index 3c26ebdb..1b9d1ba8 100644 --- a/tests/domain/backtests/test_backtest_save.py +++ b/tests/domain/backtests/test_backtest_save.py @@ -86,7 +86,8 @@ def test_save_without_metrics(self): self.assertTrue( os.path.exists(os.path.join(backtest_run_dir, "run.json")) ) - self.assertTrue( + # metrics.json is only created when backtest_metrics is provided + self.assertFalse( os.path.exists(os.path.join(backtest_run_dir, "metrics.json")) ) @@ -152,4 +153,3 @@ def test_save_with_precomputed_metrics(self): self.assertTrue( os.path.exists(os.path.join(backtest_run_dir, "metrics.json")) ) - diff --git a/tests/domain/models/backtesting/test_backtest.py b/tests/domain/models/backtesting/test_backtest.py index d97e4a69..c48f4983 100644 --- a/tests/domain/models/backtesting/test_backtest.py +++ b/tests/domain/models/backtesting/test_backtest.py @@ -44,7 +44,9 @@ def setUp(self): ) self.ohlcv_csv_path = os.path.join( self.resource_dir, - "backtest_data/OHLCV_BTC-EUR_BINANCE_2h_2020-12-15-06-00_2021-01-01-00-30.csv" + "test_data", + "ohlcv", + "OHLCV_BTC-EUR_BINANCE_2h_2023-08-07-07-08_2023-12-02-00-00.csv" ) # Test models @@ -1473,4 +1475,3 @@ def test_backtest_set_uniqueness_by_metadata_id(self): self.assertEqual(len(backtest_set2), 2) self.assertIn(backtest4, backtest_set2) self.assertIn(backtest5, backtest_set2) - diff --git a/tests/domain/utils/test_polars.py b/tests/domain/utils/test_polars.py index 49c0328e..f73441dc 100644 --- a/tests/domain/utils/test_polars.py +++ b/tests/domain/utils/test_polars.py @@ -4,7 +4,7 @@ from investing_algorithm_framework import convert_polars_to_pandas class TestConvertPandasToPolars(TestCase): - + def test_convert_pandas_to_polars(self): polars_df = DataFrame({ "Datetime": ["2021-01-01", "2021-01-02", "2021-01-03"], @@ -33,7 +33,7 @@ def test_convert_pandas_to_polars(self): self.assertEqual(set(column_names), {'Close'}) # Check if the index is a datetime object - self.assertEqual(polars_df_converted.index.dtype, "datetime64[ns]") + self.assertEqual(polars_df_converted.index.dtype, "datetime64[us]") self.assertEqual( polars_df_converted.index[0], Timestamp('2021-01-01 00:00:00') )