move StremPtr instances into Inverter class
This commit is contained in:
@@ -4,10 +4,24 @@ import asyncio
|
||||
|
||||
from itertools import count
|
||||
from mock import patch
|
||||
from app.src.async_stream import StreamPtr
|
||||
from app.src.async_stream import AsyncStream, AsyncIfcImpl
|
||||
from app.src.gen3.connection_g3 import ConnectionG3Server
|
||||
from app.src.gen3.talent import Talent
|
||||
|
||||
|
||||
class FakeInverter():
|
||||
async def async_publ_mqtt(self) -> None:
|
||||
pass # dummy funcion
|
||||
|
||||
async def async_create_remote(self, inv_prot: str, conn_class) -> None:
|
||||
pass # dummy function
|
||||
|
||||
def __init__ (self):
|
||||
self.remote = StreamPtr(None)
|
||||
self.local = StreamPtr(None)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def patch_async_init():
|
||||
with patch.object(AsyncStream, '__init__') as conn:
|
||||
@@ -71,8 +85,8 @@ def test_method_calls(patch_talent_init, patch_healthy, patch_async_close, patch
|
||||
writer = FakeWriter()
|
||||
id_str = "id_string"
|
||||
addr = ('proxy.local', 10000)
|
||||
conn = ConnectionG3Server(reader, writer, addr,
|
||||
rstream= None, id_str=id_str)
|
||||
conn = ConnectionG3Server(FakeInverter(), reader, writer, addr,
|
||||
id_str=id_str)
|
||||
assert 5 == conn._ifc.get_conn_no()
|
||||
spy2.assert_called_once_with(conn, True, conn._ifc, id_str)
|
||||
conn.healthy()
|
||||
|
||||
@@ -5,10 +5,23 @@ import asyncio
|
||||
from itertools import count
|
||||
from mock import patch
|
||||
from app.src.singleton import Singleton
|
||||
from app.src.async_stream import AsyncStream, AsyncIfcImpl
|
||||
from app.src.async_stream import AsyncStream, AsyncIfcImpl, StreamPtr
|
||||
from app.src.gen3plus.connection_g3p import ConnectionG3PServer
|
||||
from app.src.gen3plus.solarman_v5 import SolarmanV5
|
||||
|
||||
|
||||
class FakeInverter():
|
||||
async def async_publ_mqtt(self) -> None:
|
||||
pass # dummy funcion
|
||||
|
||||
async def async_create_remote(self, inv_prot: str, conn_class) -> None:
|
||||
pass # dummy function
|
||||
|
||||
def __init__ (self):
|
||||
self.remote = StreamPtr(None)
|
||||
self.local = StreamPtr(None)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def patch_async_init():
|
||||
with patch.object(AsyncStream, '__init__', return_value= None) as conn:
|
||||
@@ -76,8 +89,8 @@ def test_method_calls(patch_solarman_init, patch_healthy, patch_async_close, pat
|
||||
reader = FakeReader()
|
||||
writer = FakeWriter()
|
||||
addr = ('proxy.local', 10000)
|
||||
conn = ConnectionG3PServer(reader, writer, addr,
|
||||
rstream= None, client_mode=False)
|
||||
conn = ConnectionG3PServer(FakeInverter(), reader, writer, addr,
|
||||
client_mode=False)
|
||||
assert 5 == conn._ifc.get_conn_no()
|
||||
spy2.assert_called_once_with(conn, True, False, conn._ifc)
|
||||
conn.healthy()
|
||||
|
||||
@@ -104,18 +104,14 @@ def patch_open_connection():
|
||||
yield conn
|
||||
|
||||
|
||||
def test_method_calls(patch_conn_init, patch_conn_close):
|
||||
spy1 = patch_conn_init
|
||||
def test_method_calls(patch_conn_close):
|
||||
spy2 = patch_conn_close
|
||||
reader = FakeReader()
|
||||
writer = FakeWriter()
|
||||
addr = ('proxy.local', 10000)
|
||||
inverter = InverterG3(reader, writer, addr)
|
||||
inverter.l_addr = ''
|
||||
inverter.r_addr = ''
|
||||
|
||||
spy1.assert_called_once()
|
||||
spy1.assert_called_once_with(inverter, reader, writer, addr, None)
|
||||
assert inverter.local.stream
|
||||
assert inverter.local.ifc
|
||||
|
||||
inverter.close()
|
||||
spy2.assert_called_once()
|
||||
@@ -171,18 +167,19 @@ async def test_mqtt_publish(config_conn, patch_open_connection, patch_conn_close
|
||||
Inverter.class_init()
|
||||
|
||||
inverter = InverterG3(FakeReader(), FakeWriter(), ('proxy.local', 10000))
|
||||
stream = inverter.local.stream
|
||||
await inverter.async_publ_mqtt() # check call with invalid unique_id
|
||||
inverter._Talent__set_serial_no(serial_no= "123344")
|
||||
stream._Talent__set_serial_no(serial_no= "123344")
|
||||
|
||||
inverter.new_data['inverter'] = True
|
||||
inverter.db.db['inverter'] = {}
|
||||
stream.new_data['inverter'] = True
|
||||
stream.db.db['inverter'] = {}
|
||||
await inverter.async_publ_mqtt()
|
||||
assert inverter.new_data['inverter'] == False
|
||||
assert stream.new_data['inverter'] == False
|
||||
|
||||
inverter.new_data['env'] = True
|
||||
inverter.db.db['env'] = {}
|
||||
stream.new_data['env'] = True
|
||||
stream.db.db['env'] = {}
|
||||
await inverter.async_publ_mqtt()
|
||||
assert inverter.new_data['env'] == False
|
||||
assert stream.new_data['env'] == False
|
||||
|
||||
Infos.new_stat_data['proxy'] = True
|
||||
await inverter.async_publ_mqtt()
|
||||
@@ -203,12 +200,12 @@ async def test_mqtt_err(config_conn, patch_open_connection, patch_mqtt_err, patc
|
||||
Inverter.class_init()
|
||||
|
||||
inverter = InverterG3(FakeReader(), FakeWriter(), ('proxy.local', 10000))
|
||||
inverter._Talent__set_serial_no(serial_no= "123344")
|
||||
|
||||
inverter.new_data['inverter'] = True
|
||||
inverter.db.db['inverter'] = {}
|
||||
stream = inverter.local.stream
|
||||
stream._Talent__set_serial_no(serial_no= "123344")
|
||||
stream.new_data['inverter'] = True
|
||||
stream.db.db['inverter'] = {}
|
||||
await inverter.async_publ_mqtt()
|
||||
assert inverter.new_data['inverter'] == True
|
||||
assert stream.new_data['inverter'] == True
|
||||
|
||||
inverter.close()
|
||||
spy1.assert_called_once()
|
||||
@@ -225,12 +222,13 @@ async def test_mqtt_except(config_conn, patch_open_connection, patch_mqtt_except
|
||||
Inverter.class_init()
|
||||
|
||||
inverter = InverterG3(FakeReader(), FakeWriter(), ('proxy.local', 10000))
|
||||
inverter._Talent__set_serial_no(serial_no= "123344")
|
||||
stream = inverter.local.stream
|
||||
stream._Talent__set_serial_no(serial_no= "123344")
|
||||
|
||||
inverter.new_data['inverter'] = True
|
||||
inverter.db.db['inverter'] = {}
|
||||
stream.new_data['inverter'] = True
|
||||
stream.db.db['inverter'] = {}
|
||||
await inverter.async_publ_mqtt()
|
||||
assert inverter.new_data['inverter'] == True
|
||||
assert stream.new_data['inverter'] == True
|
||||
|
||||
inverter.close()
|
||||
spy1.assert_called_once()
|
||||
|
||||
@@ -105,18 +105,14 @@ def patch_open_connection():
|
||||
yield conn
|
||||
|
||||
|
||||
def test_method_calls(patch_conn_init, patch_conn_close):
|
||||
spy1 = patch_conn_init
|
||||
def test_method_calls(patch_conn_close):
|
||||
spy2 = patch_conn_close
|
||||
reader = FakeReader()
|
||||
writer = FakeWriter()
|
||||
addr = ('proxy.local', 10000)
|
||||
inverter = InverterG3P(reader, writer, addr, client_mode=False)
|
||||
inverter.l_addr = ''
|
||||
inverter.r_addr = ''
|
||||
|
||||
spy1.assert_called_once()
|
||||
spy1.assert_called_once_with(inverter, reader, writer, addr, None, client_mode=False)
|
||||
assert inverter.local.stream
|
||||
assert inverter.local.ifc
|
||||
|
||||
inverter.close()
|
||||
spy2.assert_called_once()
|
||||
@@ -172,18 +168,19 @@ async def test_mqtt_publish(config_conn, patch_open_connection, patch_conn_close
|
||||
Inverter.class_init()
|
||||
|
||||
inverter = InverterG3P(FakeReader(), FakeWriter(), ('proxy.local', 10000), client_mode=False)
|
||||
stream = inverter.local.stream
|
||||
await inverter.async_publ_mqtt() # check call with invalid unique_id
|
||||
inverter._SolarmanV5__set_serial_no(snr= 123344)
|
||||
stream._SolarmanV5__set_serial_no(snr= 123344)
|
||||
|
||||
inverter.new_data['inverter'] = True
|
||||
inverter.db.db['inverter'] = {}
|
||||
stream.new_data['inverter'] = True
|
||||
stream.db.db['inverter'] = {}
|
||||
await inverter.async_publ_mqtt()
|
||||
assert inverter.new_data['inverter'] == False
|
||||
assert stream.new_data['inverter'] == False
|
||||
|
||||
inverter.new_data['env'] = True
|
||||
inverter.db.db['env'] = {}
|
||||
stream.new_data['env'] = True
|
||||
stream.db.db['env'] = {}
|
||||
await inverter.async_publ_mqtt()
|
||||
assert inverter.new_data['env'] == False
|
||||
assert stream.new_data['env'] == False
|
||||
|
||||
Infos.new_stat_data['proxy'] = True
|
||||
await inverter.async_publ_mqtt()
|
||||
@@ -204,12 +201,12 @@ async def test_mqtt_err(config_conn, patch_open_connection, patch_mqtt_err, patc
|
||||
Inverter.class_init()
|
||||
|
||||
inverter = InverterG3P(FakeReader(), FakeWriter(), ('proxy.local', 10000), client_mode=False)
|
||||
inverter._SolarmanV5__set_serial_no(snr= 123344)
|
||||
|
||||
inverter.new_data['inverter'] = True
|
||||
inverter.db.db['inverter'] = {}
|
||||
stream = inverter.local.stream
|
||||
stream._SolarmanV5__set_serial_no(snr= 123344)
|
||||
stream.new_data['inverter'] = True
|
||||
stream.db.db['inverter'] = {}
|
||||
await inverter.async_publ_mqtt()
|
||||
assert inverter.new_data['inverter'] == True
|
||||
assert stream.new_data['inverter'] == True
|
||||
|
||||
inverter.close()
|
||||
spy1.assert_called_once()
|
||||
@@ -226,12 +223,13 @@ async def test_mqtt_except(config_conn, patch_open_connection, patch_mqtt_except
|
||||
Inverter.class_init()
|
||||
|
||||
inverter = InverterG3P(FakeReader(), FakeWriter(), ('proxy.local', 10000), client_mode=False)
|
||||
inverter._SolarmanV5__set_serial_no(snr= 123344)
|
||||
stream = inverter.local.stream
|
||||
stream._SolarmanV5__set_serial_no(snr= 123344)
|
||||
|
||||
inverter.new_data['inverter'] = True
|
||||
inverter.db.db['inverter'] = {}
|
||||
stream.new_data['inverter'] = True
|
||||
stream.db.db['inverter'] = {}
|
||||
await inverter.async_publ_mqtt()
|
||||
assert inverter.new_data['inverter'] == True
|
||||
assert stream.new_data['inverter'] == True
|
||||
|
||||
inverter.close()
|
||||
spy1.assert_called_once()
|
||||
|
||||
@@ -150,7 +150,8 @@ async def test_modbus_conn(patch_open):
|
||||
_ = patch_open
|
||||
assert Infos.stat['proxy']['Inverter_Cnt'] == 0
|
||||
|
||||
async with ModbusConn('test.local', 1234) as stream:
|
||||
async with ModbusConn('test.local', 1234) as inverter:
|
||||
stream = inverter.local.stream
|
||||
assert stream.node_id == 'G3P'
|
||||
assert stream.addr == ('test.local', 1234)
|
||||
assert type(stream._ifc._reader) is FakeReader
|
||||
|
||||
Reference in New Issue
Block a user