mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2025-12-06 07:12:04 +01:00
add descriptor unit test
This commit is contained in:
parent
24f310e56f
commit
370ad5ac85
61
test/module/test_descriptor.py
Normal file
61
test/module/test_descriptor.py
Normal 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"
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
Loading…
Reference in a new issue