Browse Source

Testrun and documentation improvements

tags/v1.2.0
Dirk Alders 1 year ago
parent
commit
bd1966ed4f
8 changed files with 76 additions and 23 deletions
  1. 8
    2
      Makefile
  2. 1
    0
      smart_brain_test.py
  3. 1
    1
      templates/run_statistic.tex
  4. 17
    5
      tests/__init__.py
  5. 2
    1
      tests/all.py
  6. 29
    8
      tests/heating.py
  7. 17
    4
      tests/light.py
  8. 1
    2
      tests/synchronisation.py

+ 8
- 2
Makefile View File

4
 TEXFILE_FULL=$(OUTDIR)/testrun_full.tex
4
 TEXFILE_FULL=$(OUTDIR)/testrun_full.tex
5
 PDFFILE_FULL=$(OUTDIR)/testrun_full.pdf
5
 PDFFILE_FULL=$(OUTDIR)/testrun_full.pdf
6
 
6
 
7
-run: test_smoke pdf view pdf_full clean
7
+smoke: test_smoke pdf view pdf_full clean
8
 	@echo FINISHED...
8
 	@echo FINISHED...
9
 
9
 
10
-run_full: test_full pdf view pdf_full clean
10
+short: test_short pdf view pdf_full clean
11
+	@echo FINISHED...
12
+
13
+full: test_full pdf view pdf_full clean
11
 	@echo FINISHED...
14
 	@echo FINISHED...
12
 
15
 
13
 test_smoke:
16
 test_smoke:
14
 	venv/bin/python smart_brain_test.py test.all.smoke
17
 	venv/bin/python smart_brain_test.py test.all.smoke
15
 
18
 
19
+test_short:
20
+	venv/bin/python smart_brain_test.py test.all.short
21
+
16
 test_full:
22
 test_full:
17
 	venv/bin/python smart_brain_test.py test.all.full
23
 	venv/bin/python smart_brain_test.py test.all.full
18
 
24
 

+ 1
- 0
smart_brain_test.py View File

5
 import sys
5
 import sys
6
 from tests.all import test_smarthome
6
 from tests.all import test_smarthome
7
 
7
 
8
+# TODO: Add testobject information (Info dict via mqtt) --> Report
8
 # TODO: Extend tests in simulation
9
 # TODO: Extend tests in simulation
9
 #         - Switching button functions (gfw_dirk, ffe.sleep)
10
 #         - Switching button functions (gfw_dirk, ffe.sleep)
10
 #         - Brightness button functions (gfw.dirk, ffe.sleep)
11
 #         - Brightness button functions (gfw.dirk, ffe.sleep)

+ 1
- 1
templates/run_statistic.tex View File

6
 	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 }}\\
6
 	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 }}\\
7
 	Number of failed tests & \textcolor{% if testrun.number_of_failed_tests > 0%}{red}{% else %}{black}{% endif %}{{ "{\\bf %d}" % testrun.number_of_failed_tests }}\\
7
 	Number of failed tests & \textcolor{% if testrun.number_of_failed_tests > 0%}{red}{% else %}{black}{% endif %}{{ "{\\bf %d}" % testrun.number_of_failed_tests }}\\
8
 	\midrule
8
 	\midrule
9
-	Executionlevel    & {{ macros.latex_filter(testrun.testcase_names.get('%d' % testrun.testcase_execution_level, 'unknown')) }}\\
9
+	Executionlevel    & {{ macros.latex_filter(testrun.testcase_names.get(testrun.testcase_execution_level, 'unknown')) }}\\
10
 	Time consumption  & {{ '%.3fs' % testrun.time_consumption }}\\
10
 	Time consumption  & {{ '%.3fs' % testrun.time_consumption }}\\
11
 	\bottomrule
11
 	\bottomrule
12
 \end{tabu}
12
 \end{tabu}

+ 17
- 5
tests/__init__.py View File

1
 import report
1
 import report
2
 import simulation.devices
2
 import simulation.devices
3
 from unittest.test import equivalency_chk
3
 from unittest.test import equivalency_chk
4
+from unittest.jsonlog import TRUN_EXEC_LVL
4
 
5
 
5
 DT_TOGGLE = 0.3
6
 DT_TOGGLE = 0.3
6
 
7
 
7
 
8
 
8
 class test_collection(object):
9
 class test_collection(object):
10
+    TCEL_DICT = {
11
+        'full': report.TCEL_FULL,
12
+        'short': report.TCEL_SHORT,
13
+        'smoke': report.TCEL_SMOKE
14
+    }
15
+
9
     def __init__(self, test_instance):
16
     def __init__(self, test_instance):
10
         super().__init__()
17
         super().__init__()
11
         self.test_instance = test_instance
18
         self.test_instance = test_instance
12
 
19
 
13
     def capabilities(self):
20
     def capabilities(self):
14
-        return ['full', 'smoke']
21
+        return ['full', 'short', 'smoke']
15
 
22
 
16
     def command(self, command):
23
     def command(self, command):
17
         for member in self.test_instance.getmembers():
24
         for member in self.test_instance.getmembers():
18
             obj = self.test_instance.getobjbyname(member)
25
             obj = self.test_instance.getobjbyname(member)
19
             if id(obj) != id(self):
26
             if id(obj) != id(self):
20
-                obj.test_all(report.TCEL_FULL if command == 'full' else report.TCEL_SMOKE)
27
+                tcel = self.TCEL_DICT.get(command, report.TCEL_FULL)
28
+                self.test_instance.tcl[TRUN_EXEC_LVL] = tcel
29
+                obj.test_all(tcel)
21
 
30
 
22
 
31
 
23
 class testcase(object):
32
 class testcase(object):
24
-    def __init__(self):
25
-        super().__init__()
33
+    METHOD_EXECUTED = {}
34
+
35
+    def __init__(self, tcl):
36
+        self.tcl = tcl
26
         self.__test_list__ = []
37
         self.__test_list__ = []
27
 
38
 
28
     def capabilities(self):
39
     def capabilities(self):
36
             if tc_name != "test_all":
47
             if tc_name != "test_all":
37
                 self.command(tc_name, tcel)
48
                 self.command(tc_name, tcel)
38
 
49
 
39
-    def command(self, command, tcel=report.TCEL_FULL):
50
+    def command(self, command, tcel=report.TCEL_SINGLE):
40
         simulation.devices.OUTPUT_ACTIVE = False
51
         simulation.devices.OUTPUT_ACTIVE = False
41
         tc = getattr(self, command)
52
         tc = getattr(self, command)
53
+        self.tcl[TRUN_EXEC_LVL] = tcel
42
         tc(tcel)
54
         tc(tcel)
43
         simulation.devices.OUTPUT_ACTIVE = True
55
         simulation.devices.OUTPUT_ACTIVE = True

+ 2
- 1
tests/all.py View File

78
         system_info[jsonlog.SYSI_SYSTEM] = platform.system()
78
         system_info[jsonlog.SYSI_SYSTEM] = platform.system()
79
         system_info[jsonlog.SYSI_KERNEL] = platform.release() + ' (%s)' % platform.version()
79
         system_info[jsonlog.SYSI_KERNEL] = platform.release() + ' (%s)' % platform.version()
80
         system_info[jsonlog.SYSI_USERNAME] = getpass.getuser()
80
         system_info[jsonlog.SYSI_USERNAME] = getpass.getuser()
81
-        system_info[jsonlog.SYSI_PATH] = os.path.abspath(os.path.basename(__file__))
81
+        system_info[jsonlog.SYSI_PATH] = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
82
 
82
 
83
         self.tcl = report.testSession(['__unittest__', 'unittest', ROOT_LOGGER_NAME])
83
         self.tcl = report.testSession(['__unittest__', 'unittest', ROOT_LOGGER_NAME])
84
         self.tcl[jsonlog.MAIN_KEY_SYSTEM_INFO] = system_info
84
         self.tcl[jsonlog.MAIN_KEY_SYSTEM_INFO] = system_info
85
+        self.tcl["testcase_names"] = report.TCEL_NAMES
85
 
86
 
86
     def __eval_tcl__(self):
87
     def __eval_tcl__(self):
87
         path = os.path.abspath(os.path.join(os.path.basename(__file__), '..'))
88
         path = os.path.abspath(os.path.join(os.path.basename(__file__), '..'))

+ 29
- 8
tests/heating.py View File

1
 import config
1
 import config
2
+import inspect
2
 import report
3
 import report
3
 from tests import testcase, DT_TOGGLE
4
 from tests import testcase, DT_TOGGLE
4
 import time
5
 import time
7
 
8
 
8
 class testcase_heating(testcase):
9
 class testcase_heating(testcase):
9
     def __init__(self, tcl, videv, valve):
10
     def __init__(self, tcl, videv, valve):
10
-        self.tcl = tcl
11
+        super().__init__(tcl)
11
         self.__videv__ = videv
12
         self.__videv__ = videv
12
         self.__valve__ = valve
13
         self.__valve__ = valve
13
         self.__default_temperature__ = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic)
14
         self.__default_temperature__ = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic)
14
         self.__test_list__ = ["test_user_temperature_setpoint", "test_default_temperature", "test_summer_mode", "test_away_mode", "test_boost_mode"]
15
         self.__test_list__ = ["test_user_temperature_setpoint", "test_default_temperature", "test_summer_mode", "test_away_mode", "test_boost_mode"]
15
 
16
 
16
     def test_user_temperature_setpoint(self, tcel=report.TCEL_FULL):
17
     def test_user_temperature_setpoint(self, tcel=report.TCEL_FULL):
17
-        self.tcl.testCase("User temperature setpoint test for device and virtual device: %s" %
18
-                          self.__valve__.topic, tcel, self.__test_user_temperature_setpoint__, tcel)
18
+        fname = inspect.currentframe().f_code.co_name
19
+        if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
20
+            self.METHOD_EXECUTED[fname] = True
21
+            #
22
+            self.tcl.testCase("User temperature setpoint test for device and virtual device: %s" %
23
+                              self.__valve__.topic, tcel, self.__test_user_temperature_setpoint__, tcel)
19
 
24
 
20
     def __test_user_temperature_setpoint__(self, tLogger, tcel):
25
     def __test_user_temperature_setpoint__(self, tLogger, tcel):
21
         mtemp = round(self.__valve__.TEMP_RANGE[0] + (self.__valve__.TEMP_RANGE[1] - self.__valve__.TEMP_RANGE[0]) / 2, 1)
26
         mtemp = round(self.__valve__.TEMP_RANGE[0] + (self.__valve__.TEMP_RANGE[1] - self.__valve__.TEMP_RANGE[0]) / 2, 1)
38
             equivalency_chk(self.__videv__.get(self.__videv__.KEY_VALVE_TEMPERATURE_SETPOINT), setp, tLogger, "Virtual device valve temperature")
43
             equivalency_chk(self.__videv__.get(self.__videv__.KEY_VALVE_TEMPERATURE_SETPOINT), setp, tLogger, "Virtual device valve temperature")
39
 
44
 
40
     def test_default_temperature(self, tcel=report.TCEL_FULL):
45
     def test_default_temperature(self, tcel=report.TCEL_FULL):
41
-        self.tcl.testCase("Default temperature test for device and virtual device: %s" %
42
-                          self.__valve__.topic, tcel, self.__test_default_temperature__, tcel)
46
+        fname = inspect.currentframe().f_code.co_name
47
+        if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
48
+            self.METHOD_EXECUTED[fname] = True
49
+            #
50
+            self.tcl.testCase("Default temperature test for device and virtual device: %s" %
51
+                              self.__valve__.topic, tcel, self.__test_default_temperature__, tcel)
43
 
52
 
44
     def __test_default_temperature__(self, tLogger, tcel):
53
     def __test_default_temperature__(self, tLogger, tcel):
45
         dtemp = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic)
54
         dtemp = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic)
58
         equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), dtemp, tLogger, "Valve temperature setpoint")
67
         equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), dtemp, tLogger, "Valve temperature setpoint")
59
 
68
 
60
     def test_summer_mode(self, tcel=report.TCEL_FULL):
69
     def test_summer_mode(self, tcel=report.TCEL_FULL):
61
-        self.tcl.testCase("Summer mode test: %s" % self.__valve__.topic, tcel, self.__test_summer_mode__, tcel)
70
+        fname = inspect.currentframe().f_code.co_name
71
+        if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
72
+            self.METHOD_EXECUTED[fname] = True
73
+            #
74
+            self.tcl.testCase("Summer mode test: %s" % self.__valve__.topic, tcel, self.__test_summer_mode__, tcel)
62
 
75
 
63
     def __test_summer_mode__(self, tLogger, tcel):
76
     def __test_summer_mode__(self, tLogger, tcel):
64
         self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
77
         self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
81
         equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp, tLogger, "Temperature setpoint")
94
         equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp, tLogger, "Temperature setpoint")
82
 
95
 
83
     def test_away_mode(self, tcel=report.TCEL_FULL):
96
     def test_away_mode(self, tcel=report.TCEL_FULL):
84
-        self.tcl.testCase("Away mode test: %s" % self.__valve__.topic, tcel, self.__test_away_mode__, tcel)
97
+        fname = inspect.currentframe().f_code.co_name
98
+        if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
99
+            self.METHOD_EXECUTED[fname] = True
100
+            #
101
+            self.tcl.testCase("Away mode test: %s" % self.__valve__.topic, tcel, self.__test_away_mode__, tcel)
85
 
102
 
86
     def __test_away_mode__(self, tLogger, tcel):
103
     def __test_away_mode__(self, tLogger, tcel):
87
         self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
104
         self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
104
         equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp, tLogger, "Temperature setpoint")
121
         equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp, tLogger, "Temperature setpoint")
105
 
122
 
106
     def test_boost_mode(self, tcel=report.TCEL_FULL):
123
     def test_boost_mode(self, tcel=report.TCEL_FULL):
107
-        self.tcl.testCase("Boost mode test: %s" % self.__valve__.topic, tcel, self.__test_boost_mode__, tcel)
124
+        fname = inspect.currentframe().f_code.co_name
125
+        if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
126
+            self.METHOD_EXECUTED[fname] = True
127
+            #
128
+            self.tcl.testCase("Boost mode test: %s" % self.__valve__.topic, tcel, self.__test_boost_mode__, tcel)
108
 
129
 
109
     def __test_boost_mode__(self, tLogger, tcel):
130
     def __test_boost_mode__(self, tLogger, tcel):
110
         self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
131
         self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)

+ 17
- 4
tests/light.py View File

1
+import inspect
1
 import report
2
 import report
2
 from tests import testcase, DT_TOGGLE
3
 from tests import testcase, DT_TOGGLE
3
 import time
4
 import time
6
 
7
 
7
 class testcase_light(testcase):
8
 class testcase_light(testcase):
8
     def __init__(self, tcl, videv, sw_device, li_device):
9
     def __init__(self, tcl, videv, sw_device, li_device):
9
-        self.tcl = tcl
10
+        super().__init__(tcl)
10
         self.videv = videv
11
         self.videv = videv
11
         self.sw_device = sw_device
12
         self.sw_device = sw_device
12
         self.li_device = li_device
13
         self.li_device = li_device
19
             self.__test_list__.append('test_color_temp')
20
             self.__test_list__.append('test_color_temp')
20
 
21
 
21
     def test_power_on_off(self, tcel=report.TCEL_FULL):
22
     def test_power_on_off(self, tcel=report.TCEL_FULL):
22
-        self.tcl.testCase("Power On/ Off test for device and virtual device: %s" % self.sw_device.topic, tcel, self.__test_power_on_off__, tcel)
23
+        fname = inspect.currentframe().f_code.co_name
24
+        if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
25
+            self.METHOD_EXECUTED[fname] = True
26
+            #
27
+            self.tcl.testCase("Power On/ Off test for device and virtual device: %s" % self.sw_device.topic, tcel, self.__test_power_on_off__, tcel)
23
 
28
 
24
     def __test_power_on_off__(self, tLogger, tcel):
29
     def __test_power_on_off__(self, tLogger, tcel):
25
         sw_state = self.sw_device.get(self.sw_device.KEY_OUTPUT_0)
30
         sw_state = self.sw_device.get(self.sw_device.KEY_OUTPUT_0)
38
             equivalency_chk(self.sw_device.get(self.sw_device.KEY_OUTPUT_0), sw_state, tLogger, "Switching device state")
43
             equivalency_chk(self.sw_device.get(self.sw_device.KEY_OUTPUT_0), sw_state, tLogger, "Switching device state")
39
 
44
 
40
     def test_brightness(self, tcel=report.TCEL_FULL):
45
     def test_brightness(self, tcel=report.TCEL_FULL):
41
-        self.tcl.testCase("Brightness test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_brightness__, tcel)
46
+        fname = inspect.currentframe().f_code.co_name
47
+        if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
48
+            self.METHOD_EXECUTED[fname] = True
49
+            #
50
+            self.tcl.testCase("Brightness test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_brightness__, tcel)
42
 
51
 
43
     def __test_brightness__(self, tLogger, tcel):
52
     def __test_brightness__(self, tLogger, tcel):
44
         br_state = self.li_device.get(self.li_device.KEY_BRIGHTNESS)
53
         br_state = self.li_device.get(self.li_device.KEY_BRIGHTNESS)
65
         tLogger.debug("Resetting precondition (Power off)")
74
         tLogger.debug("Resetting precondition (Power off)")
66
 
75
 
67
     def test_color_temp(self, tcel=report.TCEL_FULL):
76
     def test_color_temp(self, tcel=report.TCEL_FULL):
68
-        self.tcl.testCase("Color temperature test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_color_temp__, tcel)
77
+        fname = inspect.currentframe().f_code.co_name
78
+        if tcel != report.TCEL_SMOKE or not self.METHOD_EXECUTED.get(fname, False):
79
+            self.METHOD_EXECUTED[fname] = True
80
+            #
81
+            self.tcl.testCase("Color temperature test for device and virtual device: %s" % self.li_device.topic, tcel, self.__test_color_temp__, tcel)
69
 
82
 
70
     def __test_color_temp__(self, tLogger, tcel):
83
     def __test_color_temp__(self, tLogger, tcel):
71
         ct_state = self.li_device.get(self.li_device.KEY_COLOR_TEMP)
84
         ct_state = self.li_device.get(self.li_device.KEY_COLOR_TEMP)

+ 1
- 2
tests/synchronisation.py View File

6
 
6
 
7
 class testcase_synchronisation(testcase):
7
 class testcase_synchronisation(testcase):
8
     def __init__(self, tcl, sw_master, br_master, ct_master, *follower):
8
     def __init__(self, tcl, sw_master, br_master, ct_master, *follower):
9
-        super().__init__()
10
-        self.tcl = tcl
9
+        super().__init__(tcl)
11
         self.sw_master = sw_master
10
         self.sw_master = sw_master
12
         self.br_master = br_master
11
         self.br_master = br_master
13
         self.ct_master = ct_master
12
         self.ct_master = ct_master

Loading…
Cancel
Save