all tests are written using unittest.TestCase now
This commit is contained in:
parent
9d8cad8b46
commit
3b43cbf841
@ -1,9 +1,7 @@
|
|||||||
"""Test DSMR serial protocol."""
|
"""Test DSMR serial protocol."""
|
||||||
|
import unittest
|
||||||
from unittest.mock import Mock
|
from unittest.mock import Mock
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from dsmr_parser import obis_references as obis
|
from dsmr_parser import obis_references as obis
|
||||||
from dsmr_parser import telegram_specifications
|
from dsmr_parser import telegram_specifications
|
||||||
from dsmr_parser.parsers import TelegramParserV2_2
|
from dsmr_parser.parsers import TelegramParserV2_2
|
||||||
@ -34,25 +32,23 @@ TELEGRAM_V2_2 = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
class ProtocolTest(unittest.TestCase):
|
||||||
def protocol():
|
|
||||||
"""DSMRprotocol instance with mocked telegram_callback."""
|
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
parser = TelegramParserV2_2
|
parser = TelegramParserV2_2
|
||||||
specification = telegram_specifications.V2_2
|
specification = telegram_specifications.V2_2
|
||||||
|
|
||||||
telegram_parser = parser(specification)
|
telegram_parser = parser(specification)
|
||||||
return DSMRProtocol(None, telegram_parser,
|
self.protocol = DSMRProtocol(None, telegram_parser,
|
||||||
telegram_callback=Mock())
|
telegram_callback=Mock())
|
||||||
|
|
||||||
|
def test_complete_packet(self):
|
||||||
def test_complete_packet(protocol):
|
|
||||||
"""Protocol should assemble incoming lines into complete packet."""
|
"""Protocol should assemble incoming lines into complete packet."""
|
||||||
|
|
||||||
for line in TELEGRAM_V2_2:
|
for line in TELEGRAM_V2_2:
|
||||||
protocol.data_received(bytes(line + '\r\n', 'ascii'))
|
self.protocol.data_received(bytes(line + '\r\n', 'ascii'))
|
||||||
|
|
||||||
telegram = protocol.telegram_callback.call_args_list[0][0][0]
|
telegram = self.protocol.telegram_callback.call_args_list[0][0][0]
|
||||||
assert isinstance(telegram, dict)
|
assert isinstance(telegram, dict)
|
||||||
|
|
||||||
assert float(telegram[obis.CURRENT_ELECTRICITY_USAGE].value) == 1.01
|
assert float(telegram[obis.CURRENT_ELECTRICITY_USAGE].value) == 1.01
|
||||||
|
Loading…
Reference in New Issue
Block a user