all tests are written using unittest.TestCase now

This commit is contained in:
Nigel Dokter 2017-01-04 19:55:54 +01:00
parent 9d8cad8b46
commit 3b43cbf841

View File

@ -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,29 +32,27 @@ TELEGRAM_V2_2 = [
] ]
@pytest.fixture class ProtocolTest(unittest.TestCase):
def protocol():
"""DSMRprotocol instance with mocked telegram_callback."""
parser = TelegramParserV2_2 def setUp(self):
specification = telegram_specifications.V2_2 parser = TelegramParserV2_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):
"""Protocol should assemble incoming lines into complete packet."""
def test_complete_packet(protocol): for line in TELEGRAM_V2_2:
"""Protocol should assemble incoming lines into complete packet.""" self.protocol.data_received(bytes(line + '\r\n', 'ascii'))
for line in TELEGRAM_V2_2: telegram = self.protocol.telegram_callback.call_args_list[0][0][0]
protocol.data_received(bytes(line + '\r\n', 'ascii')) assert isinstance(telegram, dict)
telegram = protocol.telegram_callback.call_args_list[0][0][0] assert float(telegram[obis.CURRENT_ELECTRICITY_USAGE].value) == 1.01
assert isinstance(telegram, dict) assert telegram[obis.CURRENT_ELECTRICITY_USAGE].unit == 'kW'
assert float(telegram[obis.CURRENT_ELECTRICITY_USAGE].value) == 1.01 assert float(telegram[obis.GAS_METER_READING].value) == 1.001
assert telegram[obis.CURRENT_ELECTRICITY_USAGE].unit == 'kW' 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'