forked from mhvis/solar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·86 lines (74 loc) · 2.85 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
from unittest.mock import Mock, MagicMock
import samil_upload
import configparser
import logging
import sys
def one_system_default(config):
config['DEFAULT'] = {'Status interval': '1', 'API key': 'a', 'System ID': 'a'}
def one_system_section(config):
config['DEFAULT'] = {'Status interval': '1'}
config['Sys'] = {'API key': 'a', 'System ID': 'a'}
def two_systems_combine(config):
config['DEFAULT'] = {'Status interval': '1'}
config['Sys1'] = {'API key': 'a', 'System ID': 'a'}
config['Sys2'] = {'API key': 'a', 'System ID': 'a'}
def two_systems_separate(config):
config['DEFAULT'] = {'Status interval': '1'}
config['One'] = {'API key': 'a', 'System ID': '1'}
config['Two'] = {'API key': 'a', 'System ID': '2'}
def three_systems_combine(config):
config['DEFAULT'] = {'Status interval': '1', 'API key': 'a', 'System ID': 'a'}
config['One'] = {}
config['Two'] = {}
config['Three'] = {}
def two_status_intervals(config):
config['DEFAULT'] = {'API key': 'a'}
config['One'] = {'System ID': '1', 'Status interval': '1'}
config['Two'] = {'System ID': '2', 'Status interval': '2'}
def ip_filter_apply(config):
config['DEFAULT'] = {'Status interval': '1', 'API key': 'a'}
config['System'] = {'System ID': 'a', 'IP address': '192.168.0.1'}
def ip_filter_no_apply(config):
config['DEFAULT'] = {'Status interval': '1', 'API key': 'a'}
config['System'] = {'System ID': 'a', 'IP address': '192.168.0.2'}
def interface_ip(config):
config['DEFAULT'] = {'Interface IP': '192.168.0.3', 'API key': 'a',
'System ID': 'a', 'Status interval': '1'}
def main(func):
config = configparser.ConfigParser()
func(config)
inverter = MagicMock()
inverter.return_value.__enter__.return_value.request_values.side_effect = [
{
'operating_mode': 'normal',
'energy_today': 0.9,
'output_power': 120,
'internal_temp': 18.0,
'grid_voltage': 220.0
},
{
'operating_mode': 'normal',
'energy_today': 1.1,
'output_power': 180,
'internal_temp': 22.0,
'grid_voltage': 240.0
},
{
'operating_mode': 'normal',
'energy_today': 1.1,
'output_power': 180,
'internal_temp': 22.0,
'grid_voltage': 240.0
}
]
inverter.return_value.__enter__.return_value.addr = ('192.168.0.1',)
#inverter.__enter__.return_value = inverter_instance
try:
samil_upload.main(config, inverter)
except KeyboardInterrupt:
pass
print(inverter.mock_calls)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
main(three_systems_combine)