From bda92764318ce28ebffdc46c60c38d63294c9828 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Thu, 4 Jan 2018 22:24:55 +0100 Subject: [PATCH] add pytest and his config incl. first tests --- _config/pytest.ini | 19 ++++++++ boswatch/__init__.py | 0 boswatch/utils/__init__.py | 0 boswatch/utils/header.py | 89 ++++++++++++++++++++++++++++++++++++++ pytest.bat | 42 ++++++++++++++++++ test/__init__.py | 0 test/test_header.py | 36 +++++++++++++++ 7 files changed, 186 insertions(+) create mode 100644 _config/pytest.ini create mode 100644 boswatch/__init__.py create mode 100644 boswatch/utils/__init__.py create mode 100644 boswatch/utils/header.py create mode 100644 pytest.bat create mode 100644 test/__init__.py create mode 100644 test/test_header.py diff --git a/_config/pytest.ini b/_config/pytest.ini new file mode 100644 index 0000000..18cfcfe --- /dev/null +++ b/_config/pytest.ini @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# ____ ____ ______ __ __ __ _____ +# / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / +# / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < +# / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / +#/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ +# German BOS Information Script +# by Bastian Schroll + +[pytest] +log_file=logs/test.log +log_file_level=debug +log_file_format=%(asctime)s - %(module)-12s %(funcName)-15s [%(levelname)-8s] %(message)s +log_file_date_format=%d.%m.%Y %H:%M:%S + +#pep8 plugin +pep8ignore = E402, E501 # import not at top +# E501 # line too long +# pep8maxlinelength = 99 \ No newline at end of file diff --git a/boswatch/__init__.py b/boswatch/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/boswatch/utils/__init__.py b/boswatch/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/boswatch/utils/header.py b/boswatch/utils/header.py new file mode 100644 index 0000000..1461672 --- /dev/null +++ b/boswatch/utils/header.py @@ -0,0 +1,89 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +"""! + ____ ____ ______ __ __ __ _____ + / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / + / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < + / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / +/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ + German BOS Information Script + by Bastian Schroll + +@file: header.py +@date: 11.12.2017 +@author: Bastian Schroll +@description: Prints the BOSWatch Header on Screen or logfile +""" +import logging +import platform # for python version nr + +import boswatch.version + + +def logoToLog(): + """!Prints the BOSWatch logo to the log at debug level + + @return True or False on error""" + try: + logging.debug(" ____ ____ ______ __ __ __ _____ ") + logging.debug(" / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / ") + logging.debug(" / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < ") + logging.debug(" / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / ") + logging.debug("/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ ") + logging.debug(" German BOS Information Script ") + logging.debug(" by Bastian Schroll ") + logging.debug("") + return True + except: # pragma: no cover + logging.exception("cannot display logo in log") + return False + + +def infoToLog(): + """!Prints the BOSWatch and OS information to log at debug level + + @return True or False on error""" + try: + logging.debug("BOSWatch and environment information") + logging.debug("> Client version: %d.%d.%d", + boswatch.version.client["major"], + boswatch.version.client["minor"], + boswatch.version.client["patch"]) + logging.debug("> Server version: %d.%d.%d", + boswatch.version.server["major"], + boswatch.version.server["minor"], + boswatch.version.server["patch"]) + logging.debug("> Branch: %s", + boswatch.version.branch) + logging.debug("> Release date: %02d.%02d.%4d", + boswatch.version.date["day"], + boswatch.version.date["month"], + boswatch.version.date["year"]) + logging.debug("> Python version: " + platform.python_version()) + logging.debug("> Python build: " + str(platform.python_build())) + logging.debug("> System: " + platform.system()) + logging.debug("> OS Version: " + platform.platform()) + logging.debug("") + return True + except: # pragma: no cover + logging.exception("cannot display OS information") + return False + + +def logoToScreen(): + """!Prints the BOSWatch logo to the screen at debug level + + @return True or False on error""" + try: + print(" ____ ____ ______ __ __ __ _____ ") + print(" / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / ") + print(" / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < ") + print(" / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / ") + print("/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ ") + print(" German BOS Information Script ") + print(" by Bastian Schroll ") + print("") + return True + except: # pragma: no cover + logging.exception("cannot display logo on screen") + return False diff --git a/pytest.bat b/pytest.bat new file mode 100644 index 0000000..d6fdfed --- /dev/null +++ b/pytest.bat @@ -0,0 +1,42 @@ +@echo off + +echo " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " +echo " ____ ____ ______ __ __ __ _____ " +echo " / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / " +echo " / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < " +echo " / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / " +echo " /_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ " +echo " German BOS Information Script " +echo " by Bastian Schroll " +echo " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " +echo. +echo BOSWatch 3 Unittest framework +echo. +echo Which test? [ENTER] for all +echo Or name a specific test test_[###].py +echo. + +set /p test=Testcase: +if "%test%" == "" ( + goto start +) else ( + goto start_spec +) + +:start +echo. +python -m pytest -c "_config/pytest.ini" -v --pep8 --cov --cov-report=term-missing +echo. +echo --- Hit any key to repeat --- +pause +cls +goto start + +:start_spec +echo. +python -m pytest test/test_%test%.py -c "_config/pytest.ini" -v --pep8 --cov --cov-report=term-missing +echo. +echo --- Hit any key to repeat --- +pause +cls +goto start_spec diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_header.py b/test/test_header.py new file mode 100644 index 0000000..759f50d --- /dev/null +++ b/test/test_header.py @@ -0,0 +1,36 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +""" + ____ ____ ______ __ __ __ _____ + / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / + / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < + / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / +/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ + German BOS Information Script + by Bastian Schroll + +@file: test_header.py +@date: 12.12.2017 +@author: Bastian Schroll +@description: Unittests for BOSWatch. File must be run as "pytest" unittest +""" + +import pytest # impot the pytest framework + +import boswatch.utils.header + + +class Test_Header(): + """!Unittests for the header""" + + def test_logoToLog(self): + """!Test logo to log""" + assert boswatch.utils.header.logoToLog() + + def test_infoToLog(self): + """!Test info to log""" + assert boswatch.utils.header.infoToLog() + + def test_logoToScreen(self): + """!Test logo to screen""" + assert boswatch.utils.header.logoToScreen()