* Code Cleanup (#158) * print coverage report * create sonar-project property file * install all py dependencies in one step * code cleanup * reduce cognitive complexity * do not build on *.yml changes * optimise versionstring handling (#159) - Reading the version string from the image updates it even if the image is re-pulled without re-deployment * fix linter warning * exclude *.pyi filese * ignore some rules for tests * cleanup (#160) * Sonar qube 3 (#163) fix SonarQube warnings in modbus.py * Sonar qube 3 (#164) * fix SonarQube warnings * Sonar qube 3 (#165) * cleanup * Add support for TSUN Titan inverter Fixes #161 * fix SonarQube warnings * fix error * rename field "config" * SonarQube reads flake8 output * don't stop on flake8 errors * flake8 scan only app/src for SonarQube * update flake8 run * ignore flake8 C901 * cleanup * fix linter warnings * ignore changed *.yml files * read sensor list solarman data packets * catch 'No route to' error and log only in debug mode * fix unit tests * add sensor_list configuration * adapt unit tests * fix SonarQube warnings * Sonar qube 3 (#166) * add unittests for mqtt.py * add mock * move test requirements into a file * fix unit tests * fix formating * initial version * fix SonarQube warning * Sonar qube 4 (#169) * add unit test for inverter.py * fix SonarQube warning * Sonar qube 5 (#170) * fix SonarLints warnings * use random IP adresses for unit tests * Docker: The description ist missing (#171) Fixes #167 * S allius/issue167 (#172) * cleanup * Sonar qube 6 (#174) * test class ModbusConn * Sonar qube 3 (#178) * add more unit tests * GEN3: don't crash on overwritten msg in the receive buffer * improve test coverage und reduce test delays * reduce cognitive complexity * fix merge * fix merge conflikt * fix merge conflict * S allius/issue182 (#183) * GEN3: After inverter firmware update the 'Unknown Msg Type' increases continuously Fixes #182 * add support for Controller serial no and MAC * test hardening * GEN3: add support for new messages of version 3 firmwares * bump libraries to latest versions - bump aiomqtt to version 2.3.0 - bump aiohttp to version 3.10.5 * improve test coverage * reduce cognective complexity * fix target preview * remove dubbled fixtures * increase test coverage * Update README.md (#185) update badges * S allius/issue186 (#187) * Parse more values in Server Mode Fixes #186 * read OUTPUT_COEFFICIENT and MAC_ADDR in SrvMode * fix unit test * increase test coverage * S allius/issue186 (#188) * increase test coverage * update changelog * add dokumentation * change default config * Update README.md (#189) Config file is now foldable
85 lines
2.1 KiB
Python
85 lines
2.1 KiB
Python
# test_with_pytest.py
|
|
import pytest
|
|
import asyncio
|
|
|
|
from mock import patch
|
|
from app.src.async_stream import AsyncStream
|
|
from app.src.gen3.connection_g3 import ConnectionG3
|
|
from app.src.gen3.talent import Talent
|
|
|
|
@pytest.fixture
|
|
def patch_async_init():
|
|
with patch.object(AsyncStream, '__init__') as conn:
|
|
yield conn
|
|
|
|
@pytest.fixture
|
|
def patch_talent_init():
|
|
with patch.object(Talent, '__init__') as conn:
|
|
yield conn
|
|
|
|
@pytest.fixture
|
|
def patch_healthy():
|
|
with patch.object(AsyncStream, 'healthy') as conn:
|
|
yield conn
|
|
|
|
@pytest.fixture
|
|
def patch_async_close():
|
|
with patch.object(AsyncStream, 'close') as conn:
|
|
yield conn
|
|
|
|
@pytest.fixture
|
|
def patch_talent_close():
|
|
with patch.object(Talent, 'close') as conn:
|
|
yield conn
|
|
|
|
class FakeReader():
|
|
def __init__(self):
|
|
self.on_recv = asyncio.Event()
|
|
async def read(self, max_len: int):
|
|
await self.on_recv.wait()
|
|
return b''
|
|
def feed_eof(self):
|
|
return
|
|
|
|
|
|
class FakeWriter():
|
|
def write(self, buf: bytes):
|
|
return
|
|
def get_extra_info(self, sel: str):
|
|
if sel == 'peername':
|
|
return 'remote.intern'
|
|
elif sel == 'sockname':
|
|
return 'sock:1234'
|
|
assert False
|
|
def is_closing(self):
|
|
return False
|
|
def close(self):
|
|
return
|
|
async def wait_closed(self):
|
|
return
|
|
|
|
|
|
|
|
def test_method_calls(patch_async_init, patch_talent_init, patch_healthy, patch_async_close, patch_talent_close):
|
|
spy1 = patch_async_init
|
|
spy2 = patch_talent_init
|
|
spy3 = patch_healthy
|
|
spy4 = patch_async_close
|
|
spy5 = patch_talent_close
|
|
reader = FakeReader()
|
|
writer = FakeWriter()
|
|
id_str = "id_string"
|
|
addr = ('proxy.local', 10000)
|
|
conn = ConnectionG3(reader, writer, addr,
|
|
remote_stream= None, server_side=True, id_str=id_str)
|
|
spy1.assert_called_once_with(conn, reader, writer, addr)
|
|
spy2.assert_called_once_with(conn, True, id_str)
|
|
conn.healthy()
|
|
|
|
spy3.assert_called_once()
|
|
|
|
conn.close()
|
|
spy4.assert_called_once()
|
|
spy5.assert_called_once()
|
|
|