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."""
|
||||
|
||||
import unittest
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
from dsmr_parser import obis_references as obis
|
||||
from dsmr_parser import telegram_specifications
|
||||
from dsmr_parser.parsers import TelegramParserV2_2
|
||||
@ -34,29 +32,27 @@ TELEGRAM_V2_2 = [
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def protocol():
|
||||
"""DSMRprotocol instance with mocked telegram_callback."""
|
||||
class ProtocolTest(unittest.TestCase):
|
||||
|
||||
parser = TelegramParserV2_2
|
||||
specification = telegram_specifications.V2_2
|
||||
def setUp(self):
|
||||
parser = TelegramParserV2_2
|
||||
specification = telegram_specifications.V2_2
|
||||
|
||||
telegram_parser = parser(specification)
|
||||
return DSMRProtocol(None, telegram_parser,
|
||||
telegram_callback=Mock())
|
||||
telegram_parser = parser(specification)
|
||||
self.protocol = DSMRProtocol(None, telegram_parser,
|
||||
telegram_callback=Mock())
|
||||
|
||||
def test_complete_packet(self):
|
||||
"""Protocol should assemble incoming lines into complete packet."""
|
||||
|
||||
def test_complete_packet(protocol):
|
||||
"""Protocol should assemble incoming lines into complete packet."""
|
||||
for line in TELEGRAM_V2_2:
|
||||
self.protocol.data_received(bytes(line + '\r\n', 'ascii'))
|
||||
|
||||
for line in TELEGRAM_V2_2:
|
||||
protocol.data_received(bytes(line + '\r\n', 'ascii'))
|
||||
telegram = self.protocol.telegram_callback.call_args_list[0][0][0]
|
||||
assert isinstance(telegram, dict)
|
||||
|
||||
telegram = protocol.telegram_callback.call_args_list[0][0][0]
|
||||
assert isinstance(telegram, dict)
|
||||
assert float(telegram[obis.CURRENT_ELECTRICITY_USAGE].value) == 1.01
|
||||
assert telegram[obis.CURRENT_ELECTRICITY_USAGE].unit == 'kW'
|
||||
|
||||
assert float(telegram[obis.CURRENT_ELECTRICITY_USAGE].value) == 1.01
|
||||
assert telegram[obis.CURRENT_ELECTRICITY_USAGE].unit == 'kW'
|
||||
|
||||
assert float(telegram[obis.GAS_METER_READING].value) == 1.001
|
||||
assert telegram[obis.GAS_METER_READING].unit == 'm3'
|
||||
assert float(telegram[obis.GAS_METER_READING].value) == 1.001
|
||||
assert telegram[obis.GAS_METER_READING].unit == 'm3'
|
||||
|
Loading…
Reference in New Issue
Block a user