Merge branch 'develop' into build_docs

This commit is contained in:
Bastian Schroll 2020-04-18 15:29:34 +02:00 committed by GitHub
commit 7478597b87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 91 additions and 6 deletions

View file

@ -6,25 +6,29 @@ jobs:
build:
strategy:
max-parallel: 3
matrix:
os: [ubuntu-latest]
python-version: [3.5, 3.6, 3.7]
python-version: [3.5, 3.6, 3.7, 3.8]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{matrix.python-version}} at ${{matrix.os}}
uses: actions/setup-python@v1
with:
python-version: ${{matrix.python-version}}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
mkdir log/
- name: Test with pytest
run: |
pytest -c 'test/pytest.ini'
- name: Save artifacts
uses: actions/upload-artifact@master
with:

View file

@ -42,10 +42,10 @@ class BoswatchModule(ModuleBase):
@param bwPacket: A BOSWatch packet instance"""
for descriptor in self.config:
if not bwPacket.get(descriptor.get("scanField")):
break # scanField is not available in this packet
bwPacket.set(descriptor.get("descrField"), bwPacket.get(descriptor.get("scanField")))
for description in descriptor.get("descriptions"):
if not bwPacket.get(descriptor.get("scanField")):
break # scanField is not available in this packet
bwPacket.set(descriptor.get("descrField"), description.get("for"))
if str(description.get("for")) == bwPacket.get(descriptor.get("scanField")):
logging.debug("Description '%s' added in packet field '%s'",
description.get("add"), descriptor.get("descrField"))

View file

@ -0,0 +1,72 @@
#!/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():
"""!Build a descriptor object with loaded configuration"""
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():
"""!Build a BW Packet object"""
packet = Packet()
return packet
def test_descriptorFoundFirst(makeDescriptor, makePacket):
"""!Run descriptor on the first entry in list"""
makePacket.set("tone", "12345")
makePacket = makeDescriptor.doWork(makePacket)
assert makePacket.get("description") == "Test 12345"
def test_descriptorFoundSecond(makeDescriptor, makePacket):
"""!Run descriptor on the second entry in list"""
makePacket.set("tone", "23456")
makePacket = makeDescriptor.doWork(makePacket)
assert makePacket.get("description") == "Test 23456"
def test_descriptorNotFound(makeDescriptor, makePacket):
"""!Run descriptor no matching data found"""
makePacket.set("tone", "99999")
makePacket = makeDescriptor.doWork(makePacket)
assert makePacket.get("description") == "99999"
def test_descriptorScanFieldNotAvailable(makeDescriptor, makePacket):
"""!Run descriptor on a non existent scanField"""
makePacket = makeDescriptor.doWork(makePacket)
assert makePacket.get("description") is None

View file

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

View file

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