This directory contains comprehensive tests for the SignalTrader application, organized by test type and component.
tests/
├── fixtures/ # Test fixtures and mock data
│ ├── __init__.py
│ ├── test_base.py # Base test class with utilities
│ └── mock_data.py # Mock objects and test data
├── unit/ # Unit tests (isolated components)
│ ├── analyzer/ # Signal analyzer tests
│ ├── metatrader/ # MT5 integration tests
│ ├── database/ # Database operation tests
│ ├── configure/ # Configuration tests
│ └── ...
├── integration/ # Integration tests (component interaction)
│ ├── metatrader/ # Full MT5 workflow tests
│ ├── database/ # Database integration tests
│ └── telegram/ # Telegram integration tests
├── utils/ # Test utilities and data generators
│ └── ScrapperGenerator/ # Signal data generation tools
└── __init__.py # Test runner utilities
python -m pytest tests/
# or
python tests/__init__.pypython -m pytest tests/unit/
# or
python -c "from tests import run_unit_tests; run_unit_tests()"python -m pytest tests/integration/
# or
python -c "from tests import run_integration_tests; run_integration_tests()"python -m pytest tests/unit/analyzer/test_text_processor.pypip install pytest-cov
pytest --cov=app --cov-report=html tests/- Analyzer Tests: Signal parsing, text processing, action detection
- MetaTrader Tests: Lot calculation, validation, connection mocking
- Database Tests: Repository operations, model validation
- Configuration Tests: Settings loading, validation
- MetaTrader Integration: Full trading workflows with mocked MT5
- Database Integration: Multi-table operations, migrations
- Telegram Integration: Message handling, API interactions
All tests inherit from TestBase which provides:
- Temporary directory management
- Logging configuration
- Common assertion helpers
- Mock utilities
Pre-configured mock objects for:
- MT5 connections and responses
- Telegram messages This directory contains comprehensive tests for the SignalTrader application, organized by test type and component.
- Trading signals
import unittest
from tests.fixtures import TestBase
class TestMyComponent(TestBase):
def setUp(self):
super().setUp()
# Component-specific setup
def test_feature(self):
# Arrange
# Act
# Assertfrom unittest.mock import patch, MagicMock
def test_with_mock(self):
with patch('module.function') as mock_func:
mock_func.return_value = expected_value
# Test code@patch('sqlite3.connect')
def test_database_operation(self, mock_connect):
mock_conn = self.mock_database_connection()
mock_connect.return_value = mock_conn
# Test database operationsLocated in fixtures/mock_data.py:
- Sample trading signals in multiple formats
- Expected parsing results
- Edge cases and error conditions
- Mock positions and orders
- Simulated market data
- Error conditions
Tests are designed to run in CI environments:
- No external dependencies required
- All external APIs mocked
- Fast execution (< 30 seconds)
- Deterministic results
- Unit Tests: > 80% coverage of individual functions
- Integration Tests: Cover all major workflows
- Error Handling: Test all error paths
- Edge Cases: Boundary conditions and unusual inputs
Add new test signals to fixtures/mock_data.py:
analyzer_test_data.append({
"input": "NEW_SIGNAL_FORMAT",
"expected": {
"action": "BUY",
"symbol": "SYMBOL",
"price": 1.2345,
"sl": 1.2200,
"tp": [1.2500, 1.2600]
}
})Extend mock data in fixtures/mock_data.py for new test scenarios.
- Import Errors: Ensure
PYTHONPATHincludes project root - Mock Failures: Check mock setup and return values
- Database Tests: Verify mock connection setup
- Coverage Issues: Check test file discovery
pytest -v -s tests/unit/analyzer/test_text_processor.py::TestTextProcessor::test_clean_text_basicWhen adding new features:
- Add corresponding unit tests
- Update integration tests if needed
- Ensure all tests pass
- Update this documentation