add descriptor unit test

This commit is contained in:
Bastian Schroll 2020-04-14 18:33:49 +02:00
parent 24f310e56f
commit 370ad5ac85
No known key found for this signature in database
GPG key ID: 0AE96912A20E9F5F
3 changed files with 71 additions and 1 deletions

View file

@ -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"

View file

@ -8,7 +8,7 @@
# by Bastian Schroll # by Bastian Schroll
[pytest] [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 # classic or progress
console_output_style = progress console_output_style = progress

View file

@ -30,3 +30,12 @@ list1:
- two - two
- three - three
- string1 - string1
descriptor_test:
- scanField: tone
descrField: description
descriptions:
- for: 12345
add: Test 12345
- for: 23456
add: Test 23456