{
"extension": ".py",
"source": "import unittest\n\nfrom decimal import Decimal\n\nfrom dsmr_parser.objects import MBusObject, 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_V2_2\n\n\nclass TelegramParserV2_2Test(unittest.TestCase):\n \"\"\" Test parsing of a DSMR v2.2 telegram. \"\"\"\n\n def test_parse(self):\n parser = TelegramParser(telegram_specifications.V2_2)\n try:\n result = parser.parse(TELEGRAM_V2_2, throw_ex=True)\n except Exception as ex:\n assert False, f\"parse trigged an exception {ex}\"\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('1.001')\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('1.001')\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('1.001')\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('1.001')\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 # EQUIPMENT_IDENTIFIER (0-0:96.1.1)\n assert isinstance(result[obis.EQUIPMENT_IDENTIFIER], CosemObject)\n assert result[obis.EQUIPMENT_IDENTIFIER].unit is None\n assert isinstance(result[obis.EQUIPMENT_IDENTIFIER].value, str)\n assert result[obis.EQUIPMENT_IDENTIFIER].value == '00000000000000'\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('1.01')\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')\n\n # TEXT_MESSAGE_CODE (0-0:96.13.1)\n assert isinstance(result[obis.TEXT_MESSAGE_CODE], CosemObject)\n assert result[obis.TEXT_MESSAGE_CODE].unit is None\n\n # TEXT_MESSAGE (0-0:96.13.0)\n assert isinstance(result[obis.TEXT_MESSAGE], CosemObject)\n assert result[obis.TEXT_MESSAGE].unit is None\n assert result[obis.TEXT_MESSAGE].value is None\n\n # DEVICE_TYPE (0-x:24.1.0)\n assert isinstance(result[obis.TEXT_MESSAGE], CosemObject)\n assert result[obis.DEVICE_TYPE].unit is None\n assert isinstance(result[obis.DEVICE_TYPE].value, str)\n assert result[obis.DEVICE_TYPE].value == '3'\n\n # EQUIPMENT_IDENTIFIER_GAS (0-x: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 == '000000000000'\n\n # GAS_METER_READING (0-1:24.3.0)\n assert isinstance(result[obis.GAS_METER_READING], MBusObject)\n assert result[obis.GAS_METER_READING].unit == 'm3'\n assert isinstance(result[obis.GAS_METER_READING].value, Decimal)\n assert result[obis.GAS_METER_READING].value == Decimal('1.001')\n",
"review": "**Grade: 8**\n\n## Bugs\n- No apparent bugs were found in the provided code.\n\n## Optimizations\n- Use `self.assertEqual()` and similar functions from `unittest` instead of `assert` for better test case reporting and compatibility with test runners.\n- Avoid using camelCase for class names in Python unless following a specific naming convention for imports.\n\n## Good points\n- Comprehensive test coverage of various fields in the DSMR telegram.\n- Use of `Decimal` for precise fixed-point arithmetic, ensuring accuracy of test assertions.\n- Good organization and readability of test cases with clear checks for both values and units.\n\n## Summary\nThe code is a unit test for parsing DSMR v2.2 telegrams. It checks the parsing of numerous fields using the `unittest` framework, ensuring parsed values match expected data. Replacing `assert` statements with `unittest` assert methods would improve readability and compatibility with test suite tools. No bugs were identified, and the tests are well-structured for clarity.\n\n## Open source alternatives\n- [dsmr_parser](https://github.com/ndokter/dsmr_parser): The provided test cases seem to be a part of this library which handles parsing of DSMR telegrams, implying it might offer similar functionalities for DSMR telegram parsing.",
"filename": "test_parse_v2_2.py",
"path": "test/test_parse_v2_2.py",
"directory": "test",
"grade": 8,
"size": 4845,
"line_count": 96
}