Add test/style suite.

This commit is contained in:
Johan Bloemberg 2016-11-07 19:59:39 +01:00
parent 90eb6fb3fe
commit 4a82066144
No known key found for this signature in database
GPG Key ID: B1AE6948ED49BB55
6 changed files with 74 additions and 53 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.idea
*.pyc
.tox
.cache

View File

@ -1,7 +1,7 @@
import argparse
from dsmr_parser.serial import SERIAL_SETTINGS_V2_2, SERIAL_SETTINGS_V4, SerialReader
from dsmr_parser import telegram_specifications
from dsmr_parser.obis_references import P1_MESSAGE_TIMESTAMP
def console():
"""Output DSMR data to console."""
@ -14,8 +14,6 @@ def console():
args = parser.parse_args()
version = 'V' + args.version.replace('.', '_')
settings = {
'2.2': (SERIAL_SETTINGS_V2_2, telegram_specifications.V2_2),
'4': (SERIAL_SETTINGS_V4, telegram_specifications.V4),
@ -32,4 +30,3 @@ def console():
if obj:
print(obj.value, obj.unit)
print()

View File

@ -62,4 +62,3 @@ class SerialReader(object):
if is_end_of_telegram(line):
yield self.telegram_parser.parse(telegram)
telegram = []

View File

@ -1,6 +1,6 @@
from decimal import Decimal
from .obis_references import *
from . import obis_references as obis
from .parsers import CosemParser, ValueParser, MBusParser
from .value_types import timestamp
@ -14,53 +14,60 @@ how the telegram lines are parsed.
"""
V2_2 = {
EQUIPMENT_IDENTIFIER: CosemParser(ValueParser(str)),
ELECTRICITY_USED_TARIFF_1: CosemParser(ValueParser(Decimal)),
ELECTRICITY_USED_TARIFF_2: CosemParser(ValueParser(Decimal)),
ELECTRICITY_DELIVERED_TARIFF_1: CosemParser(ValueParser(Decimal)),
ELECTRICITY_DELIVERED_TARIFF_2: CosemParser(ValueParser(Decimal)),
ELECTRICITY_ACTIVE_TARIFF: CosemParser(ValueParser(str)),
CURRENT_ELECTRICITY_USAGE: CosemParser(ValueParser(Decimal)),
CURRENT_ELECTRICITY_DELIVERY: CosemParser(ValueParser(Decimal)),
ACTUAL_TRESHOLD_ELECTRICITY: CosemParser(ValueParser(Decimal)),
ACTUAL_SWITCH_POSITION: CosemParser(ValueParser(str)),
TEXT_MESSAGE_CODE: CosemParser(ValueParser(int)),
TEXT_MESSAGE: CosemParser(ValueParser(str)),
EQUIPMENT_IDENTIFIER_GAS: CosemParser(ValueParser(str)),
DEVICE_TYPE: CosemParser(ValueParser(str)),
VALVE_POSITION_GAS: CosemParser(ValueParser(str)),
obis.EQUIPMENT_IDENTIFIER: CosemParser(ValueParser(str)),
obis.ELECTRICITY_USED_TARIFF_1: CosemParser(ValueParser(Decimal)),
obis.ELECTRICITY_USED_TARIFF_2: CosemParser(ValueParser(Decimal)),
obis.ELECTRICITY_DELIVERED_TARIFF_1: CosemParser(ValueParser(Decimal)),
obis.ELECTRICITY_DELIVERED_TARIFF_2: CosemParser(ValueParser(Decimal)),
obis.ELECTRICITY_ACTIVE_TARIFF: CosemParser(ValueParser(str)),
obis.CURRENT_ELECTRICITY_USAGE: CosemParser(ValueParser(Decimal)),
obis.CURRENT_ELECTRICITY_DELIVERY: CosemParser(ValueParser(Decimal)),
obis.ACTUAL_TRESHOLD_ELECTRICITY: CosemParser(ValueParser(Decimal)),
obis.ACTUAL_SWITCH_POSITION: CosemParser(ValueParser(str)),
obis.TEXT_MESSAGE_CODE: CosemParser(ValueParser(int)),
obis.TEXT_MESSAGE: CosemParser(ValueParser(str)),
obis.EQUIPMENT_IDENTIFIER_GAS: CosemParser(ValueParser(str)),
obis.DEVICE_TYPE: CosemParser(ValueParser(str)),
obis.VALVE_POSITION_GAS: CosemParser(ValueParser(str)),
obis.GAS_METER_READING: MBusParser(
ValueParser(timestamp),
ValueParser(int),
ValueParser(int),
ValueParser(int),
ValueParser(str),
ValueParser(Decimal),
),
}
V4 = {
P1_MESSAGE_HEADER: CosemParser(ValueParser(str)),
P1_MESSAGE_TIMESTAMP: CosemParser(ValueParser(timestamp)),
ELECTRICITY_USED_TARIFF_1: CosemParser(ValueParser(Decimal)),
ELECTRICITY_USED_TARIFF_2: CosemParser(ValueParser(Decimal)),
ELECTRICITY_DELIVERED_TARIFF_1: CosemParser(ValueParser(Decimal)),
ELECTRICITY_DELIVERED_TARIFF_2: CosemParser(ValueParser(Decimal)),
ELECTRICITY_ACTIVE_TARIFF: CosemParser(ValueParser(str)),
EQUIPMENT_IDENTIFIER: CosemParser(ValueParser(str)),
CURRENT_ELECTRICITY_USAGE: CosemParser(ValueParser(Decimal)),
CURRENT_ELECTRICITY_DELIVERY: CosemParser(ValueParser(Decimal)),
LONG_POWER_FAILURE_COUNT: CosemParser(ValueParser(int)),
obis.P1_MESSAGE_HEADER: CosemParser(ValueParser(str)),
obis.P1_MESSAGE_TIMESTAMP: CosemParser(ValueParser(timestamp)),
obis.ELECTRICITY_USED_TARIFF_1: CosemParser(ValueParser(Decimal)),
obis.ELECTRICITY_USED_TARIFF_2: CosemParser(ValueParser(Decimal)),
obis.ELECTRICITY_DELIVERED_TARIFF_1: CosemParser(ValueParser(Decimal)),
obis.ELECTRICITY_DELIVERED_TARIFF_2: CosemParser(ValueParser(Decimal)),
obis.ELECTRICITY_ACTIVE_TARIFF: CosemParser(ValueParser(str)),
obis.EQUIPMENT_IDENTIFIER: CosemParser(ValueParser(str)),
obis.CURRENT_ELECTRICITY_USAGE: CosemParser(ValueParser(Decimal)),
obis.CURRENT_ELECTRICITY_DELIVERY: CosemParser(ValueParser(Decimal)),
obis.LONG_POWER_FAILURE_COUNT: CosemParser(ValueParser(int)),
# POWER_EVENT_FAILURE_LOG: ProfileGenericParser(), TODO
VOLTAGE_SAG_L1_COUNT: CosemParser(ValueParser(int)),
VOLTAGE_SAG_L2_COUNT: CosemParser(ValueParser(int)),
VOLTAGE_SAG_L3_COUNT: CosemParser(ValueParser(int)),
VOLTAGE_SWELL_L1_COUNT: CosemParser(ValueParser(int)),
VOLTAGE_SWELL_L2_COUNT: CosemParser(ValueParser(int)),
VOLTAGE_SWELL_L3_COUNT: CosemParser(ValueParser(int)),
TEXT_MESSAGE_CODE: CosemParser(ValueParser(int)),
TEXT_MESSAGE: CosemParser(ValueParser(str)),
DEVICE_TYPE: CosemParser(ValueParser(int)),
INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE: CosemParser(ValueParser(Decimal)),
INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE: CosemParser(ValueParser(Decimal)),
INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE: CosemParser(ValueParser(Decimal)),
INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE: CosemParser(ValueParser(Decimal)),
INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE: CosemParser(ValueParser(Decimal)),
INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE: CosemParser(ValueParser(Decimal)),
EQUIPMENT_IDENTIFIER_GAS: CosemParser(ValueParser(str)),
HOURLY_GAS_METER_READING: MBusParser(ValueParser(timestamp),
obis.VOLTAGE_SAG_L1_COUNT: CosemParser(ValueParser(int)),
obis.VOLTAGE_SAG_L2_COUNT: CosemParser(ValueParser(int)),
obis.VOLTAGE_SAG_L3_COUNT: CosemParser(ValueParser(int)),
obis.VOLTAGE_SWELL_L1_COUNT: CosemParser(ValueParser(int)),
obis.VOLTAGE_SWELL_L2_COUNT: CosemParser(ValueParser(int)),
obis.VOLTAGE_SWELL_L3_COUNT: CosemParser(ValueParser(int)),
obis.TEXT_MESSAGE_CODE: CosemParser(ValueParser(int)),
obis.TEXT_MESSAGE: CosemParser(ValueParser(str)),
obis.DEVICE_TYPE: CosemParser(ValueParser(int)),
obis.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE: CosemParser(ValueParser(Decimal)),
obis.INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE: CosemParser(ValueParser(Decimal)),
obis.INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE: CosemParser(ValueParser(Decimal)),
obis.INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE: CosemParser(ValueParser(Decimal)),
obis.INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE: CosemParser(ValueParser(Decimal)),
obis.INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE: CosemParser(ValueParser(Decimal)),
obis.EQUIPMENT_IDENTIFIER_GAS: CosemParser(ValueParser(str)),
obis.HOURLY_GAS_METER_READING: MBusParser(ValueParser(timestamp),
ValueParser(Decimal))
}

View File

@ -7,8 +7,8 @@ setup(
version='0.1',
packages=find_packages(),
install_requires=[
'pyserial==3.0.1',
'pytz==2016.3'
'pyserial>=3.2.1',
'pytz'
],
entry_points={
'console_scripts': ['dsmr_console=dsmr_parser.__main__:console']

16
tox.ini Normal file
View File

@ -0,0 +1,16 @@
[tox]
envlist = py35
[testenv]
deps=
pytest
pylama
commands=
py.test test {posargs}
pylama dsmr_parser test
[pylama:pylint]
max_line_length = 100
[pylama:pycodestyle]
max_line_length = 100