|
| 1 | +""" |
| 2 | +Shared pytest fixtures for SunGather tests. |
| 3 | +
|
| 4 | +This file is automatically discovered by pytest and makes fixtures |
| 5 | +available to all test files. |
| 6 | +""" |
| 7 | + |
| 8 | +import pytest |
| 9 | +import sys |
| 10 | +from pathlib import Path |
| 11 | + |
| 12 | +# Add SunGather directory to Python path for imports |
| 13 | +sungather_dir = Path(__file__).parent.parent / "SunGather" |
| 14 | +sys.path.insert(0, str(sungather_dir)) |
| 15 | + |
| 16 | + |
| 17 | +# Fixture: Mock inverter configuration |
| 18 | +@pytest.fixture |
| 19 | +def mock_inverter_config(): |
| 20 | + """Standard inverter configuration for testing.""" |
| 21 | + return { |
| 22 | + 'host': '192.168.1.100', |
| 23 | + 'port': 502, |
| 24 | + 'timeout': 10, |
| 25 | + 'retries': 3, |
| 26 | + 'slave': 0x01, |
| 27 | + 'scan_interval': 30, |
| 28 | + 'connection': 'modbus', |
| 29 | + 'model': 'SH5.0RS', |
| 30 | + 'smart_meter': False, |
| 31 | + 'use_local_time': False, |
| 32 | + 'log_console': 'WARNING', |
| 33 | + 'log_file': 'OFF', |
| 34 | + 'level': 1 |
| 35 | + } |
| 36 | + |
| 37 | + |
| 38 | +# Fixture: Mock register data |
| 39 | +@pytest.fixture |
| 40 | +def mock_register_data(): |
| 41 | + """Sample register data returned from inverter.""" |
| 42 | + return { |
| 43 | + 'device_type_code': 'SH5.0RS', |
| 44 | + 'serial_number': '12345678', |
| 45 | + 'total_active_power': 3500, |
| 46 | + 'meter_power': -200, # Negative = exporting to grid |
| 47 | + 'load_power': 1500, |
| 48 | + 'battery_voltage': 52.4, |
| 49 | + 'battery_current': 10.5, |
| 50 | + 'battery_power': 550, |
| 51 | + 'daily_export_energy': 15.2, |
| 52 | + 'timestamp': '2025-10-19 10:30:00' |
| 53 | + } |
| 54 | + |
| 55 | + |
| 56 | +# Fixture: Mock MQTT export configuration |
| 57 | +@pytest.fixture |
| 58 | +def mock_mqtt_config(): |
| 59 | + """Standard MQTT export configuration for testing.""" |
| 60 | + return { |
| 61 | + 'name': 'mqtt', |
| 62 | + 'enabled': True, |
| 63 | + 'host': 'localhost', |
| 64 | + 'port': 1883, |
| 65 | + 'topic': 'SunGather/12345678', |
| 66 | + 'username': None, |
| 67 | + 'password': None, |
| 68 | + 'homeassistant': False |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | +# Fixture: Mock InfluxDB export configuration |
| 73 | +@pytest.fixture |
| 74 | +def mock_influxdb_config(): |
| 75 | + """Standard InfluxDB export configuration for testing.""" |
| 76 | + return { |
| 77 | + 'name': 'influxdb', |
| 78 | + 'enabled': True, |
| 79 | + 'url': 'http://localhost:8086', |
| 80 | + 'token': 'test-token', |
| 81 | + 'org': 'test-org', |
| 82 | + 'bucket': 'sungather', |
| 83 | + 'measurements': [ |
| 84 | + {'register': 'total_active_power', 'point': 'power'}, |
| 85 | + {'register': 'battery_voltage', 'point': 'battery'} |
| 86 | + ] |
| 87 | + } |
| 88 | + |
| 89 | + |
| 90 | +# Fixture: Mock webserver export configuration |
| 91 | +@pytest.fixture |
| 92 | +def mock_webserver_config(): |
| 93 | + """Standard webserver export configuration for testing.""" |
| 94 | + return { |
| 95 | + 'name': 'webserver', |
| 96 | + 'enabled': True, |
| 97 | + 'port': 8080 |
| 98 | + } |
0 commit comments