From aa7c1832ef61a5cf62c3bce0c9d79ae721ffdc1c Mon Sep 17 00:00:00 2001 From: Stefan Allius Date: Fri, 27 Sep 2024 00:47:44 +0200 Subject: [PATCH] split ConnectionG3(P) in server and client class --- app/proxy.svg | 811 +++++++++++++++-------------- app/proxy.yuml | 28 +- app/src/gen3/connection_g3.py | 62 ++- app/src/gen3/inverter_g3.py | 14 +- app/src/gen3plus/connection_g3p.py | 65 +-- app/src/gen3plus/inverter_g3p.py | 15 +- app/tests/test_connection_g3.py | 6 +- app/tests/test_connection_g3p.py | 6 +- app/tests/test_inverter_g3.py | 8 +- app/tests/test_inverter_g3p.py | 8 +- 10 files changed, 548 insertions(+), 475 deletions(-) diff --git a/app/proxy.svg b/app/proxy.svg index b79e92e..240812f 100644 --- a/app/proxy.svg +++ b/app/proxy.svg @@ -4,504 +4,547 @@ - + G - + A0 - - - -You can stick notes -on diagrams too! + + + +You can stick notes +on diagrams too! A1 - -Mqtt -<<Singleton>> - -<static>ha_restarts -<static>__client -<static>__cb_MqttIsUp - -<async>publish() -<async>close() + +Mqtt +<<Singleton>> + +<static>ha_restarts +<static>__client +<static>__cb_MqttIsUp + +<async>publish() +<async>close() A2 - -Inverter - -cls.db_stat -cls.entity_prfx -cls.discovery_prfx -cls.proxy_node_id -cls.proxy_unique_id -cls.mqtt:Mqtt - + +Inverter + +cls.db_stat +cls.entity_prfx +cls.discovery_prfx +cls.proxy_node_id +cls.proxy_unique_id +cls.mqtt:Mqtt + A1->A2 - - - + + + A3 - -InverterG3 - -__ha_restarts - -async_create_remote() -async_publ_mqtt() -close() + +InverterG3 + +__ha_restarts + +async_create_remote() +async_publ_mqtt() +close() A2->A3 - - + + A4 - -InverterG3P - -__ha_restarts - -async_create_remote( -)async_publ_mqtt() -close() + +InverterG3P + +__ha_restarts + +async_create_remote( +)async_publ_mqtt() +close() A2->A4 - - + + A5 - -IterRegistry - - -__iter__ + +IterRegistry + + +__iter__ A6 - -Message - -server_side:bool -header_valid:bool -header_len:unsigned -data_len:unsigned -unique_id -node_id -sug_area -_recv_buffer:bytearray -_send_buffer:bytearray -_forward_buffer:bytearray -db:Infos -new_data:list -state - -_read():void<abstract> -close():void -inc_counter():void -dec_counter():void + +Message + +server_side:bool +header_valid:bool +header_len:unsigned +data_len:unsigned +unique_id +node_id +sug_area +_recv_buffer:bytearray +_send_buffer:bytearray +_forward_buffer:bytearray +db:Infos +new_data:list +state + +_read():void<abstract> +close():void +inc_counter():void +dec_counter():void A5->A6 - - + + - - -A17 - -Talent - -await_conn_resp_cnt -id_str -contact_name -contact_mail -db:InfosG3 -mb:Modbus -switch - -msg_contact_info() -msg_ota_update() -msg_get_time() -msg_collector_data() -msg_inverter_data() -msg_unknown() -close() + + +A21 + +Talent + +await_conn_resp_cnt +id_str +contact_name +contact_mail +db:InfosG3 +mb:Modbus +switch + +msg_contact_info() +msg_ota_update() +msg_get_time() +msg_collector_data() +msg_inverter_data() +msg_unknown() +close() - - -A6->A17 - - + + +A6->A21 + + - - -A18 - -SolarmanV5 - -control -serial -snr -db:InfosG3P -mb:Modbus -switch - -msg_unknown() -close() + + +A22 + +SolarmanV5 + +control +serial +snr +db:InfosG3P +mb:Modbus +switch + +msg_unknown() +close() - - -A6->A18 - - + + +A6->A22 + + A7 - -<<AsyncIfc>> - - -set_node_id() -get_conn_no() -tx_add() -tx_flush() -tx_get() -tx_peek() -tx_log() -tx_clear() -tx_len() -fwd_add() -fwd_flush() -fwd_log() -fwd_clear() -rx_get() -rx_peek() -rx_log() -rx_clear() -rx_len() -rx_set_cb() -prot_set_timeout_cb() + +<<AsyncIfc>> + + +set_node_id() +get_conn_no() +tx_add() +tx_flush() +tx_get() +tx_peek() +tx_log() +tx_clear() +tx_len() +fwd_add() +fwd_flush() +fwd_log() +fwd_clear() +rx_get() +rx_peek() +rx_log() +rx_clear() +rx_len() +rx_set_cb() +prot_set_timeout_cb() A8 - -AsyncIfcImpl - -fwd_fifo:ByteFifo -tx_fifo:ByteFifo -rx_fifo:ByteFifo -conn_no:Count -node_id -timeout_cb + +AsyncIfcImpl + +fwd_fifo:ByteFifo +tx_fifo:ByteFifo +rx_fifo:ByteFifo +conn_no:Count +node_id +timeout_cb A7->A8 - - + + A9 - -AsyncStream - -reader -writer -addr -r_addr -l_addr - -<async>loop -disc() -close() -healthy() -__async_read() -__async_write() -__async_forward() + +AsyncStream + +reader +writer +addr +r_addr +l_addr + +<async>loop +disc() +close() +healthy() +__async_read() +__async_write() +__async_forward() A8->A9 - - + + A10 - -AsyncStreamServer - -async_create_remote - -<async>server_loop() -<async>_async_forward() -<async>publish_outstanding_mqtt() -close() + +AsyncStreamServer + +async_create_remote + +<async>server_loop() +<async>_async_forward() +<async>publish_outstanding_mqtt() +close() A9->A10 - - + + A11 - -AsyncStreamClient - - -<async>client_loop() -<async>_async_forward()) + +AsyncStreamClient + + +<async>client_loop() +<async>_async_forward()) A9->A11 - - + + A12 - -ConnectionG3 - -remote.stream:ConnectionG3 - -healthy() -close() - - - -A12->A3 - - - - - -A12->A10 - - - -0..1 - - - -A12->A11 - - - -0..1 - - - -A12->A12 - - -0..1 -has + +ConnectionG3 + +remote.stream:ConnectionG3 + +healthy() A13 - -ConnectionG3P - -remote.stream:ConnectionG3P - -healthy() -close() + +ConnectionG3Client - - -A13->A4 - - - - - -A13->A10 - - - -0..1 - - - -A13->A11 - - - -0..1 - - - -A13->A13 - - -0..1 -has + + +A12->A13 + + A14 - -Infos - -stat -new_stat_data -info_dev - -static_init() -dev_value() -inc_counter() -dec_counter() -ha_proxy_conf -ha_conf -ha_remove -update_db -set_db_def_value -get_db_value -ignore_this_device + +ConnectionG3Server + + + +A12->A14 + + + + + +A13->A3 + + + + + +A13->A11 + + + +1 + + + +A14->A3 + + + + + +A14->A10 + + + +1 A15 - -InfosG3 - - -ha_confs() -parse() - - - -A14->A15 - - + +ConnectionG3P + +remote.stream:ConnectionG3P + +healthy() +close() A16 - -InfosG3P - - -ha_confs() -parse() + +ConnectionG3PClient - + + +A15->A16 + + + + + +A17 + +ConnectionG3PServer + + + +A15->A17 + + + + + +A16->A4 + + + + -A14->A16 - - +A16->A11 + + + +1 - - -A17->A7 - - -use - - + -A17->A12 - - +A17->A4 + + - - -A17->A15 - - + + +A17->A10 + + + +1 - - -A18->A7 - - -use - - - -A18->A13 - - - - - -A18->A16 - - + + +A18 + +Infos + +stat +new_stat_data +info_dev + +static_init() +dev_value() +inc_counter() +dec_counter() +ha_proxy_conf +ha_conf +ha_remove +update_db +set_db_def_value +get_db_value +ignore_this_device A19 - -Modbus - -que -snd_handler -rsp_handler -timeout -max_retires -last_xxx -err -retry_cnt -req_pend -tim - -build_msg() -recv_req() -recv_resp() -close() + +InfosG3 + + +ha_confs() +parse() - - -A19->A17 - - -has -1 - - - -A19->A18 - - -has -1 + + +A18->A19 + + A20 + +InfosG3P + + +ha_confs() +parse() + + + +A18->A20 + + + + + +A21->A7 + + +use + + + +A21->A12 + + + + + +A21->A19 + + + + + +A22->A7 + + +use + + + +A22->A15 + + + + + +A22->A20 + + + + + +A23 + +Modbus + +que +snd_handler +rsp_handler +timeout +max_retires +last_xxx +err +retry_cnt +req_pend +tim + +build_msg() +recv_req() +recv_resp() +close() + + + +A23->A21 + + +has +1 + + + +A23->A22 + + +has +1 + + + +A24 ModbusConn @@ -511,13 +554,13 @@ stream:InverterG3P - - -A20->A4 - - -1 -has + + +A24->A4 + + +1 +has diff --git a/app/proxy.yuml b/app/proxy.yuml index b9f25e4..af14779 100644 --- a/app/proxy.yuml +++ b/app/proxy.yuml @@ -23,16 +23,26 @@ [AsyncStream]<-[AsyncStreamClient] -[ConnectionG3|remote.stream:ConnectionG3|healthy();close()] -[ConnectionG3]^[InverterG3] -[ConnectionG3]has-0..1>[ConnectionG3] -[ConnectionG3]++-0..1>[AsyncStreamClient] -[ConnectionG3]++-0..1>[AsyncStreamServer] +[ConnectionG3|remote.stream:ConnectionG3|healthy()] +[ConnectionG3]^[ConnectionG3Client] +[ConnectionG3]^[ConnectionG3Server] +[ConnectionG3Client|remote.stream:ConnectionG3|close()] +[ConnectionG3Client]^[InverterG3] +[ConnectionG3Client]++-1>[AsyncStreamClient] +[ConnectionG3Server|remote.stream:ConnectionG3|;close()] +[ConnectionG3Server]^[InverterG3] +[ConnectionG3Server]++-1>[AsyncStreamServer] + [ConnectionG3P|remote.stream:ConnectionG3P|healthy();close()] -[ConnectionG3P]^[InverterG3P] -[ConnectionG3P]has-0..1>[ConnectionG3P] -[ConnectionG3P]++-0..1>[AsyncStreamClient] -[ConnectionG3P]++-0..1>[AsyncStreamServer] +[ConnectionG3P]^[ConnectionG3PClient] +[ConnectionG3P]^[ConnectionG3PServer] + +[ConnectionG3PClient|remote.stream:ConnectionG3P|close()] +[ConnectionG3PClient]^[InverterG3P] +[ConnectionG3PClient]++-1>[AsyncStreamClient] +[ConnectionG3PServer|remote.stream:ConnectionG3P|;close()] +[ConnectionG3PServer]^[InverterG3P] +[ConnectionG3PServer]++-1>[AsyncStreamServer] [Infos|stat;new_stat_data;info_dev|static_init();dev_value();inc_counter();dec_counter();ha_proxy_conf;ha_conf;ha_remove;update_db;set_db_def_value;get_db_value;ignore_this_device] [Infos]^[InfosG3||ha_confs();parse()] diff --git a/app/src/gen3/connection_g3.py b/app/src/gen3/connection_g3.py index 933c35b..8e431c4 100644 --- a/app/src/gen3/connection_g3.py +++ b/app/src/gen3/connection_g3.py @@ -14,32 +14,6 @@ logger = logging.getLogger('conn') class ConnectionG3(Talent): - - def __init__(self, reader: StreamReader, writer: StreamWriter, - addr, rstream: 'ConnectionG3', server_side: bool, - id_str=b'') -> None: - self.remote = StreamPtr(rstream) - if server_side: - self._ifc = AsyncStreamServer(reader, writer, addr, - self.async_publ_mqtt, - self.async_create_remote, - self.remote) - else: - self._ifc = AsyncStreamClient(reader, writer, addr, - self.remote) - Talent.__init__(self, server_side, self._ifc, id_str) - - self.conn_no = self._ifc.get_conn_no() - self.addr = addr - - ''' - Our puplic methods - ''' - def close(self): - self._ifc.close() - Talent.close(self) - # logger.info(f'AsyncStream refs: {gc.get_referrers(self)}') - async def async_create_remote(self) -> None: pass # virtual interface # pragma: no cover @@ -49,3 +23,39 @@ class ConnectionG3(Talent): def healthy(self) -> bool: logger.debug('ConnectionG3 healthy()') return self._ifc.healthy() + + def close(self): + self._ifc.close() + Talent.close(self) + # logger.info(f'AsyncStream refs: {gc.get_referrers(self)}') + + +class ConnectionG3Server(ConnectionG3): + + def __init__(self, reader: StreamReader, writer: StreamWriter, + addr, rstream: 'ConnectionG3Client', + id_str=b'') -> None: + + server_side = True + self.remote = StreamPtr(rstream) + self._ifc = AsyncStreamServer(reader, writer, addr, + self.async_publ_mqtt, + self.async_create_remote, + self.remote) + self.conn_no = self._ifc.get_conn_no() + self.addr = addr + Talent.__init__(self, server_side, self._ifc, id_str) + + +class ConnectionG3Client(ConnectionG3): + + def __init__(self, reader: StreamReader, writer: StreamWriter, + addr, rstream: 'ConnectionG3Server', + id_str=b'') -> None: + server_side = False + self.remote = StreamPtr(rstream) + self._ifc = AsyncStreamClient(reader, writer, addr, + self.remote) + self.conn_no = self._ifc.get_conn_no() + self.addr = addr + Talent.__init__(self, server_side, self._ifc, id_str) diff --git a/app/src/gen3/inverter_g3.py b/app/src/gen3/inverter_g3.py index 48c70ad..f2483e7 100644 --- a/app/src/gen3/inverter_g3.py +++ b/app/src/gen3/inverter_g3.py @@ -8,19 +8,21 @@ from aiomqtt import MqttCodeError if __name__ == "app.src.gen3.inverter_g3": from app.src.config import Config from app.src.inverter import Inverter - from app.src.gen3.connection_g3 import ConnectionG3 + from app.src.gen3.connection_g3 import ConnectionG3Server + from app.src.gen3.connection_g3 import ConnectionG3Client from app.src.infos import Infos else: # pragma: no cover from config import Config from inverter import Inverter - from gen3.connection_g3 import ConnectionG3 + from gen3.connection_g3 import ConnectionG3Server + from gen3.connection_g3 import ConnectionG3Client from infos import Infos logger_mqtt = logging.getLogger('mqtt') -class InverterG3(Inverter, ConnectionG3): +class InverterG3(Inverter, ConnectionG3Server): '''class Inverter is a derivation of an Async_Stream The class has some class method for managing common resources like a @@ -51,7 +53,7 @@ class InverterG3(Inverter, ConnectionG3): ''' def __init__(self, reader: StreamReader, writer: StreamWriter, addr): - super().__init__(reader, writer, addr, None, True) + super().__init__(reader, writer, addr, None) self.__ha_restarts = -1 self.addr = addr @@ -66,8 +68,8 @@ class InverterG3(Inverter, ConnectionG3): logging.info(f'[{self.node_id}] Connect to {addr}') connect = asyncio.open_connection(host, port) reader, writer = await connect - self.remote.stream = ConnectionG3(reader, writer, addr, self, - False, self.id_str) + self.remote.stream = ConnectionG3Client(reader, writer, addr, self, + self.id_str) logging.info(f'[{self.remote.stream.node_id}:' f'{self.remote.stream.conn_no}] ' f'Connected to {addr}') diff --git a/app/src/gen3plus/connection_g3p.py b/app/src/gen3plus/connection_g3p.py index 8e486ae..2fcf1bb 100644 --- a/app/src/gen3plus/connection_g3p.py +++ b/app/src/gen3plus/connection_g3p.py @@ -14,35 +14,6 @@ logger = logging.getLogger('conn') class ConnectionG3P(SolarmanV5): - - def __init__(self, reader: StreamReader, writer: StreamWriter, - addr, rstream: 'ConnectionG3P', - server_side: bool, - client_mode: bool) -> None: - - self.remote = StreamPtr(rstream) - if server_side: - self._ifc = AsyncStreamServer(reader, writer, addr, - self.async_publ_mqtt, - self.async_create_remote, - self.remote) - else: - self._ifc = AsyncStreamClient(reader, writer, addr, - self.remote) - - SolarmanV5.__init__(self, server_side, client_mode, self._ifc) - - self.conn_no = self._ifc.get_conn_no() - self.addr = addr - - ''' - Our puplic methods - ''' - def close(self): - self._ifc.close() - SolarmanV5.close(self) - # logger.info(f'AsyncStream refs: {gc.get_referrers(self)}') - async def async_create_remote(self) -> None: pass # virtual interface # pragma: no cover @@ -52,3 +23,39 @@ class ConnectionG3P(SolarmanV5): def healthy(self) -> bool: logger.debug('ConnectionG3P healthy()') return self._ifc.healthy() + + def close(self): + self._ifc.close() + SolarmanV5.close(self) + # logger.info(f'AsyncStream refs: {gc.get_referrers(self)}') + + +class ConnectionG3PServer(ConnectionG3P): + + def __init__(self, reader: StreamReader, writer: StreamWriter, + addr, rstream: 'ConnectionG3PClient', + client_mode: bool) -> None: + + server_side = True + self.remote = StreamPtr(rstream) + self._ifc = AsyncStreamServer(reader, writer, addr, + self.async_publ_mqtt, + self.async_create_remote, + self.remote) + self.conn_no = self._ifc.get_conn_no() + self.addr = addr + SolarmanV5.__init__(self, server_side, client_mode, self._ifc) + + +class ConnectionG3PClient(ConnectionG3P): + + def __init__(self, reader: StreamReader, writer: StreamWriter, + addr, rstream: 'ConnectionG3PServer') -> None: + + server_side = False + client_mode = False + self.remote = StreamPtr(rstream) + self._ifc = AsyncStreamClient(reader, writer, addr, self.remote) + self.conn_no = self._ifc.get_conn_no() + self.addr = addr + SolarmanV5.__init__(self, server_side, client_mode, self._ifc) diff --git a/app/src/gen3plus/inverter_g3p.py b/app/src/gen3plus/inverter_g3p.py index be32fe1..2c9bca7 100644 --- a/app/src/gen3plus/inverter_g3p.py +++ b/app/src/gen3plus/inverter_g3p.py @@ -8,19 +8,21 @@ from aiomqtt import MqttCodeError if __name__ == "app.src.gen3plus.inverter_g3p": from app.src.config import Config from app.src.inverter import Inverter - from app.src.gen3plus.connection_g3p import ConnectionG3P + from app.src.gen3plus.connection_g3p import ConnectionG3PServer + from app.src.gen3plus.connection_g3p import ConnectionG3PClient from app.src.infos import Infos else: # pragma: no cover from config import Config from inverter import Inverter - from gen3plus.connection_g3p import ConnectionG3P + from gen3plus.connection_g3p import ConnectionG3PServer + from gen3plus.connection_g3p import ConnectionG3PClient from infos import Infos logger_mqtt = logging.getLogger('mqtt') -class InverterG3P(Inverter, ConnectionG3P): +class InverterG3P(Inverter, ConnectionG3PServer): '''class Inverter is a derivation of an Async_Stream The class has some class method for managing common resources like a @@ -53,7 +55,7 @@ class InverterG3P(Inverter, ConnectionG3P): def __init__(self, reader: StreamReader, writer: StreamWriter, addr, client_mode: bool = False): super().__init__(reader, writer, addr, None, - server_side=True, client_mode=client_mode) + client_mode=client_mode) self.__ha_restarts = -1 self.addr = addr @@ -68,9 +70,8 @@ class InverterG3P(Inverter, ConnectionG3P): logging.info(f'[{self.node_id}] Connect to {addr}') connect = asyncio.open_connection(host, port) reader, writer = await connect - self.remote.stream = ConnectionG3P(reader, writer, addr, self, - server_side=False, - client_mode=False) + self.remote.stream = ConnectionG3PClient(reader, writer, + addr, self) logging.info(f'[{self.remote.stream.node_id}:' f'{self.remote.stream.conn_no}] ' f'Connected to {addr}') diff --git a/app/tests/test_connection_g3.py b/app/tests/test_connection_g3.py index b7282e7..e182560 100644 --- a/app/tests/test_connection_g3.py +++ b/app/tests/test_connection_g3.py @@ -5,7 +5,7 @@ import asyncio from itertools import count from mock import patch from app.src.async_stream import AsyncStream, AsyncIfcImpl -from app.src.gen3.connection_g3 import ConnectionG3 +from app.src.gen3.connection_g3 import ConnectionG3Server from app.src.gen3.talent import Talent @pytest.fixture @@ -71,8 +71,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 = ConnectionG3(reader, writer, addr, - rstream= None, server_side=True, id_str=id_str) + conn = ConnectionG3Server(reader, writer, addr, + rstream= None, id_str=id_str) assert 5 == conn._ifc.get_conn_no() spy2.assert_called_once_with(conn, True, conn._ifc, id_str) conn.healthy() diff --git a/app/tests/test_connection_g3p.py b/app/tests/test_connection_g3p.py index 60aac30..85ed802 100644 --- a/app/tests/test_connection_g3p.py +++ b/app/tests/test_connection_g3p.py @@ -6,7 +6,7 @@ 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.gen3plus.connection_g3p import ConnectionG3P +from app.src.gen3plus.connection_g3p import ConnectionG3PServer from app.src.gen3plus.solarman_v5 import SolarmanV5 @pytest.fixture @@ -76,8 +76,8 @@ def test_method_calls(patch_solarman_init, patch_healthy, patch_async_close, pat reader = FakeReader() writer = FakeWriter() addr = ('proxy.local', 10000) - conn = ConnectionG3P(reader, writer, addr, - rstream= None, server_side=True, client_mode=False) + conn = ConnectionG3PServer(reader, writer, addr, + rstream= None, client_mode=False) assert 5 == conn._ifc.get_conn_no() spy2.assert_called_once_with(conn, True, False, conn._ifc) conn.healthy() diff --git a/app/tests/test_inverter_g3.py b/app/tests/test_inverter_g3.py index 762659a..b4bec04 100644 --- a/app/tests/test_inverter_g3.py +++ b/app/tests/test_inverter_g3.py @@ -8,7 +8,7 @@ from app.src.infos import Infos from app.src.config import Config from app.src.inverter import Inverter from app.src.singleton import Singleton -from app.src.gen3.connection_g3 import ConnectionG3 +from app.src.gen3.connection_g3 import ConnectionG3Server from app.src.gen3.inverter_g3 import InverterG3 from app.tests.test_modbus_tcp import patch_mqtt_err, patch_mqtt_except, test_port, test_hostname @@ -44,12 +44,12 @@ def module_init(): @pytest.fixture def patch_conn_init(): - with patch.object(ConnectionG3, '__init__', return_value= None) as conn: + with patch.object(ConnectionG3Server, '__init__', return_value= None) as conn: yield conn @pytest.fixture def patch_conn_close(): - with patch.object(ConnectionG3, 'close') as conn: + with patch.object(ConnectionG3Server, 'close') as conn: yield conn class FakeReader(): @@ -115,7 +115,7 @@ def test_method_calls(patch_conn_init, patch_conn_close): inverter.r_addr = '' spy1.assert_called_once() - spy1.assert_called_once_with(reader, writer, addr, None, True) + spy1.assert_called_once_with(reader, writer, addr, None) inverter.close() spy2.assert_called_once() diff --git a/app/tests/test_inverter_g3p.py b/app/tests/test_inverter_g3p.py index 26e50ae..0a4946e 100644 --- a/app/tests/test_inverter_g3p.py +++ b/app/tests/test_inverter_g3p.py @@ -8,7 +8,7 @@ from app.src.infos import Infos from app.src.config import Config from app.src.inverter import Inverter from app.src.singleton import Singleton -from app.src.gen3plus.connection_g3p import ConnectionG3P +from app.src.gen3plus.connection_g3p import ConnectionG3PServer from app.src.gen3plus.inverter_g3p import InverterG3P from app.tests.test_modbus_tcp import patch_mqtt_err, patch_mqtt_except, test_port, test_hostname @@ -45,12 +45,12 @@ def module_init(): @pytest.fixture def patch_conn_init(): - with patch.object(ConnectionG3P, '__init__', return_value= None) as conn: + with patch.object(ConnectionG3PServer, '__init__', return_value= None) as conn: yield conn @pytest.fixture def patch_conn_close(): - with patch.object(ConnectionG3P, 'close') as conn: + with patch.object(ConnectionG3PServer, 'close') as conn: yield conn class FakeReader(): @@ -116,7 +116,7 @@ def test_method_calls(patch_conn_init, patch_conn_close): inverter.r_addr = '' spy1.assert_called_once() - spy1.assert_called_once_with(reader, writer, addr, None, server_side=True, client_mode=False) + spy1.assert_called_once_with(reader, writer, addr, None, client_mode=False) inverter.close() spy2.assert_called_once()