11 lines
11 KiB
JSON
11 lines
11 KiB
JSON
|
{
|
||
|
"extension": ".py",
|
||
|
"source": "import unittest\n\nfrom decimal import Decimal\n\nfrom dsmr_parser.exceptions import InvalidChecksumError, ParseError\nfrom dsmr_parser.objects import CosemObject\nfrom dsmr_parser.parsers import TelegramParser\nfrom dsmr_parser import telegram_specifications\nfrom dsmr_parser import obis_references as obis\nfrom test.example_telegrams import TELEGRAM_ISKRA_IE\n\n\nclass TelegramParserIskraIETest(unittest.TestCase):\n \"\"\" Test parsing of a Iskra IE5 telegram. \"\"\"\n\n def test_parse(self):\n parser = TelegramParser(telegram_specifications.ISKRA_IE)\n try:\n result = parser.parse(TELEGRAM_ISKRA_IE, throw_ex=True)\n except Exception as ex:\n assert False, f\"parse trigged an exception {ex}\"\n\n # EQUIPMENT_IDENTIFIER_GAS (0-0:96.1.0)\n assert isinstance(result[obis.EQUIPMENT_IDENTIFIER_GAS], CosemObject)\n assert result[obis.EQUIPMENT_IDENTIFIER_GAS].unit is None\n assert isinstance(result[obis.EQUIPMENT_IDENTIFIER_GAS].value, str)\n assert result[obis.EQUIPMENT_IDENTIFIER_GAS].value == '09610'\n\n # ELECTRICITY_USED_TARIFF_1 (1-0:1.8.1)\n assert isinstance(result[obis.ELECTRICITY_USED_TARIFF_1], CosemObject)\n assert result[obis.ELECTRICITY_USED_TARIFF_1].unit == 'kWh'\n assert isinstance(result[obis.ELECTRICITY_USED_TARIFF_1].value, Decimal)\n assert result[obis.ELECTRICITY_USED_TARIFF_1].value == Decimal('10.181')\n\n # ELECTRICITY_USED_TARIFF_2 (1-0:1.8.2)\n assert isinstance(result[obis.ELECTRICITY_USED_TARIFF_2], CosemObject)\n assert result[obis.ELECTRICITY_USED_TARIFF_2].unit == 'kWh'\n assert isinstance(result[obis.ELECTRICITY_USED_TARIFF_2].value, Decimal)\n assert result[obis.ELECTRICITY_USED_TARIFF_2].value == Decimal('10.182')\n\n # ELECTRICITY_DELIVERED_TARIFF_1 (1-0:2.8.1)\n assert isinstance(result[obis.ELECTRICITY_DELIVERED_TARIFF_1], CosemObject)\n assert result[obis.ELECTRICITY_DELIVERED_TARIFF_1].unit == 'kWh'\n assert isinstance(result[obis.ELECTRICITY_DELIVERED_TARIFF_1].value, Decimal)\n assert result[obis.ELECTRICITY_DELIVERED_TARIFF_1].value == Decimal('10.281')\n\n # ELECTRICITY_DELIVERED_TARIFF_2 (1-0:2.8.2)\n assert isinstance(result[obis.ELECTRICITY_DELIVERED_TARIFF_2], CosemObject)\n assert result[obis.ELECTRICITY_DELIVERED_TARIFF_2].unit == 'kWh'\n assert isinstance(result[obis.ELECTRICITY_DELIVERED_TARIFF_2].value, Decimal)\n assert result[obis.ELECTRICITY_DELIVERED_TARIFF_2].value == Decimal('10.282')\n\n # ELECTRICITY_ACTIVE_TARIFF (0-0:96.14.0)\n assert isinstance(result[obis.ELECTRICITY_ACTIVE_TARIFF], CosemObject)\n assert result[obis.ELECTRICITY_ACTIVE_TARIFF].unit is None\n assert isinstance(result[obis.ELECTRICITY_ACTIVE_TARIFF].value, str)\n assert result[obis.ELECTRICITY_ACTIVE_TARIFF].value == '0001'\n\n # CURRENT_ELECTRICITY_USAGE (1-0:1.7.0)\n assert isinstance(result[obis.CURRENT_ELECTRICITY_USAGE], CosemObject)\n assert result[obis.CURRENT_ELECTRICITY_USAGE].unit == 'kW'\n assert isinstance(result[obis.CURRENT_ELECTRICITY_USAGE].value, Decimal)\n assert result[obis.CURRENT_ELECTRICITY_USAGE].value == Decimal('0.170')\n\n # CURRENT_ELECTRICITY_DELIVERY (1-0:2.7.0)\n assert isinstance(result[obis.CURRENT_ELECTRICITY_DELIVERY], CosemObject)\n assert result[obis.CURRENT_ELECTRICITY_DELIVERY].unit == 'kW'\n assert isinstance(result[obis.CURRENT_ELECTRICITY_DELIVERY].value, Decimal)\n assert result[obis.CURRENT_ELECTRICITY_DELIVERY].value == Decimal('0.270')\n\n # INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE (1-0:21.7.0)\n assert isinstance(result[obis.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE], CosemObject)\n assert result[obis.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE].unit == 'kW'\n assert isinstance(result[obis.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE].value, Decimal)\n assert result[obis.INSTANTANEOUS_ACTIVE_POWER_
|
||
|
"review": "# 8\n\n## Bugs\n- No significant bugs identified in the test code.\n\n## Optimizations\n- Use `self.assertIsInstance` and `self.assertEqual` instead of `assert` statements for better test framework integration.\n- Consider using `setUp` method to initialize common variables to reduce repetition.\n- Group similar assertions together for better readability and performance where possible.\n\n## Good points\n- The code is well-structured and highly readable.\n- Comprehensive test coverage for various scenarios including valid parsing and checksum cases as well as invalid ones.\n- Use of specific exceptions (`InvalidChecksumError`, `ParseError`) enhances clarity and debugging.\n- Efficient use of the `unittest` framework for structured testing.\n\n## Summary\nThe code is a well-developed test suite for the `TelegramParser` class related to parsing Iskra IE5 telegrams. It effectively checks both normal and edge cases, including parsing and validation operations. Optimization could be done by using more features from the `unittest` module to standardize and simplify assertion checks, thereby improving maintainability.\n\n## Open source alternatives\n- **PyDSM**: A Python library providing an interface for reading DSMR telegrams, capturing similar functionality.\n- **dsmr-parser-python**: Another Python parser specifically designed for DSMR telegrams, very similar to the approach used here.",
|
||
|
"filename": "test_parse_iskra_ie.py",
|
||
|
"path": "test/test_parse_iskra_ie.py",
|
||
|
"directory": "test",
|
||
|
"grade": 8,
|
||
|
"size": 9825,
|
||
|
"line_count": 178
|
||
|
}
|