Merge branch 'feature/additional-testing' into develop
This commit is contained in:
commit
cca369df05
|
@ -190,4 +190,10 @@ Im Wiki liegen Konfig-Beispiele für Icinga2.
|
|||
|
||||
![Beispielhafte Icinga-Service-Ansocht](./doc/img/icinga-service-overview.png "Beispielhafte Icinga-Service-Ansicht")
|
||||
|
||||
Das wars.
|
||||
Das wars.
|
||||
|
||||
# Tests durchführen
|
||||
|
||||
Die Tests befinden sich in `src/test`. Für die Durchführung der Tests sind die zusätzlichen Abhängigkeiten aus `requirements-test.txt` erforderlich.
|
||||
|
||||
Zur Testausführung im Ordner `src` einfach `py.test --cov --cov-report term-missing --cov-config .coveragerc test/` aufrufen.
|
||||
|
|
|
@ -8,37 +8,37 @@ from rs500common.configuration import discover_config_file_by_name
|
|||
|
||||
|
||||
def test_discovery_file_in_folder(monkeypatch: MonkeyPatch):
|
||||
with monkeypatch.context() as m:
|
||||
with monkeypatch.context() as m: # type: MonkeyPatch
|
||||
m.setattr('os.path.isfile', lambda path: True)
|
||||
m.setattr('os.path.exists', lambda path: True)
|
||||
result = discover_config_file_by_name('test.ini', '/foo/bar')
|
||||
assert result == os.path.join('/foo/bar', 'test.ini')
|
||||
assert os.path.join('/foo/bar', 'test.ini') == result
|
||||
|
||||
|
||||
def test_discovery_via_env_var(monkeypatch: MonkeyPatch):
|
||||
with monkeypatch.context() as m:
|
||||
with monkeypatch.context() as m: # type: MonkeyPatch
|
||||
m.setenv('RS500_CONFIG_PATH', '/rs500_config_path/here/we/are')
|
||||
m.setattr('os.path.isfile', lambda path: True)
|
||||
m.setattr('os.path.exists', lambda path: True)
|
||||
result = discover_config_file_by_name('test.ini', script_dir=None)
|
||||
assert result == os.path.join('/rs500_config_path/here/we/are', 'test.ini')
|
||||
assert os.path.join('/rs500_config_path/here/we/are', 'test.ini') == result
|
||||
|
||||
|
||||
def test_discovery_via_user_home(monkeypatch: MonkeyPatch):
|
||||
with monkeypatch.context() as m:
|
||||
with monkeypatch.context() as m: # type: MonkeyPatch
|
||||
m.setattr('os.path.isfile', lambda path: True)
|
||||
m.setattr('os.path.exists', lambda path: True)
|
||||
monkeypatch.setattr(pathlib.Path, 'absolute', lambda x: '/user/home/path/test')
|
||||
result = discover_config_file_by_name('test.ini', script_dir=None)
|
||||
assert result == os.path.join('/user/home/path/test', '.rs500', 'test.ini')
|
||||
assert os.path.join('/user/home/path/test', '.rs500', 'test.ini') == result
|
||||
|
||||
|
||||
def test_discovery_in_etc(monkeypatch: MonkeyPatch):
|
||||
with monkeypatch.context() as m:
|
||||
with monkeypatch.context() as m: # type: MonkeyPatch
|
||||
m.setattr('os.path.isfile', lambda path: path.startswith('/etc'))
|
||||
m.setattr('os.path.exists', lambda path: path.startswith('/etc'))
|
||||
result = discover_config_file_by_name('test.ini')
|
||||
assert result == os.path.join('/etc', 'test.ini')
|
||||
assert os.path.join('/etc', 'test.ini') == result
|
||||
|
||||
|
||||
def test_no_hit():
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
import pytest
|
||||
|
||||
from rs500reader.do import Response, TempHum
|
||||
|
||||
|
||||
def test_response_object():
|
||||
r = Response()
|
||||
r.set_channel_data(1, TempHum(23.4, 52))
|
||||
r.set_channel_data(3, TempHum(-1.4, 25))
|
||||
r.set_channel_data(6, TempHum(0.1, 78))
|
||||
assert 23.4 == r.get_channel_data(1).temperature
|
||||
assert 52 == r.get_channel_data(1).humidity
|
||||
assert -1.4 == r.get_channel_data(3).temperature
|
||||
assert 25 == r.get_channel_data(3).humidity
|
||||
assert 0.1 == r.get_channel_data(6).temperature
|
||||
assert 78 == r.get_channel_data(6).humidity
|
||||
|
||||
|
||||
def test_invalid_channel_set():
|
||||
r = Response()
|
||||
r.set_channel_data(71, TempHum(0.5, 50))
|
||||
assert 0.5 == r.get_channel_data(71).temperature
|
||||
assert 50 == r.get_channel_data(71).humidity
|
||||
|
||||
|
||||
def test_none_fetch():
|
||||
r = Response()
|
||||
with pytest.raises(AttributeError):
|
||||
dummy = r.get_channel_data(1).humidity
|
||||
|
||||
|
||||
def test_get_all():
|
||||
th = TempHum(8.8, 76)
|
||||
r = Response()
|
||||
r.set_channel_data(2, th)
|
||||
assert {1: None, 2: th, 3: None, 4: None, 5: None, 6: None, 7: None, 8: None} == r.all
|
|
@ -0,0 +1,43 @@
|
|||
from typing import Sequence
|
||||
|
||||
import pytest
|
||||
|
||||
from rs500reader.do import TempHum
|
||||
|
||||
|
||||
@pytest.mark.parametrize('temp_from_protocol,expected_temp', [
|
||||
([0x00, 0x00], 0),
|
||||
([0xff, 0xff], -0.1),
|
||||
([0xff, 0xee], -1.8),
|
||||
([0xff, 0xe7], -2.5),
|
||||
([0x00, 0xcb], 20.3),
|
||||
([0x00, 0xff], 25.5),
|
||||
([0x7f, 0xff], 3276.7), # Protocol Dumbness
|
||||
])
|
||||
def test_temp_parser(temp_from_protocol: Sequence[int], expected_temp: float):
|
||||
obj = TempHum.from_protocol(temp_from_protocol, 0)
|
||||
assert expected_temp == obj.temperature
|
||||
|
||||
|
||||
@pytest.mark.parametrize('hum_from_protocol,expected_hum', [
|
||||
(0x00, 0),
|
||||
(0xff, 255), # Protocol Dumbness
|
||||
(0x01, 1),
|
||||
(0x35, 53),
|
||||
(0x34, 52),
|
||||
(0x28, 40),
|
||||
(0x2b, 43),
|
||||
])
|
||||
def test_hum_parser(hum_from_protocol: int, expected_hum: int):
|
||||
obj = TempHum.from_protocol([0, 0], hum_from_protocol)
|
||||
assert expected_hum == obj.humidity
|
||||
|
||||
|
||||
def test_setters():
|
||||
obj = TempHum.from_protocol([0, 0], 0)
|
||||
assert 0 == obj.humidity
|
||||
assert 0 == obj.temperature
|
||||
obj.temperature = 23.4
|
||||
obj.humidity = 53
|
||||
assert 23.4 == obj.temperature
|
||||
assert 53 == obj.humidity
|
Loading…
Reference in New Issue