From bd1966ed4f74ee3879368af011d032cec6900bd4 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Thu, 9 Feb 2023 10:03:34 +0100 Subject: [PATCH] Testrun and documentation improvements --- Makefile | 10 ++++++++-- smart_brain_test.py | 1 + templates/run_statistic.tex | 2 +- tests/__init__.py | 22 +++++++++++++++++----- tests/all.py | 3 ++- tests/heating.py | 37 +++++++++++++++++++++++++++++-------- tests/light.py | 21 +++++++++++++++++---- tests/synchronisation.py | 3 +-- 8 files changed, 76 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 0f01d6e..c7984b8 100644 --- a/Makefile +++ b/Makefile @@ -4,15 +4,21 @@ PDFFILE=$(OUTDIR)/testrun.pdf TEXFILE_FULL=$(OUTDIR)/testrun_full.tex PDFFILE_FULL=$(OUTDIR)/testrun_full.pdf -run: test_smoke pdf view pdf_full clean +smoke: test_smoke pdf view pdf_full clean @echo FINISHED... -run_full: test_full pdf view pdf_full clean +short: test_short pdf view pdf_full clean + @echo FINISHED... + +full: test_full pdf view pdf_full clean @echo FINISHED... test_smoke: venv/bin/python smart_brain_test.py test.all.smoke +test_short: + venv/bin/python smart_brain_test.py test.all.short + test_full: venv/bin/python smart_brain_test.py test.all.full diff --git a/smart_brain_test.py b/smart_brain_test.py index ff505c5..3b97b2b 100644 --- a/smart_brain_test.py +++ b/smart_brain_test.py @@ -5,6 +5,7 @@ from simulation.rooms import house import sys from tests.all import test_smarthome +# TODO: Add testobject information (Info dict via mqtt) --> Report # TODO: Extend tests in simulation # - Switching button functions (gfw_dirk, ffe.sleep) # - Brightness button functions (gfw.dirk, ffe.sleep) diff --git a/templates/run_statistic.tex b/templates/run_statistic.tex index 10928ff..4e89318 100644 --- a/templates/run_statistic.tex +++ b/templates/run_statistic.tex @@ -6,7 +6,7 @@ Number of possibly failed tests & \textcolor{% if testrun.number_of_possibly_failed_tests > 0%}{orange}{% else %}{black}{% endif %}{{ "{\\bf %d}" % testrun.number_of_possibly_failed_tests }}\\ Number of failed tests & \textcolor{% if testrun.number_of_failed_tests > 0%}{red}{% else %}{black}{% endif %}{{ "{\\bf %d}" % testrun.number_of_failed_tests }}\\ \midrule - Executionlevel & {{ macros.latex_filter(testrun.testcase_names.get('%d' % testrun.testcase_execution_level, 'unknown')) }}\\ + Executionlevel & {{ macros.latex_filter(testrun.testcase_names.get(testrun.testcase_execution_level, 'unknown')) }}\\ Time consumption & {{ '%.3fs' % testrun.time_consumption }}\\ \bottomrule \end{tabu} diff --git a/tests/__init__.py b/tests/__init__.py index 7d21899..b27988e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,28 +1,39 @@ import report import simulation.devices from unittest.test import equivalency_chk +from unittest.jsonlog import TRUN_EXEC_LVL DT_TOGGLE = 0.3 class test_collection(object): + TCEL_DICT = { + 'full': report.TCEL_FULL, + 'short': report.TCEL_SHORT, + 'smoke': report.TCEL_SMOKE + } + def __init__(self, test_instance): super().__init__() self.test_instance = test_instance def capabilities(self): - return ['full', 'smoke'] + return ['full', 'short', 'smoke'] def command(self, command): for member in self.test_instance.getmembers(): obj = self.test_instance.getobjbyname(member) if id(obj) != id(self): - obj.test_all(report.TCEL_FULL if command == 'full' else report.TCEL_SMOKE) + tcel = self.TCEL_DICT.get(command, report.TCEL_FULL) + self.test_instance.tcl[TRUN_EXEC_LVL] = tcel + obj.test_all(tcel) class testcase(object): - def __init__(self): - super().__init__() + METHOD_EXECUTED = {} + + def __init__(self, tcl): + self.tcl = tcl self.__test_list__ = [] def capabilities(self): @@ -36,8 +47,9 @@ class testcase(object): if tc_name != "test_all": self.command(tc_name, tcel) - def command(self, command, tcel=report.TCEL_FULL): + def command(self, command, tcel=report.TCEL_SINGLE): simulation.devices.OUTPUT_ACTIVE = False tc = getattr(self, command) + self.tcl[TRUN_EXEC_LVL] = tcel tc(tcel) simulation.devices.OUTPUT_ACTIVE = True diff --git a/tests/all.py b/tests/all.py index b3e1f2e..7e97c86 100644 --- a/tests/all.py +++ b/tests/all.py @@ -78,10 +78,11 @@ class test_smarthome(object): system_info[jsonlog.SYSI_SYSTEM] = platform.system() system_info[jsonlog.SYSI_KERNEL] = platform.release() + ' (%s)' % platform.version() system_info[jsonlog.SYSI_USERNAME] = getpass.getuser() - system_info[jsonlog.SYSI_PATH] = os.path.abspath(os.path.basename(__file__)) + system_info[jsonlog.SYSI_PATH] = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) self.tcl = report.testSession(['__unittest__', 'unittest', ROOT_LOGGER_NAME]) self.tcl[jsonlog.MAIN_KEY_SYSTEM_INFO] = system_info + self.tcl["testcase_names"] = report.TCEL_NAMES def __eval_tcl__(self): path = os.path.abspath(os.path.join(os.path.basename(__file__), '..')) diff --git a/tests/heating.py b/tests/heating.py index 09f1f78..26f6e78 100644 --- a/tests/heating.py +++ b/tests/heating.py @@ -1,4 +1,5 @@ import config +import inspect import report from tests import testcase, DT_TOGGLE import time @@ -7,15 +8,19 @@ from unittest.test import equivalency_chk, greater_chk class testcase_heating(testcase): def __init__(self, tcl, videv, valve): - self.tcl = tcl + super().__init__(tcl) self.__videv__ = videv self.__valve__ = valve self.__default_temperature__ = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic) self.__test_list__ = ["test_user_temperature_setpoint", "test_default_temperature", "test_summer_mode", "test_away_mode", "test_boost_mode"] def test_user_temperature_setpoint(self, tcel=report.TCEL_FULL): - self.tcl.testCase("User temperature setpoint test for device and virtual device: %s" % - self.__valve__.topic, tcel, self.__test_user_temperature_setpoint__, tcel) + fname = inspect.currentframe().f_code.co_name + if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False): + self.METHOD_EXECUTED[fname] = True + # + self.tcl.testCase("User temperature setpoint test for device and virtual device: %s" % + self.__valve__.topic, tcel, self.__test_user_temperature_setpoint__, tcel) def __test_user_temperature_setpoint__(self, tLogger, tcel): mtemp = round(self.__valve__.TEMP_RANGE[0] + (self.__valve__.TEMP_RANGE[1] - self.__valve__.TEMP_RANGE[0]) / 2, 1) @@ -38,8 +43,12 @@ class testcase_heating(testcase): equivalency_chk(self.__videv__.get(self.__videv__.KEY_VALVE_TEMPERATURE_SETPOINT), setp, tLogger, "Virtual device valve temperature") def test_default_temperature(self, tcel=report.TCEL_FULL): - self.tcl.testCase("Default temperature test for device and virtual device: %s" % - self.__valve__.topic, tcel, self.__test_default_temperature__, tcel) + fname = inspect.currentframe().f_code.co_name + if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False): + self.METHOD_EXECUTED[fname] = True + # + self.tcl.testCase("Default temperature test for device and virtual device: %s" % + self.__valve__.topic, tcel, self.__test_default_temperature__, tcel) def __test_default_temperature__(self, tLogger, tcel): dtemp = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic) @@ -58,7 +67,11 @@ class testcase_heating(testcase): equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), dtemp, tLogger, "Valve temperature setpoint") def test_summer_mode(self, tcel=report.TCEL_FULL): - self.tcl.testCase("Summer mode test: %s" % self.__valve__.topic, tcel, self.__test_summer_mode__, tcel) + fname = inspect.currentframe().f_code.co_name + if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False): + self.METHOD_EXECUTED[fname] = True + # + self.tcl.testCase("Summer mode test: %s" % self.__valve__.topic, tcel, self.__test_summer_mode__, tcel) def __test_summer_mode__(self, tLogger, tcel): self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None) @@ -81,7 +94,11 @@ class testcase_heating(testcase): equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp, tLogger, "Temperature setpoint") def test_away_mode(self, tcel=report.TCEL_FULL): - self.tcl.testCase("Away mode test: %s" % self.__valve__.topic, tcel, self.__test_away_mode__, tcel) + fname = inspect.currentframe().f_code.co_name + if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False): + self.METHOD_EXECUTED[fname] = True + # + self.tcl.testCase("Away mode test: %s" % self.__valve__.topic, tcel, self.__test_away_mode__, tcel) def __test_away_mode__(self, tLogger, tcel): self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None) @@ -104,7 +121,11 @@ class testcase_heating(testcase): equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp, tLogger, "Temperature setpoint") def test_boost_mode(self, tcel=report.TCEL_FULL): - self.tcl.testCase("Boost mode test: %s" % self.__valve__.topic, tcel, self.__test_boost_mode__, tcel) + fname = inspect.currentframe().f_code.co_name + if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False): + self.METHOD_EXECUTED[fname] = True + # + self.tcl.testCase("Boost mode test: %s" % self.__valve__.topic, tcel, self.__test_boost_mode__, tcel) def __test_boost_mode__(self, tLogger, tcel): self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None) diff --git a/tests/light.py b/tests/light.py index 96b5653..1e2cfd7 100644 --- a/tests/light.py +++ b/tests/light.py @@ -1,3 +1,4 @@ +import inspect import report from tests import testcase, DT_TOGGLE import time @@ -6,7 +7,7 @@ from unittest.test import equivalency_chk class testcase_light(testcase): def __init__(self, tcl, videv, sw_device, li_device): - self.tcl = tcl + super().__init__(tcl) self.videv = videv self.sw_device = sw_device self.li_device = li_device @@ -19,7 +20,11 @@ class testcase_light(testcase): self.__test_list__.append('test_color_temp') def test_power_on_off(self, tcel=report.TCEL_FULL): - self.tcl.testCase("Power On/ Off test for device and virtual device: %s" % self.sw_device.topic, tcel, self.__test_power_on_off__, tcel) + fname = inspect.currentframe().f_code.co_name + if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False): + self.METHOD_EXECUTED[fname] = True + # + self.tcl.testCase("Power On/ Off test for device and virtual device: %s" % self.sw_device.topic, tcel, self.__test_power_on_off__, tcel) def __test_power_on_off__(self, tLogger, tcel): sw_state = self.sw_device.get(self.sw_device.KEY_OUTPUT_0) @@ -38,7 +43,11 @@ class testcase_light(testcase): equivalency_chk(self.sw_device.get(self.sw_device.KEY_OUTPUT_0), sw_state, tLogger, "Switching device state") def test_brightness(self, tcel=report.TCEL_FULL): - self.tcl.testCase("Brightness test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_brightness__, tcel) + fname = inspect.currentframe().f_code.co_name + if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False): + self.METHOD_EXECUTED[fname] = True + # + self.tcl.testCase("Brightness test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_brightness__, tcel) def __test_brightness__(self, tLogger, tcel): br_state = self.li_device.get(self.li_device.KEY_BRIGHTNESS) @@ -65,7 +74,11 @@ class testcase_light(testcase): tLogger.debug("Resetting precondition (Power off)") def test_color_temp(self, tcel=report.TCEL_FULL): - self.tcl.testCase("Color temperature test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_color_temp__, tcel) + fname = inspect.currentframe().f_code.co_name + if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False): + self.METHOD_EXECUTED[fname] = True + # + self.tcl.testCase("Color temperature test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_color_temp__, tcel) def __test_color_temp__(self, tLogger, tcel): ct_state = self.li_device.get(self.li_device.KEY_COLOR_TEMP) diff --git a/tests/synchronisation.py b/tests/synchronisation.py index f436110..b2b4d55 100644 --- a/tests/synchronisation.py +++ b/tests/synchronisation.py @@ -6,8 +6,7 @@ from unittest.test import equivalency_chk class testcase_synchronisation(testcase): def __init__(self, tcl, sw_master, br_master, ct_master, *follower): - super().__init__() - self.tcl = tcl + super().__init__(tcl) self.sw_master = sw_master self.br_master = br_master self.ct_master = ct_master