浏览代码

Testrun and documentation improvements

tags/v1.2.0
Dirk Alders 1年前
父节点
当前提交
bd1966ed4f
共有 8 个文件被更改,包括 76 次插入23 次删除
  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 查看文件

@@ -4,15 +4,21 @@ PDFFILE=$(OUTDIR)/testrun.pdf
4 4
 TEXFILE_FULL=$(OUTDIR)/testrun_full.tex
5 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 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 14
 	@echo FINISHED...
12 15
 
13 16
 test_smoke:
14 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 22
 test_full:
17 23
 	venv/bin/python smart_brain_test.py test.all.full
18 24
 

+ 1
- 0
smart_brain_test.py 查看文件

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

+ 1
- 1
templates/run_statistic.tex 查看文件

@@ -6,7 +6,7 @@
6 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 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 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 10
 	Time consumption  & {{ '%.3fs' % testrun.time_consumption }}\\
11 11
 	\bottomrule
12 12
 \end{tabu}

+ 17
- 5
tests/__init__.py 查看文件

@@ -1,28 +1,39 @@
1 1
 import report
2 2
 import simulation.devices
3 3
 from unittest.test import equivalency_chk
4
+from unittest.jsonlog import TRUN_EXEC_LVL
4 5
 
5 6
 DT_TOGGLE = 0.3
6 7
 
7 8
 
8 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 16
     def __init__(self, test_instance):
10 17
         super().__init__()
11 18
         self.test_instance = test_instance
12 19
 
13 20
     def capabilities(self):
14
-        return ['full', 'smoke']
21
+        return ['full', 'short', 'smoke']
15 22
 
16 23
     def command(self, command):
17 24
         for member in self.test_instance.getmembers():
18 25
             obj = self.test_instance.getobjbyname(member)
19 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 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 37
         self.__test_list__ = []
27 38
 
28 39
     def capabilities(self):
@@ -36,8 +47,9 @@ class testcase(object):
36 47
             if tc_name != "test_all":
37 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 51
         simulation.devices.OUTPUT_ACTIVE = False
41 52
         tc = getattr(self, command)
53
+        self.tcl[TRUN_EXEC_LVL] = tcel
42 54
         tc(tcel)
43 55
         simulation.devices.OUTPUT_ACTIVE = True

+ 2
- 1
tests/all.py 查看文件

@@ -78,10 +78,11 @@ class test_smarthome(object):
78 78
         system_info[jsonlog.SYSI_SYSTEM] = platform.system()
79 79
         system_info[jsonlog.SYSI_KERNEL] = platform.release() + ' (%s)' % platform.version()
80 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 83
         self.tcl = report.testSession(['__unittest__', 'unittest', ROOT_LOGGER_NAME])
84 84
         self.tcl[jsonlog.MAIN_KEY_SYSTEM_INFO] = system_info
85
+        self.tcl["testcase_names"] = report.TCEL_NAMES
85 86
 
86 87
     def __eval_tcl__(self):
87 88
         path = os.path.abspath(os.path.join(os.path.basename(__file__), '..'))

+ 29
- 8
tests/heating.py 查看文件

@@ -1,4 +1,5 @@
1 1
 import config
2
+import inspect
2 3
 import report
3 4
 from tests import testcase, DT_TOGGLE
4 5
 import time
@@ -7,15 +8,19 @@ from unittest.test import equivalency_chk, greater_chk
7 8
 
8 9
 class testcase_heating(testcase):
9 10
     def __init__(self, tcl, videv, valve):
10
-        self.tcl = tcl
11
+        super().__init__(tcl)
11 12
         self.__videv__ = videv
12 13
         self.__valve__ = valve
13 14
         self.__default_temperature__ = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic)
14 15
         self.__test_list__ = ["test_user_temperature_setpoint", "test_default_temperature", "test_summer_mode", "test_away_mode", "test_boost_mode"]
15 16
 
16 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 25
     def __test_user_temperature_setpoint__(self, tLogger, tcel):
21 26
         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):
38 43
             equivalency_chk(self.__videv__.get(self.__videv__.KEY_VALVE_TEMPERATURE_SETPOINT), setp, tLogger, "Virtual device valve temperature")
39 44
 
40 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 53
     def __test_default_temperature__(self, tLogger, tcel):
45 54
         dtemp = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic)
@@ -58,7 +67,11 @@ class testcase_heating(testcase):
58 67
         equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), dtemp, tLogger, "Valve temperature setpoint")
59 68
 
60 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 76
     def __test_summer_mode__(self, tLogger, tcel):
64 77
         self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
@@ -81,7 +94,11 @@ class testcase_heating(testcase):
81 94
         equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp, tLogger, "Temperature setpoint")
82 95
 
83 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 103
     def __test_away_mode__(self, tLogger, tcel):
87 104
         self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
@@ -104,7 +121,11 @@ class testcase_heating(testcase):
104 121
         equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp, tLogger, "Temperature setpoint")
105 122
 
106 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 130
     def __test_boost_mode__(self, tLogger, tcel):
110 131
         self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)

+ 17
- 4
tests/light.py 查看文件

@@ -1,3 +1,4 @@
1
+import inspect
1 2
 import report
2 3
 from tests import testcase, DT_TOGGLE
3 4
 import time
@@ -6,7 +7,7 @@ from unittest.test import equivalency_chk
6 7
 
7 8
 class testcase_light(testcase):
8 9
     def __init__(self, tcl, videv, sw_device, li_device):
9
-        self.tcl = tcl
10
+        super().__init__(tcl)
10 11
         self.videv = videv
11 12
         self.sw_device = sw_device
12 13
         self.li_device = li_device
@@ -19,7 +20,11 @@ class testcase_light(testcase):
19 20
             self.__test_list__.append('test_color_temp')
20 21
 
21 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 29
     def __test_power_on_off__(self, tLogger, tcel):
25 30
         sw_state = self.sw_device.get(self.sw_device.KEY_OUTPUT_0)
@@ -38,7 +43,11 @@ class testcase_light(testcase):
38 43
             equivalency_chk(self.sw_device.get(self.sw_device.KEY_OUTPUT_0), sw_state, tLogger, "Switching device state")
39 44
 
40 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 52
     def __test_brightness__(self, tLogger, tcel):
44 53
         br_state = self.li_device.get(self.li_device.KEY_BRIGHTNESS)
@@ -65,7 +74,11 @@ class testcase_light(testcase):
65 74
         tLogger.debug("Resetting precondition (Power off)")
66 75
 
67 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 83
     def __test_color_temp__(self, tLogger, tcel):
71 84
         ct_state = self.li_device.get(self.li_device.KEY_COLOR_TEMP)

+ 1
- 2
tests/synchronisation.py 查看文件

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

正在加载...
取消
保存