diff --git a/test/module/test_descriptor.py b/test/module/test_descriptor.py new file mode 100644 index 0000000..c064170 --- /dev/null +++ b/test/module/test_descriptor.py @@ -0,0 +1,61 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +"""! + ____ ____ ______ __ __ __ _____ + / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / + / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < + / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / +/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ + German BOS Information Script + by Bastian Schroll + +@file: test_descriptor.py +@date: 14.04.2020 +@author: Bastian Schroll +@description: Unittests for BOSWatch. File have to run as "pytest" unittest +""" +# problem of the pytest fixtures +# pylint: disable=redefined-outer-name +import logging +import pytest +from boswatch.utils import paths + +from boswatch.configYaml import ConfigYAML +from boswatch.packet import Packet +from module.descriptor import BoswatchModule as Descriptor + + +def setup_method(method): + logging.debug("[TEST] %s.%s", method.__module__, method.__name__) + + +@pytest.fixture +def makeDescriptor(): + config = ConfigYAML() + assert config.loadConfigFile(paths.TEST_PATH + "test_config.yaml") is True + descriptor = Descriptor(config.get("descriptor_test")) + return descriptor + + +@pytest.fixture +def makePacket(): + packet = Packet() + return packet + + +def test_descriptorFoundFirst(makeDescriptor, makePacket): + makePacket.set("tone", "12345") + makePacket = makeDescriptor.doWork(makePacket) + assert makePacket.get("description") == "Test 12345" + + +def test_descriptorFoundSecond(makeDescriptor, makePacket): + makePacket.set("tone", "23456") + makePacket = makeDescriptor.doWork(makePacket) + assert makePacket.get("description") == "Test 23456" + + +def test_descriptorNotFound(makeDescriptor, makePacket): + makePacket.set("tone", "99999") + makePacket = makeDescriptor.doWork(makePacket) + assert makePacket.get("description") == "99999" diff --git a/test/pytest.ini b/test/pytest.ini index 6e8fc02..e5d4311 100644 --- a/test/pytest.ini +++ b/test/pytest.ini @@ -8,7 +8,7 @@ # by Bastian Schroll [pytest] -addopts = -v --pep8 --flakes --cov=boswatch/ --cov-report=term-missing --log-level=CRITICAL +addopts = -v --pep8 --flakes --cov=boswatch/ --cov=module/ --cov plugin/ --cov-report=term-missing --log-level=CRITICAL # classic or progress console_output_style = progress diff --git a/test/test_config.yaml b/test/test_config.yaml index 6840f26..f20f454 100644 --- a/test/test_config.yaml +++ b/test/test_config.yaml @@ -30,3 +30,12 @@ list1: - two - three - string1 + +descriptor_test: + - scanField: tone + descrField: description + descriptions: + - for: 12345 + add: Test 12345 + - for: 23456 + add: Test 23456 \ No newline at end of file