Skip to content

Commit

Permalink
Improve code coverage
Browse files Browse the repository at this point in the history
(and fix a bug in Parameters if ´index == 0´)
  • Loading branch information
gerw committed Jul 21, 2023
1 parent 67440ce commit 602db34
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion luxtronik/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ def __init__(self, safe=True):
def set(self, target, value):
"""Set parameter to new value."""
index, parameter = self._lookup(target, with_index=True)
if index:
if index is not None:
if parameter.writeable or not self.safe:
self.queue[index] = parameter.to_heatpump(value)
else:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_calculations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Test suite for parameters module"""

# pylint: disable=too-few-public-methods

from luxtronik.calculations import Calculations


class TestCalculations:
"""Test suite for Calculations"""

def test_init(self):
"""Test cases for initialization"""
calculations = Calculations()
assert calculations.name == "Calculation"
39 changes: 39 additions & 0 deletions tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ def test__lookup(self):
assert parameters._lookup("0", True) == (0, p0)
assert parameters._lookup(s, True) == (0, p0)

# Look for a name which does not exist
s = "ID_BarFoo"
assert parameters._lookup(s, True)[0] is None

# Look for something which is not an int and not a string
j = 0.0
assert parameters._lookup(j) is None

def test_parse(self):
"""Test cases for _parse"""
parameters = Parameters()
Expand All @@ -53,3 +58,37 @@ def test_parse(self):
p = parameters.get(n)

assert p.name == f"Unknown_Parameter_{n}"

def test___iter__(self):
"""Test cases for __iter__"""
parameters = Parameters()

for i, p in parameters:
if i == 0:
assert p.name == "ID_Transfert_LuxNet"
elif i == 1:
assert p.name == "ID_Einst_WK_akt"
else:
break

def test_set(self):
"""Test cases for set"""
parameters = Parameters()

# Set something which does not exist
parameters.set("BarFoo", 0)
assert len(parameters.queue) == 0

# Set something which is not allowed to be set
parameters.set("ID_Transfert_LuxNet", 0)
assert len(parameters.queue) == 0

# Set something which is allowed to be set
parameters.set("ID_Einst_WK_akt", 0)
assert len(parameters.queue) == 1

parameters = Parameters(safe=False)

# Set something which is not allowed to be set, but we are brave.
parameters.set("ID_Transfert_LuxNet", 0)
assert len(parameters.queue) == 1
14 changes: 14 additions & 0 deletions tests/test_visibilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Test suite for parameters module"""

# pylint: disable=too-few-public-methods

from luxtronik.visibilities import Visibilities


class TestVisibilities:
"""Test suite for Visibilities"""

def test_init(self):
"""Test cases for initialization"""
visibilities = Visibilities()
assert visibilities.name == "Visibility"

0 comments on commit 602db34

Please sign in to comment.