Skip to content

Commit 50ac874

Browse files
committed
fix: remove network dependency from test_download
Replace the CI-only skip with a fully mocked CCXT exchange so the download test reads from local CSV data in tests/resources/test_data/ohlcv instead of making network calls.
1 parent 26d49bc commit 50ac874

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

tests/test_download.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,41 @@
22
import unittest
33
from pathlib import Path
44
from unittest import TestCase
5+
from unittest.mock import patch, MagicMock
56
from datetime import datetime, timezone
67

7-
from investing_algorithm_framework import download
8+
import polars as pl
89

10+
from investing_algorithm_framework import download
911

1012

1113
class TestDownload(TestCase):
1214

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+
)
1633
data = download(
1734
symbol="BTC/EUR",
1835
market="BITVAVO",
1936
data_type="OHLCV",
2037
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),
2340
storage_path=str(storage_path)
2441
)
2542
self.assertIsNotNone(data)

0 commit comments

Comments
 (0)