5c24d2d72d
- Add check for `mt5.copy_rates_from_pos` returning `None` in `live_trading/multi_bar.py:82` - Add test in `tests/test_multi_bar.py` verifying that when `mt5.copy_rates_from_pos` returns `None`, the function returns `None` and an error is logged. Co-authored-by: maghdam <63883156+maghdam@users.noreply.github.com>
25 lines
898 B
Python
25 lines
898 B
Python
import sys
|
|
from unittest.mock import MagicMock
|
|
# Mock out MetaTrader5 before importing our module
|
|
sys.modules['MetaTrader5'] = MagicMock()
|
|
|
|
import unittest
|
|
from unittest.mock import patch
|
|
import pandas as pd
|
|
from live_trading.multi_bar import TradingApp, log_and_print
|
|
|
|
class TestTradingApp(unittest.TestCase):
|
|
def setUp(self):
|
|
self.app = TradingApp(symbol="EURUSD", lot_size=0.01, magic_number=123456)
|
|
|
|
@patch("live_trading.multi_bar.mt5.copy_rates_from_pos")
|
|
@patch("live_trading.multi_bar.log_and_print")
|
|
def test_get_data_returns_none(self, mock_log, mock_copy_rates):
|
|
mock_copy_rates.return_value = None
|
|
|
|
# Test what happens when mt5.copy_rates_from_pos returns None
|
|
result = self.app.get_data("EURUSD", 100, 16408)
|
|
|
|
self.assertIsNone(result)
|
|
mock_log.assert_called_once_with("Could not retrieve data for EURUSD", is_error=True)
|