Project skeleton
Some checks failed
HACS Validation / validate (push) Failing after 38s
Validate with hassfest / validate (push) Failing after 41s

This commit is contained in:
Adrian Rumpold
2025-04-07 10:17:40 +02:00
commit 5180992e98
23 changed files with 3302 additions and 0 deletions

42
tests/test_units.py Normal file
View File

@@ -0,0 +1,42 @@
import pytest
from pv_microinverter.units import Dimension, SIUnit
def test_siunit_parse_base_unit():
unit = SIUnit.parse("W")
# Check that parsing base unit returns the registered unit
assert unit.name == "Watt"
assert unit.symbol == "W"
assert unit.factor == 1
def test_siunit_parse_prefixed_unit():
unit = SIUnit.parse("kW")
# The expected unit is created by prefix "k" and the base unit "Watt"
assert unit.name == "kWatt"
assert unit.symbol == "kW"
assert unit.factor == 1000 # 1e3 multiplier
def test_dimension_parse_valid():
# Parsing a valid dimension string should succeed
dim = Dimension.parse("3.5 kW")
assert dim.value == "3.5"
# Check unit attributes from SIUnit.parse
assert dim.unit.name == "kWatt"
assert dim.unit.symbol == "kW"
# Check conversion to base unit: 3.5 * 1000 = 3500.0
assert dim.to_base_unit() == 3500.0
def test_dimension_parse_invalid_format():
# Missing space between value and unit should raise a ValueError
with pytest.raises(ValueError):
Dimension.parse("3.5kW")
def test_siunit_parse_unknown_unit():
# Attempting to parse an unknown unit should raise a ValueError
with pytest.raises(ValueError):
SIUnit.parse("invalid")