|
2 | 2 | import unittest |
3 | 3 | from pathlib import Path |
4 | 4 | from unittest import TestCase |
| 5 | +from unittest.mock import patch, MagicMock |
5 | 6 | from datetime import datetime, timezone |
6 | 7 |
|
7 | | -from investing_algorithm_framework import download |
| 8 | +import polars as pl |
8 | 9 |
|
| 10 | +from investing_algorithm_framework import download |
9 | 11 |
|
10 | 12 |
|
11 | 13 | class TestDownload(TestCase): |
12 | 14 |
|
13 | | - @unittest.skipIf(os.environ.get("CI"), "Requires pre-downloaded data") |
14 | | - def test_download_data_with_already_existing_data(self): |
15 | | - storage_path = Path(__file__).parent / "resources" / "data" |
| 15 | + @patch("investing_algorithm_framework.infrastructure" |
| 16 | + ".data_providers.ccxt.ccxt") |
| 17 | + def test_download_data_with_already_existing_data(self, mock_ccxt_module): |
| 18 | + """ |
| 19 | + Test that download() works when local CSV data already exists. |
| 20 | + Uses test_data/ohlcv CSVs; CCXT is mocked so no network call |
| 21 | + is made (the provider reads from the local file). |
| 22 | + """ |
| 23 | + # Mock the exchange so has_data() succeeds without network |
| 24 | + mock_exchange = MagicMock() |
| 25 | + mock_exchange.load_markets.return_value = {"BTC/EUR": {}} |
| 26 | + mock_exchange.timeframes = {"2h": "2h"} |
| 27 | + mock_exchange_class = MagicMock(return_value=mock_exchange) |
| 28 | + mock_ccxt_module.bitvavo = mock_exchange_class |
| 29 | + |
| 30 | + storage_path = ( |
| 31 | + Path(__file__).parent / "resources" / "test_data" / "ohlcv" |
| 32 | + ) |
16 | 33 | data = download( |
17 | 34 | symbol="BTC/EUR", |
18 | 35 | market="BITVAVO", |
19 | 36 | data_type="OHLCV", |
20 | 37 | time_frame="2h", |
21 | | - start_date=datetime(2023, 1, 1, tzinfo=timezone.utc), |
22 | | - end_date=datetime(2023, 12, 31, tzinfo=timezone.utc), |
| 38 | + start_date=datetime(2023, 8, 11, 16, 0, tzinfo=timezone.utc), |
| 39 | + end_date=datetime(2023, 12, 2, 0, 0, tzinfo=timezone.utc), |
23 | 40 | storage_path=str(storage_path) |
24 | 41 | ) |
25 | 42 | self.assertIsNotNone(data) |
|
0 commit comments