cleaned up based on pylama complaints / pinpointed to coverage version 4.5.4 as next version is incompatible

This commit is contained in:
Hans Erik van Elburg 2020-02-02 22:12:25 +01:00
parent fee3f696c4
commit b6537678a7
8 changed files with 67 additions and 75 deletions

View File

@ -9,6 +9,7 @@ from dsmr_parser.parsers import TelegramParser
logger = logging.getLogger(__name__)
class FileReader(object):
"""
Filereader to read and parse raw telegram strings from a file and instantiate Telegram objects
@ -74,6 +75,7 @@ class FileReader(object):
except ParseError as e:
logger.error('Failed to parse telegram: %s', e)
class FileInputReader(object):
"""
Filereader to read and parse raw telegram strings from stdin or files specified at the commandline
@ -163,8 +165,7 @@ class FileTailReader(object):
for telegram in self.telegram_buffer.get_all():
try:
yield Telegram(telegram, self.telegram_parser, self.telegram_specification)
except dsmr_parser.exceptions.InvalidChecksumError as e:
except InvalidChecksumError as e:
logger.warning(str(e))
except dsmr_parser.exceptions.ParseError as e:
except ParseError as e:
logger.error('Failed to parse telegram: %s', e)

View File

@ -59,6 +59,7 @@ def create_tcp_dsmr_reader(host, port, dsmr_version,
conn = loop.create_connection(protocol, host, port)
return conn
class DSMRProtocol(asyncio.Protocol):
"""Assemble and handle incoming data into complete DSM telegrams."""

View File

@ -1,5 +1,6 @@
import dsmr_parser.obis_name_mapping
class Telegram(object):
"""
Container for raw and parsed telegram data.

View File

@ -3,7 +3,7 @@ import re
from ctypes import c_ushort
from dsmr_parser.objects import MBusObject, CosemObject, Telegram
from dsmr_parser.objects import MBusObject, CosemObject
from dsmr_parser.exceptions import ParseError, InvalidChecksumError
logger = logging.getLogger(__name__)

View File

@ -1,11 +1,5 @@
from decimal import Decimal
import datetime
import unittest
import pytz
from dsmr_parser import obis_references as obis
from dsmr_parser import telegram_specifications
from dsmr_parser.exceptions import InvalidChecksumError, ParseError
from dsmr_parser.objects import CosemObject, MBusObject, Telegram
from dsmr_parser.objects import Telegram
from dsmr_parser.parsers import TelegramParser
from example_telegrams import TELEGRAM_V4_2
parser = TelegramParser(telegram_specifications.V4)

View File

@ -1,30 +1,21 @@
from decimal import Decimal
import datetime
import unittest
import pytz
from dsmr_parser import obis_references as obis
from dsmr_parser import telegram_specifications
from dsmr_parser.exceptions import InvalidChecksumError, ParseError
from dsmr_parser.objects import CosemObject, MBusObject, Telegram
from dsmr_parser.objects import CosemObject
from dsmr_parser.objects import Telegram
from dsmr_parser.parsers import TelegramParser
from test.example_telegrams import TELEGRAM_V4_2
class TelegramTest(unittest.TestCase):
""" Test instantiation of Telegram object """
def test_instantiate(self):
parser = TelegramParser(telegram_specifications.V4)
#result = parser.parse(TELEGRAM_V4_2)
telegram = Telegram(TELEGRAM_V4_2, parser, telegram_specifications.V4)
# P1_MESSAGE_HEADER (1-3:0.2.8)
#assert isinstance(result[obis.P1_MESSAGE_HEADER], CosemObject)
#assert result[obis.P1_MESSAGE_HEADER].unit is None
#assert isinstance(result[obis.P1_MESSAGE_HEADER].value, str)
#assert result[obis.P1_MESSAGE_HEADER].value == '50'
testitem = telegram.P1_MESSAGE_HEADER
assert isinstance(testitem, CosemObject)
assert testitem.unit is None
assert testitem.value == '42'

12
tox.ini
View File

@ -1,5 +1,6 @@
[tox]
envlist = py34,py35,p36
envlist = py34,py35,py36,py37
requires = coverage<=4.5.4
[testenv]
deps=
@ -14,10 +15,13 @@ commands=
pylama dsmr_parser test
[pylama:dsmr_parser/clients/__init__.py]
ignore = W0611,W0605
ignore = W0611
[pylama:dsmr_parser/parsers.py]
ignore = W605
[pylama:pylint]
max_line_length = 100
max_line_length = 120
[pylama:pycodestyle]
max_line_length = 100
max_line_length = 120