Procházet zdrojové kódy

Testreport from unittest added + Test extension

tags/v1.2.0
Dirk Alders před 1 rokem
rodič
revize
7cf868e886

+ 2
- 0
.gitignore Zobrazit soubor

@@ -1,3 +1,5 @@
1
+testresults
2
+
1 3
 # ---> VirtualEnv
2 4
 # Virtualenv
3 5
 # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/

+ 9
- 0
.gitmodules Zobrazit soubor

@@ -10,3 +10,12 @@
10 10
 [submodule "task"]
11 11
 	path = task
12 12
 	url = https://git.mount-mockery.de/pylib/task.git
13
+[submodule "fstools"]
14
+	path = fstools
15
+	url = https://git.mount-mockery.de/pylib/fstools.git
16
+[submodule "reqif"]
17
+	path = reqif
18
+	url = https://git.mount-mockery.de/pylib/reqif.git
19
+[submodule "unittest"]
20
+	path = unittest
21
+	url = https://git.mount-mockery.de/pylib/unittest.git

+ 39
- 0
Makefile Zobrazit soubor

@@ -0,0 +1,39 @@
1
+OUTDIR=testresults
2
+TEXFILE=$(OUTDIR)/testrun.tex
3
+PDFFILE=$(OUTDIR)/testrun.pdf
4
+TEXFILE_FULL=$(OUTDIR)/testrun_full.tex
5
+PDFFILE_FULL=$(OUTDIR)/testrun_full.pdf
6
+
7
+run: test_smoke pdf view pdf_full clean
8
+	@echo FINISHED...
9
+
10
+run_full: test_full pdf view pdf_full clean
11
+	@echo FINISHED...
12
+
13
+test_smoke:
14
+	venv/bin/python smart_brain_test.py test.all.smoke
15
+
16
+test_full:
17
+	venv/bin/python smart_brain_test.py test.all.full
18
+
19
+pdf:
20
+	@latexmk -pdf -quiet -pdflatex="pdflatex -interaction=nonstopmode" -output-directory=$(OUTDIR) -use-make $(TEXFILE) > /dev/null
21
+
22
+pdf_full:
23
+	@latexmk -pdf -quiet -pdflatex="pdflatex -interaction=nonstopmode" -output-directory=$(OUTDIR) -use-make $(TEXFILE_FULL) > /dev/null
24
+
25
+view:
26
+	@open $(PDFFILE)
27
+
28
+view_full:
29
+	@open $(PDFFILE_FULL)
30
+
31
+clean:
32
+	@latexmk -quiet -output-directory=$(OUTDIR) -c $(TEXFILE) > /dev/null
33
+	@latexmk -quiet -output-directory=$(OUTDIR) -c $(TEXFILE_FULL) > /dev/null
34
+	@find . -name *~ -type f | xargs rm -f
35
+	@find . -name __pycache__ -type d | xargs rm -rf
36
+
37
+%:
38
+	venv/bin/python smart_brain_test.py $@
39
+	$(MAKE) pdf_full view_full pdf clean

+ 1
- 0
fstools

@@ -0,0 +1 @@
1
+Subproject commit c10e8792abb05671dab6de51cdadda3bf8ead50f

+ 1
- 0
reqif

@@ -0,0 +1 @@
1
+Subproject commit c0e8533af5eeb4dccb6cd8742c936eb456ce6466

+ 26
- 16
simulation/devices.py Zobrazit soubor

@@ -15,6 +15,8 @@ COLOR_MOTION_SENSOR = colored.fg("dark_orange_3b")
15 15
 COLOR_HEATING_VALVE = colored.fg("red")
16 16
 COLOR_REMOTE = colored.fg("green")
17 17
 
18
+OUTPUT_ACTIVE = True
19
+
18 20
 
19 21
 class base(mqtt_base):
20 22
     AUTOSEND = True
@@ -85,24 +87,27 @@ class base(mqtt_base):
85 87
             print("You need to give a numeric parameter not '%s'" % str(value))
86 88
 
87 89
     def print_formatted_light(self, color, state, description, led=False):
88
-        if led is True:
89
-            if state is True:
90
-                icon = colored.fg('green') + "\u2b24" + color
90
+        if OUTPUT_ACTIVE:
91
+            if led is True:
92
+                if state is True:
93
+                    icon = colored.fg('green') + "\u2b24" + color
94
+                else:
95
+                    icon = colored.fg('light_gray') + "\u2b24" + color
91 96
             else:
92
-                icon = colored.fg('light_gray') + "\u2b24" + color
93
-        else:
94
-            icon = u'\u2b24' if state is True else u'\u25ef'
95
-        print(color + 10 * ' ' + icon + 9 * ' ' + self.__devicename__(), description + colored.attr("reset"))
97
+                icon = u'\u2b24' if state is True else u'\u25ef'
98
+            print(color + 10 * ' ' + icon + 9 * ' ' + self.__devicename__(), description + colored.attr("reset"))
96 99
 
97 100
     def print_formatted_videv(self, color, state, description):
98
-        icon = u'\u25a0' if state is True else u'\u25a1'
99
-        print(color + 10 * ' ' + icon + 9 * ' ' + self.__devicename__(), description + colored.attr("reset"))
101
+        if OUTPUT_ACTIVE:
102
+            icon = u'\u25a0' if state is True else u'\u25a1'
103
+            print(color + 10 * ' ' + icon + 9 * ' ' + self.__devicename__(), description + colored.attr("reset"))
100 104
 
101 105
     def print_formatted_percent(self, color, prefix, perc_value, value_str,  description):
102
-        if len(prefix) > 1 or len(value_str) > 7:
103
-            raise ValueError("Length of prefix (%d) > 1 or length of value_str (%d) > 7" % (len(prefix), len(value_str)))
104
-        print(color + prefix + self.__percent_bar__(perc_value), value_str + (8 - len(value_str))
105
-              * ' ' + self.__devicename__(), description + colored.attr("reset"))
106
+        if OUTPUT_ACTIVE:
107
+            if len(prefix) > 1 or len(value_str) > 7:
108
+                raise ValueError("Length of prefix (%d) > 1 or length of value_str (%d) > 7" % (len(prefix), len(value_str)))
109
+            print(color + prefix + self.__percent_bar__(perc_value), value_str + (8 - len(value_str))
110
+                  * ' ' + self.__devicename__(), description + colored.attr("reset"))
106 111
 
107 112
 
108 113
 class base_videv(base):
@@ -365,9 +370,9 @@ class tradfri_light(base):
365 370
 
366 371
     def __ext_to_int__(self, key, data):
367 372
         if key == self.KEY_BRIGHTNESS:
368
-            return round((data - 1) / 2.53, 0)
373
+            return int(round((data - 1) / 2.53, 0))
369 374
         elif key == self.KEY_COLOR_TEMP:
370
-            return round((data - 250) / 20.4, 0)
375
+            return int(round((data - 250) / 20.4, 0))
371 376
         else:
372 377
             return super().__ext_to_int__(key, data)
373 378
 
@@ -547,12 +552,17 @@ class videv_light(base_videv):
547 552
         self.add_callback(self.KEY_COLOR_TEMP, None, self.__send__, True)
548 553
         self.add_callback(self.KEY_TIMER, None, self.__send__, True)
549 554
 
555
+    def __ext_to_int__(self, key, data):
556
+        if key in [self.KEY_BRIGHTNESS, self.KEY_COLOR_TEMP]:
557
+            return int(data)
558
+        return super().__ext_to_int__(key, data)
559
+
550 560
     def __rx__(self, client, userdata, message):
551 561
         value = self.__payload_filter__(message.payload)
552 562
         if message.topic.startswith(self.topic):
553 563
             targetkey = message.topic.split('/')[-1]
554 564
             if targetkey in self.keys():
555
-                self.set(targetkey, value, block_callback=(self.__send__, ))
565
+                self.set(targetkey, self.__ext_to_int__(targetkey, value), block_callback=(self.__send__, ))
556 566
             elif targetkey != "__info__":
557 567
                 print("Unknown key %s in %s::%s" % (targetkey, message.topic, self.__class__.__name__))
558 568
 

+ 37
- 28
smart_brain_test.py Zobrazit soubor

@@ -1,16 +1,20 @@
1 1
 import config
2
-import logging
3 2
 import mqtt
4 3
 import readline
5
-import report
6 4
 from simulation.rooms import house
7
-from tests import test_smarthome
8
-import time
5
+import sys
6
+from tests.all import test_smarthome
7
+
8
+# TODO: Extend tests in simulation
9
+#         - Switching button functions (gfw_dirk, ffe.sleep)
10
+#         - Brightness button functions (gfw.dirk, ffe.sleep)
11
+#         - Synch functions of amplifier with spotify, mpd
12
+#         - Remote actions after amplifier on
13
+#         - Heating functionality (extended: mode switch off by other function, timer)
14
+#         - Circulation pump (Extend Timer)
15
+#         - Stairways (Extend Motion sensor and Timer)
9 16
 
10 17
 if __name__ == "__main__":
11
-    report.stdoutLoggingConfigure(
12
-        ((config.APP_NAME, logging.WARNING), ), report.SHORT_FMT)
13
-    #
14 18
     mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
15 19
                           password=config.MQTT_PASSWORD, name=config.APP_NAME + '_simulation')
16 20
     #
@@ -61,25 +65,30 @@ if __name__ == "__main__":
61 65
                 else:
62 66
                     state -= 1
63 67
 
64
-    readline.parse_and_bind("tab: complete")
65
-    readline.set_completer(completer)
66
-    time.sleep(0.3)
67
-    print("\nEnter command: ")
68
-
69
-    while True:
70
-        userfeedback = input('')
71
-        command = userfeedback.split(' ')[0]
72
-        if userfeedback == 'quit':
73
-            break
74
-        elif userfeedback == 'help':
75
-            print("Help is not yet implemented!")
76
-        elif userfeedback.startswith("test"):
77
-            ts.command(userfeedback)
78
-        elif userfeedback == 'test.smoke':
79
-            ts.smoke()
80
-        elif command in COMMANDS[2:]:
81
-            h.command(userfeedback)
82
-        elif userfeedback != "":
83
-            print("Unknown command!")
68
+    if len(sys.argv) == 1:
69
+        readline.parse_and_bind("tab: complete")
70
+        readline.set_completer(completer)
71
+        print("\nEnter command: ")
72
+        while True:
73
+            userfeedback = input('')
74
+            command = userfeedback.split(' ')[0]
75
+            if userfeedback == 'quit':
76
+                break
77
+            elif userfeedback == 'help':
78
+                print("Help is not yet implemented!")
79
+            elif userfeedback.startswith("test"):
80
+                ts.command(userfeedback)
81
+            elif command in COMMANDS[2:]:
82
+                h.command(userfeedback)
83
+            elif userfeedback != "":
84
+                print("Unknown command!")
85
+            else:
86
+                print()
87
+    else:
88
+        cmd = sys.argv[1]
89
+        if cmd.startswith('test'):
90
+            ts.command(cmd)
84 91
         else:
85
-            print()
92
+            h.command(cmd)
93
+
94
+    del (ts)

+ 11
- 0
templates/macros.tex Zobrazit soubor

@@ -0,0 +1,11 @@
1
+{%- macro latex_filter(text) -%}{{ text.replace('\\', '/').replace('%', '\\%').replace('/xc2/xb0', '$^\circ$').replace('"', '\'').replace('/', '/\\allowbreak ').replace('&', '\\allowbreak \\&').replace('_', '\\_').replace('->', '$\\rightarrow$').replace('<-', '$\\leftarrow$').replace('=>', '$\\Rightarrow$').replace('<=', '$\\leq$').replace('>=', '$\\geq$').replace('<', '$<$').replace('>', '$>$').replace('{', '\{').replace('}', '\}').replace('#', '\\#')}}
2
+{%- endmacro -%}
3
+
4
+{%- macro color_by_level(level) -%}{% if level <= 10 %}black{% else %}{% if level <= 20 %}green{% else %}{% if level <= 30 %}orange{% else %}red{% endif %}{% endif %}{% endif %}
5
+{%- endmacro -%}
6
+
7
+{%- macro bg_by_levelno(level) -%}{% if level <= 10 %}0.8 0.8 0.8{% else %}{% if level <= 20 %}0.8 0.95 0.8{% else %}{% if level <= 30 %}1 0.75 0.45{% else %}0.95 0.8 0.8{% endif %}{% endif %}{% endif %}
8
+{%- endmacro -%}
9
+
10
+{%- macro result(level) -%}{% if level <= 10 %}Info{% else %}{% if level <= 20 %}\textcolor{green}{Success}{% else %}{% if level <= 30 %}\textcolor{orange}{Warning}{% else %}\textcolor{red}{Failed}{% endif %}{% endif %}{% endif %}
11
+{%- endmacro -%}

+ 36
- 0
templates/report_testcase.tex Zobrazit soubor

@@ -0,0 +1,36 @@
1
+{%- import 'macros.tex' as macros %}
2
+\paragraph{Testsummary}\mbox{}\\
3
+This test was passed with the state: {\bf {{ macros.result(testcase.levelno) }}}.
4
+\begin{longtabu} to \linewidth {lX}
5
+\toprule
6
+Caller: & {{ macros.latex_filter(testcase.pathname) }} ({{ "%d" % testcase.lineno }})\\
7
+Start-Time: & {{ macros.latex_filter(testcase.time_start) }}\\
8
+Finished-Time: & {{ macros.latex_filter(testcase.time_finished) }}\\
9
+Time-Consumption & {{ '%.3fs' % (testcase.time_consumption) }}\\
10
+\midrule
11
+\multicolumn{2}{l}{\bf{Testresults:}}\\
12
+\midrule
13
+{%- for tLogger in testcase.testcaseLogger %}
14
+\bf{\,{{ macros.result(tLogger.levelno) }} } & {{ macros.latex_filter(tLogger.message) }}\\
15
+{%- endfor %}
16
+\bottomrule
17
+\end{longtabu}
18
+
19
+{% if details== true %}
20
+\paragraph{Testdetails}\mbox{}\\
21
+{%- for tLogger in testcase.testcaseLogger %}
22
+    \begin{tabu} to \linewidth {lX}
23
+    \toprule
24
+    {\bf {{ macros.result(tLogger.levelno) }} } & {{ macros.latex_filter(tLogger.message) }}\\
25
+    \bottomrule
26
+    \end{tabu}
27
+    {%- for mLogger in tLogger.moduleLogger %}
28
+        \definecolor{shadecolor}{rgb}{ {{macros.bg_by_levelno(mLogger.levelno) }} }\begin{modulelog}[breaklines=true, breakanywhere=true]
29
+        {{ mLogger.message }}
30
+        \end{modulelog}
31
+        \vspace*{-0.225cm}\pagebreak[1]
32
+    {%- endfor %}
33
+
34
+    \vspace*{2.5ex}
35
+{%- endfor %}
36
+{% endif %}

+ 13
- 0
templates/run_statistic.tex Zobrazit soubor

@@ -0,0 +1,13 @@
1
+{%- import 'macros.tex' as macros %}
2
+\begin{tabu} to \linewidth {lX}
3
+	\toprule
4
+	Number of tests & {{ "{\\bf %d}" % testrun.number_of_tests }}\\
5
+	Number of successfull tests & {{ "{\\bf %d}" % testrun.number_of_successfull_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 }}\\
8
+	\midrule
9
+	Executionlevel    & {{ macros.latex_filter(testrun.testcase_names.get('%d' % testrun.testcase_execution_level, 'unknown')) }}\\
10
+	Time consumption  & {{ '%.3fs' % testrun.time_consumption }}\\
11
+	\bottomrule
12
+\end{tabu}
13
+

+ 12
- 0
templates/system.tex Zobrazit soubor

@@ -0,0 +1,12 @@
1
+{%- import 'macros.tex' as macros %}
2
+\begin{tabu} to \linewidth {lX}
3
+\toprule
4
+{\bf System Information}   & \\
5
+\midrule
6
+{%- for key in system_information %}
7
+{%- if key != "Description" %}
8
+{{macros.latex_filter(key)}} & {{macros.latex_filter(data.system_information[key])}} \\
9
+{%- endif %}
10
+{%- endfor %}
11
+\bottomrule
12
+\end{tabu}

+ 49
- 0
templates/unittest.tex Zobrazit soubor

@@ -0,0 +1,49 @@
1
+{%- import 'macros.tex' as macros %}
2
+{%- include 'unittest_head.tex' %}
3
+{%- include 'unittest_titlepage.tex' %}
4
+
5
+\tableofcontents
6
+\newpage
7
+
8
+\section{Test System Information}
9
+{%- with system_information = data.system_information %}
10
+  {%- include 'system.tex' %}
11
+{%- endwith %}
12
+
13
+
14
+\section{Summary}
15
+{%- with testrun = data %}
16
+  {%- include 'run_statistic.tex' %}
17
+{%- endwith %}
18
+
19
+{% if data.number_of_failed_tests > 0 or data.number_of_possibly_failed_tests > 0%}
20
+  \section{\textcolor{red}{Testcases (Failed)}}
21
+  {%- for test_name in data.uid_list_sorted %}
22
+    {% with testcase = data.testcases[test_name] %}
23
+      {% if testcase.levelno > 20 %}
24
+        \subsection{ {{macros.latex_filter(testcase.message)}} }
25
+        {% with details = true %}
26
+          {% include 'report_testcase.tex' %}
27
+        {% endwith %}
28
+      {% endif %}
29
+    {% endwith %}
30
+  {% endfor %}
31
+{% endif %}
32
+
33
+
34
+{% if data.number_of_successfull_tests > 0 %}
35
+  \section{\textcolor{green}{Testcases (Success)}}
36
+  {%- for test_name in data.uid_list_sorted %}
37
+    {% with testcase = data.testcases[test_name] %}
38
+      {% if testcase.levelno <= 20 %}
39
+        \subsection{ {{macros.latex_filter(testcase.message)}} }
40
+        {% with details = details %}
41
+          {% include 'report_testcase.tex' %}
42
+        {% endwith %}
43
+      {% endif %}
44
+    {% endwith %}
45
+  {% endfor %}
46
+{% endif %}
47
+
48
+
49
+{% include 'unittest_foot.tex' %}

+ 1
- 0
templates/unittest_foot.tex Zobrazit soubor

@@ -0,0 +1 @@
1
+\end{document}

+ 89
- 0
templates/unittest_head.tex Zobrazit soubor

@@ -0,0 +1,89 @@
1
+{%- import 'macros.tex' as macros %}
2
+\documentclass[a4paper]{article}
3
+%\documentclass[a4paper,landscape]{article}
4
+
5
+\renewcommand{\familydefault}{\sfdefault}
6
+\usepackage[table]{xcolor}
7
+\definecolor{orange}{rgb}{1, 0.7, 0}
8
+\definecolor{lightgrey}{rgb}{0.925, 0.925, 0.925}
9
+
10
+\setlength{\topmargin}{-3cm}
11
+\setlength{\oddsidemargin}{-0.5cm}
12
+\setlength{\evensidemargin}{0cm}
13
+\setlength{\textwidth}{17.5cm}
14
+\setlength{\textheight}{24.5cm}
15
+%\setlength{\textwidth}{25cm}
16
+%\setlength{\textheight}{15cm}
17
+\setlength{\headheight}{84pt}
18
+
19
+\usepackage{fancyvrb}
20
+\usepackage{fvextra}
21
+%\usepackage{framed,color}
22
+%\newenvironment{modulelog}{\snugshade\Verbatim}{\endVerbatim\endsnugshade}
23
+\usepackage{adjustbox}
24
+\newenvironment{modulelog}%
25
+{\par\noindent\adjustbox{margin=0ex,bgcolor=shadecolor,margin=0ex}\bgroup\varwidth\linewidth\Verbatim}%
26
+{\endVerbatim\endvarwidth\egroup}
27
+%\usepackage{xcolor}
28
+
29
+\renewcommand{\baselinestretch}{1,2}
30
+\setlength{\parindent}{0pt}
31
+\setlength{\parskip}{9pt plus3pt minus3pt}
32
+
33
+\usepackage{listings}
34
+\usepackage{color}
35
+\definecolor{bg-partially-covered}{rgb}{1,1,0.6}    % light-yellow
36
+\definecolor{bg-uncovered}{rgb}{1,0.8,0.8}          % light-red
37
+\definecolor{bg-covered}{rgb}{0.95,1,0.95}          % very light-green
38
+\definecolor{bg-clean}{rgb}{1,1,1}                  % white
39
+\definecolor{mygreen}{rgb}{0,0.6,0}
40
+\definecolor{mygray}{rgb}{0.5,0.5,0.5}
41
+\definecolor{mymauve}{rgb}{0.58,0,0.82}
42
+\lstset{ %
43
+  backgroundcolor=\color{white},   % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}; should come as last argument
44
+  basicstyle=\footnotesize,        % the size of the fonts that are used for the code
45
+  breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace
46
+  breaklines=true,                 % sets automatic line breaking
47
+  captionpos=b,                    % sets the caption-position to bottom
48
+  commentstyle=\color{mygreen},    % comment style
49
+  deletekeywords={...},            % if you want to delete keywords from the given language
50
+  escapeinside={\%*}{*)},          % if you want to add LaTeX within your code
51
+  extendedchars=true,              % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
52
+  frame=none,	                   % adds a frame around the code
53
+  keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
54
+  keywordstyle=\color{blue},       % keyword style
55
+  language=Octave,                 % the language of the code
56
+  morekeywords={*,...},            % if you want to add more keywords to the set
57
+  numbers=left,                    % where to put the line-numbers; possible values are (none, left, right)
58
+  numbersep=5pt,                   % how far the line-numbers are from the code
59
+  numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
60
+  rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
61
+  showlines=true,
62
+  showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
63
+  showstringspaces=false,          % underline spaces within strings only
64
+  showtabs=false,                  % show tabs within strings adding particular underscores
65
+  stepnumber=1,                    % the step between two line-numbers. If it's 1, each line will be numbered
66
+  stringstyle=\color{mymauve},     % string literal style
67
+  tabsize=2,	                   % sets default tabsize to 2 spaces
68
+}
69
+\usepackage{hyperref}
70
+\usepackage{longtable}[=v4.13]
71
+\usepackage{tabu}
72
+\usepackage{multicol}
73
+\usepackage{booktabs}
74
+\usepackage{graphicx}
75
+\usepackage{lastpage} % for the number of the last page in the document
76
+\usepackage{fancyhdr}
77
+
78
+\fancyhf{}
79
+\renewcommand{\headrulewidth}{0pt}
80
+\renewcommand{\footrulewidth}{0pt}
81
+\lhead{\textcolor{gray}{}}
82
+\chead{\textcolor{gray}{ Unittest for {\tt smart\_brain }}}
83
+\rhead{\textcolor{gray}{}}
84
+\lfoot{\textcolor{gray}{}}
85
+\cfoot{\textcolor{gray}{}}
86
+\rfoot{\textcolor{gray}{\thepage\,/ \pageref{LastPage}}}
87
+
88
+\begin{document}
89
+

+ 14
- 0
templates/unittest_titlepage.tex Zobrazit soubor

@@ -0,0 +1,14 @@
1
+{%- import 'macros.tex' as macros %}
2
+\begin{titlepage}
3
+\date{\today}
4
+\title{
5
+	Unittest for {\tt smart\_brain }
6
+}
7
+\date{\today} 
8
+\maketitle
9
+\thispagestyle{empty}
10
+\newpage
11
+\end{titlepage}
12
+
13
+\setcounter{page}{1}
14
+\pagestyle{fancy}

+ 6409
- 0
testresults/testrun.json
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


binární
testresults/testrun.pdf Zobrazit soubor


+ 304
- 0
testresults/testrun.tex Zobrazit soubor

@@ -0,0 +1,304 @@
1
+
2
+\documentclass[a4paper]{article}
3
+%\documentclass[a4paper,landscape]{article}
4
+
5
+\renewcommand{\familydefault}{\sfdefault}
6
+\usepackage[table]{xcolor}
7
+\definecolor{orange}{rgb}{1, 0.7, 0}
8
+\definecolor{lightgrey}{rgb}{0.925, 0.925, 0.925}
9
+
10
+\setlength{\topmargin}{-3cm}
11
+\setlength{\oddsidemargin}{-0.5cm}
12
+\setlength{\evensidemargin}{0cm}
13
+\setlength{\textwidth}{17.5cm}
14
+\setlength{\textheight}{24.5cm}
15
+%\setlength{\textwidth}{25cm}
16
+%\setlength{\textheight}{15cm}
17
+\setlength{\headheight}{84pt}
18
+
19
+\usepackage{fancyvrb}
20
+\usepackage{fvextra}
21
+%\usepackage{framed,color}
22
+%\newenvironment{modulelog}{\snugshade\Verbatim}{\endVerbatim\endsnugshade}
23
+\usepackage{adjustbox}
24
+\newenvironment{modulelog}%
25
+{\par\noindent\adjustbox{margin=0ex,bgcolor=shadecolor,margin=0ex}\bgroup\varwidth\linewidth\Verbatim}%
26
+{\endVerbatim\endvarwidth\egroup}
27
+%\usepackage{xcolor}
28
+
29
+\renewcommand{\baselinestretch}{1,2}
30
+\setlength{\parindent}{0pt}
31
+\setlength{\parskip}{9pt plus3pt minus3pt}
32
+
33
+\usepackage{listings}
34
+\usepackage{color}
35
+\definecolor{bg-partially-covered}{rgb}{1,1,0.6}    % light-yellow
36
+\definecolor{bg-uncovered}{rgb}{1,0.8,0.8}          % light-red
37
+\definecolor{bg-covered}{rgb}{0.95,1,0.95}          % very light-green
38
+\definecolor{bg-clean}{rgb}{1,1,1}                  % white
39
+\definecolor{mygreen}{rgb}{0,0.6,0}
40
+\definecolor{mygray}{rgb}{0.5,0.5,0.5}
41
+\definecolor{mymauve}{rgb}{0.58,0,0.82}
42
+\lstset{ %
43
+  backgroundcolor=\color{white},   % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}; should come as last argument
44
+  basicstyle=\footnotesize,        % the size of the fonts that are used for the code
45
+  breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace
46
+  breaklines=true,                 % sets automatic line breaking
47
+  captionpos=b,                    % sets the caption-position to bottom
48
+  commentstyle=\color{mygreen},    % comment style
49
+  deletekeywords={...},            % if you want to delete keywords from the given language
50
+  escapeinside={\%*}{*)},          % if you want to add LaTeX within your code
51
+  extendedchars=true,              % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
52
+  frame=none,	                   % adds a frame around the code
53
+  keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
54
+  keywordstyle=\color{blue},       % keyword style
55
+  language=Octave,                 % the language of the code
56
+  morekeywords={*,...},            % if you want to add more keywords to the set
57
+  numbers=left,                    % where to put the line-numbers; possible values are (none, left, right)
58
+  numbersep=5pt,                   % how far the line-numbers are from the code
59
+  numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
60
+  rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
61
+  showlines=true,
62
+  showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
63
+  showstringspaces=false,          % underline spaces within strings only
64
+  showtabs=false,                  % show tabs within strings adding particular underscores
65
+  stepnumber=1,                    % the step between two line-numbers. If it's 1, each line will be numbered
66
+  stringstyle=\color{mymauve},     % string literal style
67
+  tabsize=2,	                   % sets default tabsize to 2 spaces
68
+}
69
+\usepackage{hyperref}
70
+\usepackage{longtable}[=v4.13]
71
+\usepackage{tabu}
72
+\usepackage{multicol}
73
+\usepackage{booktabs}
74
+\usepackage{graphicx}
75
+\usepackage{lastpage} % for the number of the last page in the document
76
+\usepackage{fancyhdr}
77
+
78
+\fancyhf{}
79
+\renewcommand{\headrulewidth}{0pt}
80
+\renewcommand{\footrulewidth}{0pt}
81
+\lhead{\textcolor{gray}{}}
82
+\chead{\textcolor{gray}{ Unittest for {\tt smart\_brain }}}
83
+\rhead{\textcolor{gray}{}}
84
+\lfoot{\textcolor{gray}{}}
85
+\cfoot{\textcolor{gray}{}}
86
+\rfoot{\textcolor{gray}{\thepage\,/ \pageref{LastPage}}}
87
+
88
+\begin{document}
89
+
90
+\begin{titlepage}
91
+\date{\today}
92
+\title{
93
+	Unittest for {\tt smart\_brain }
94
+}
95
+\date{\today} 
96
+\maketitle
97
+\thispagestyle{empty}
98
+\newpage
99
+\end{titlepage}
100
+
101
+\setcounter{page}{1}
102
+\pagestyle{fancy}
103
+
104
+\tableofcontents
105
+\newpage
106
+
107
+\section{Test System Information}
108
+\begin{tabu} to \linewidth {lX}
109
+\toprule
110
+{\bf System Information}   & \\
111
+\midrule
112
+Architecture & 64bit \\
113
+Machine & x86\_64 \\
114
+Hostname & ahorn \\
115
+Distribution & Linux Mint 21.1 (vera) \\
116
+System & Linux \\
117
+Kernel & 5.15.0-58-generic (\#64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023) \\
118
+Username & dirk \\
119
+Path & /\allowbreak home/\allowbreak dirk/\allowbreak my\_repositories/\allowbreak smarthome/\allowbreak smart\_brain\_test/\allowbreak all.py \\
120
+\bottomrule
121
+\end{tabu}
122
+
123
+
124
+\section{Summary}
125
+\begin{tabu} to \linewidth {lX}
126
+	\toprule
127
+	Number of tests & {\bf 5}\\
128
+	Number of successfull tests & {\bf 5}\\
129
+	Number of possibly failed tests & \textcolor{black}{\bf 0}\\
130
+	Number of failed tests & \textcolor{black}{\bf 0}\\
131
+	\midrule
132
+	Executionlevel    & unknown\\
133
+	Time consumption  & 4.510s\\
134
+	\bottomrule
135
+\end{tabu}
136
+
137
+
138
+
139
+
140
+
141
+
142
+  \section{\textcolor{green}{Testcases (Success)}}
143
+    
144
+      
145
+        \subsection{ Away mode test: zigbee/\allowbreak gfw/\allowbreak dirk/\allowbreak heating\_valve }
146
+        
147
+          
148
+\paragraph{Testsummary}\mbox{}\\
149
+This test was passed with the state: {\bf \textcolor{green}{Success}}.
150
+\begin{longtabu} to \linewidth {lX}
151
+\toprule
152
+Caller: & /\allowbreak home/\allowbreak dirk/\allowbreak my\_repositories/\allowbreak smarthome/\allowbreak smart\_brain\_test/\allowbreak tests/\allowbreak heating.py (84)\\
153
+Start-Time: & 2023-02-09 07:53:02,566\\
154
+Finished-Time: & 2023-02-09 07:53:03,468\\
155
+Time-Consumption & 0.902s\\
156
+\midrule
157
+\multicolumn{2}{l}{\bf{Testresults:}}\\
158
+\midrule
159
+\bf{\,Info } & Setting preconditions (Default setpoint)\\
160
+\bf{\,\textcolor{green}{Success} } & Away mode is correct (Content False and Type is $<$class 'bool'$>$).\\
161
+\bf{\,Info } & Activating away mode\\
162
+\bf{\,\textcolor{green}{Success} } & Away mode is correct (Content True and Type is $<$class 'bool'$>$).\\
163
+\bf{\,\textcolor{green}{Success} } & Temperature setpoint is correct (Content 20 and Type is $<$class 'int'$>$).\\
164
+\bf{\,Info } & Deactivating away mode\\
165
+\bf{\,\textcolor{green}{Success} } & Away mode is correct (Content False and Type is $<$class 'bool'$>$).\\
166
+\bf{\,\textcolor{green}{Success} } & Temperature setpoint is correct (Content 25 and Type is $<$class 'int'$>$).\\
167
+\bottomrule
168
+\end{longtabu}
169
+
170
+
171
+        
172
+      
173
+    
174
+  
175
+    
176
+      
177
+        \subsection{ Boost mode test: zigbee/\allowbreak gfw/\allowbreak dirk/\allowbreak heating\_valve }
178
+        
179
+          
180
+\paragraph{Testsummary}\mbox{}\\
181
+This test was passed with the state: {\bf \textcolor{green}{Success}}.
182
+\begin{longtabu} to \linewidth {lX}
183
+\toprule
184
+Caller: & /\allowbreak home/\allowbreak dirk/\allowbreak my\_repositories/\allowbreak smarthome/\allowbreak smart\_brain\_test/\allowbreak tests/\allowbreak heating.py (107)\\
185
+Start-Time: & 2023-02-09 07:53:03,468\\
186
+Finished-Time: & 2023-02-09 07:53:04,370\\
187
+Time-Consumption & 0.902s\\
188
+\midrule
189
+\multicolumn{2}{l}{\bf{Testresults:}}\\
190
+\midrule
191
+\bf{\,Info } & Setting preconditions (Default setpoint)\\
192
+\bf{\,\textcolor{green}{Success} } & Boost timer is correct (Content 0 and Type is $<$class 'int'$>$).\\
193
+\bf{\,Info } & Activating boost mode\\
194
+\bf{\,\textcolor{green}{Success} } & Boost timer is greater expectation (Content 900 and Type is $<$class 'int'$>$).\\
195
+\bf{\,Info } & Setting postconditions (Default setpoint)\\
196
+\bf{\,\textcolor{green}{Success} } & Boost timer is correct (Content 0 and Type is $<$class 'int'$>$).\\
197
+\bottomrule
198
+\end{longtabu}
199
+
200
+
201
+        
202
+      
203
+    
204
+  
205
+    
206
+      
207
+        \subsection{ Default temperature test for device and virtual device: zigbee/\allowbreak gfw/\allowbreak dirk/\allowbreak heating\_valve }
208
+        
209
+          
210
+\paragraph{Testsummary}\mbox{}\\
211
+This test was passed with the state: {\bf \textcolor{green}{Success}}.
212
+\begin{longtabu} to \linewidth {lX}
213
+\toprule
214
+Caller: & /\allowbreak home/\allowbreak dirk/\allowbreak my\_repositories/\allowbreak smarthome/\allowbreak smart\_brain\_test/\allowbreak tests/\allowbreak heating.py (41)\\
215
+Start-Time: & 2023-02-09 07:53:04,370\\
216
+Finished-Time: & 2023-02-09 07:53:04,972\\
217
+Time-Consumption & 0.601s\\
218
+\midrule
219
+\multicolumn{2}{l}{\bf{Testresults:}}\\
220
+\midrule
221
+\bf{\,Info } & Setting preconditions (Valve setpoint to 20.0)\\
222
+\bf{\,\textcolor{green}{Success} } & Valve temperature setpoint (is not default temperature) is correct (Content True and Type is $<$class 'bool'$>$).\\
223
+\bf{\,Info } & Triggering set to default temperature (25.0)\\
224
+\bf{\,\textcolor{green}{Success} } & Valve temperature setpoint is correct (Content 25 and Type is $<$class 'int'$>$).\\
225
+\bottomrule
226
+\end{longtabu}
227
+
228
+
229
+        
230
+      
231
+    
232
+  
233
+    
234
+      
235
+        \subsection{ Summer mode test: zigbee/\allowbreak gfw/\allowbreak dirk/\allowbreak heating\_valve }
236
+        
237
+          
238
+\paragraph{Testsummary}\mbox{}\\
239
+This test was passed with the state: {\bf \textcolor{green}{Success}}.
240
+\begin{longtabu} to \linewidth {lX}
241
+\toprule
242
+Caller: & /\allowbreak home/\allowbreak dirk/\allowbreak my\_repositories/\allowbreak smarthome/\allowbreak smart\_brain\_test/\allowbreak tests/\allowbreak heating.py (61)\\
243
+Start-Time: & 2023-02-09 07:53:04,972\\
244
+Finished-Time: & 2023-02-09 07:53:05,874\\
245
+Time-Consumption & 0.902s\\
246
+\midrule
247
+\multicolumn{2}{l}{\bf{Testresults:}}\\
248
+\midrule
249
+\bf{\,Info } & Setting preconditions (Default setpoint)\\
250
+\bf{\,\textcolor{green}{Success} } & Summer mode is correct (Content False and Type is $<$class 'bool'$>$).\\
251
+\bf{\,Info } & Activating summer mode\\
252
+\bf{\,\textcolor{green}{Success} } & Summer mode is correct (Content True and Type is $<$class 'bool'$>$).\\
253
+\bf{\,\textcolor{green}{Success} } & Temperature setpoint is correct (Content 5 and Type is $<$class 'int'$>$).\\
254
+\bf{\,Info } & Deactivating summer mode\\
255
+\bf{\,\textcolor{green}{Success} } & Summer mode is correct (Content False and Type is $<$class 'bool'$>$).\\
256
+\bf{\,\textcolor{green}{Success} } & Temperature setpoint is correct (Content 25 and Type is $<$class 'int'$>$).\\
257
+\bottomrule
258
+\end{longtabu}
259
+
260
+
261
+        
262
+      
263
+    
264
+  
265
+    
266
+      
267
+        \subsection{ User temperature setpoint test for device and virtual device: zigbee/\allowbreak gfw/\allowbreak dirk/\allowbreak heating\_valve }
268
+        
269
+          
270
+\paragraph{Testsummary}\mbox{}\\
271
+This test was passed with the state: {\bf \textcolor{green}{Success}}.
272
+\begin{longtabu} to \linewidth {lX}
273
+\toprule
274
+Caller: & /\allowbreak home/\allowbreak dirk/\allowbreak my\_repositories/\allowbreak smarthome/\allowbreak smart\_brain\_test/\allowbreak tests/\allowbreak heating.py (17)\\
275
+Start-Time: & 2023-02-09 07:53:05,874\\
276
+Finished-Time: & 2023-02-09 07:53:07,076\\
277
+Time-Consumption & 1.203s\\
278
+\midrule
279
+\multicolumn{2}{l}{\bf{Testresults:}}\\
280
+\midrule
281
+\bf{\,Info } & Changing valve temperature setpoint to '20.0'\\
282
+\bf{\,\textcolor{green}{Success} } & Virtual device valve temperature is correct (Content 20 and Type is $<$class 'int'$>$).\\
283
+\bf{\,\textcolor{green}{Success} } & Virtual device user temperature is correct (Content 20 and Type is $<$class 'int'$>$).\\
284
+\bf{\,Info } & Changing videv user temperature setpoint to '25.0'\\
285
+\bf{\,\textcolor{green}{Success} } & Valve device temperature setpoint is correct (Content 25 and Type is $<$class 'int'$>$).\\
286
+\bf{\,\textcolor{green}{Success} } & Virtual device valve temperature is correct (Content 25 and Type is $<$class 'int'$>$).\\
287
+\bf{\,Info } & Changing valve temperature setpoint to '20.0'\\
288
+\bf{\,\textcolor{green}{Success} } & Virtual device valve temperature is correct (Content 20 and Type is $<$class 'int'$>$).\\
289
+\bf{\,\textcolor{green}{Success} } & Virtual device user temperature is correct (Content 20 and Type is $<$class 'int'$>$).\\
290
+\bf{\,Info } & Changing videv user temperature setpoint to '25.0'\\
291
+\bf{\,\textcolor{green}{Success} } & Valve device temperature setpoint is correct (Content 25 and Type is $<$class 'int'$>$).\\
292
+\bf{\,\textcolor{green}{Success} } & Virtual device valve temperature is correct (Content 25 and Type is $<$class 'int'$>$).\\
293
+\bottomrule
294
+\end{longtabu}
295
+
296
+
297
+        
298
+      
299
+    
300
+  
301
+
302
+
303
+
304
+\end{document}

binární
testresults/testrun_full.pdf Zobrazit soubor


+ 1328
- 0
testresults/testrun_full.tex
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 13
- 366
tests/__init__.py Zobrazit soubor

@@ -1,137 +1,26 @@
1
-import colored
2
-import config
3
-import inspect
4
-import simulation.devices as devices
5
-import time
6
-
1
+import report
2
+import simulation.devices
3
+from unittest.test import equivalency_chk
7 4
 
8 5
 DT_TOGGLE = 0.3
9 6
 
10 7
 
11
-TEST_FULL = 'full'
12
-TEST_SMOKE = 'smoke'
13
-#
14
-COLOR_SUCCESS = colored.fg("light_green")
15
-COLOR_FAIL = colored.fg("light_red")
16
-
17
-
18
-class test_smarthome(object):
19
-    def __init__(self, rooms):
20
-        # add testcases for switching devices
21
-        for name in rooms.getmembers():
22
-            obj = rooms.getobjbyname(name)
23
-            if obj.__class__.__name__ == "videv_light":
24
-                common_name = '.'.join(name.split('.')[:-1]) + '.' + name.split('.')[-1][6:]
25
-                try:
26
-                    li_device = rooms.getobjbyname(common_name + '_zigbee') if obj.enable_brightness or obj.enable_color_temp else None
27
-                except AttributeError:
28
-                    li_device = rooms.getobjbyname(common_name + '_zigbee_1') if obj.enable_brightness or obj.enable_color_temp else None
29
-                try:
30
-                    sw_device = rooms.getobjbyname(common_name) if obj.enable_state else None
31
-                except AttributeError:
32
-                    # must be a device without switching device
33
-                    sw_device = li_device
34
-                setattr(self, common_name.replace('.', '_'), testcase_light(obj, sw_device, li_device))
35
-        # add testcases for heating devices
36
-        for name in rooms.getmembers():
37
-            obj = rooms.getobjbyname(name)
38
-            if obj.__class__.__name__ == "videv_heating":
39
-                common_name = '.'.join(name.split('.')[:-1]) + '.' + name.split('.')[-1][6:]
40
-                heat_device = rooms.getobjbyname(common_name + '_valve')
41
-                setattr(self, common_name.replace('.', '_'), testcase_heating(obj, heat_device))
42
-        # synchronisation
43
-        self.gfw_dirk_cd_player_amplifier_sync = testcase_synchronisation(
44
-            rooms.gfw.dirk.cd_player, None, None,
45
-            rooms.gfw.dirk.amplifier)
46
-        self.gfw_floor_main_light_sync = testcase_synchronisation(
47
-            rooms.gfw.floor.main_light, rooms.gfw.floor.videv_main_light, rooms.gfw.floor.videv_main_light,
48
-            rooms.gfw.floor.main_light_zigbee_1, rooms.gfw.floor.main_light_zigbee_2
49
-        )
50
-        self.ffe_diningroom_main_light_floor_lamp_sync = testcase_synchronisation(
51
-            rooms.ffe.diningroom.main_light, None, None,
52
-            rooms.ffe.diningroom.floor_lamp)
53
-        self.ffe_livingroom_main_light_floor_lamp_sync = testcase_synchronisation(
54
-            rooms.ffe.livingroom.main_light, rooms.ffe.livingroom.videv_floor_lamp, rooms.ffe.livingroom.videv_floor_lamp,
55
-            *[getattr(rooms.ffe.livingroom, "floor_lamp_zigbee_%d" % i) for i in range(1, 7)]
56
-        )
57
-        # add test collection
58
-        self.all = test_collection(self)
59
-
60
-    def getmembers(self, prefix=''):
61
-        rv = []
62
-        for name, obj in inspect.getmembers(self):
63
-            if prefix:
64
-                full_name = prefix + '.' + name
65
-            else:
66
-                full_name = name
67
-            if not name.startswith('_'):
68
-                try:
69
-                    if obj.__class__.__bases__[0].__name__ == "testcase" or obj.__class__.__name__ == "test_collection":
70
-                        rv.append(full_name)
71
-                    else:
72
-                        rv.extend(obj.getmembers(full_name))
73
-                except AttributeError:
74
-                    pass
75
-        return rv
76
-
77
-    def getobjbyname(self, name):
78
-        if name.startswith("test."):
79
-            name = name[5:]
80
-        obj = self
81
-        for subname in name.split('.'):
82
-            obj = getattr(obj, subname)
83
-        return obj
84
-
85
-    def command(self, full_command):
86
-        try:
87
-            parameter = " " + full_command.split(' ')[1]
88
-        except IndexError:
89
-            parameter = ""
90
-        command = full_command.split(' ')[0].split('.')[-1] + parameter
91
-        device_name = '.'.join(full_command.split(' ')[0].split('.')[:-1])
92
-        self.getobjbyname(device_name).command(command)
93
-
94
-
95
-class test_result_base(object):
96
-    def __init__(self):
97
-        self.__init_test_counters__()
98
-
99
-    def __init_test_counters__(self):
100
-        self.test_counter = 0
101
-        self.success_tests = 0
102
-        self.failed_tests = 0
103
-
104
-    def statistic(self):
105
-        return (self.test_counter, self.success_tests, self.failed_tests)
106
-
107
-    def print_statistic(self):
108
-        color = COLOR_SUCCESS if self.test_counter == self.success_tests else COLOR_FAIL
109
-        print(color + "*** SUCCESS: (%4d/%4d)   FAIL: (%4d/%4d) ***\n" % (self.success_tests,
110
-              self.test_counter, self.failed_tests, self.test_counter) + colored.attr("reset"))
111
-
112
-
113
-class test_collection(test_result_base):
8
+class test_collection(object):
114 9
     def __init__(self, test_instance):
115 10
         super().__init__()
116 11
         self.test_instance = test_instance
117 12
 
118 13
     def capabilities(self):
119
-        return [TEST_FULL, TEST_SMOKE]
14
+        return ['full', 'smoke']
120 15
 
121 16
     def command(self, command):
122
-        self.__init_test_counters__()
123 17
         for member in self.test_instance.getmembers():
124 18
             obj = self.test_instance.getobjbyname(member)
125 19
             if id(obj) != id(self):
126
-                obj.test_all(command)
127
-                num, suc, fail = obj.statistic()
128
-                self.test_counter += num
129
-                self.success_tests += suc
130
-                self.failed_tests += fail
131
-        self.print_statistic()
20
+                obj.test_all(report.TCEL_FULL if command == 'full' else report.TCEL_SMOKE)
132 21
 
133 22
 
134
-class testcase(test_result_base):
23
+class testcase(object):
135 24
     def __init__(self):
136 25
         super().__init__()
137 26
         self.__test_list__ = []
@@ -142,255 +31,13 @@ class testcase(test_result_base):
142 31
         self.__test_list__.sort()
143 32
         return self.__test_list__
144 33
 
145
-    def test_all(self, test=TEST_FULL):
146
-        test_counter = 0
147
-        success_tests = 0
148
-        failed_tests = 0
34
+    def test_all(self, tcel=report.TCEL_FULL):
149 35
         for tc_name in self.capabilities():
150 36
             if tc_name != "test_all":
151
-                self.command(tc_name, test)
152
-                test_counter += self.test_counter
153
-                success_tests += self.success_tests
154
-                failed_tests += self.failed_tests
155
-        self.test_counter = test_counter
156
-        self.success_tests = success_tests
157
-        self.failed_tests = failed_tests
37
+                self.command(tc_name, tcel)
158 38
 
159
-    def command(self, command, test=TEST_FULL):
160
-        self.__init_test_counters__()
39
+    def command(self, command, tcel=report.TCEL_FULL):
40
+        simulation.devices.OUTPUT_ACTIVE = False
161 41
         tc = getattr(self, command)
162
-        self.__init_test_counters__()
163
-        tc(test)
164
-        self.print_statistic()
165
-
166
-    def heading(self, desciption):
167
-        print(desciption)
168
-
169
-    def sub_heading(self, desciption):
170
-        print(2 * " " + desciption)
171
-
172
-    def result(self, desciption, success):
173
-        self.test_counter += 1
174
-        if success:
175
-            self.success_tests += 1
176
-        else:
177
-            self.failed_tests += 1
178
-        print(4 * " " + ("SUCCESS - " if success else "FAIL    - ") + desciption)
179
-
180
-
181
-class testcase_light(testcase):
182
-    def __init__(self, videv, sw_device, li_device):
183
-        self.videv = videv
184
-        self.sw_device = sw_device
185
-        self.li_device = li_device
186
-        self.__test_list__ = []
187
-        if self.videv.enable_state:
188
-            self.__test_list__.append('test_power_on_off')
189
-        if self.videv.enable_brightness:
190
-            self.__test_list__.append('test_brightness')
191
-        if self.videv.enable_color_temp:
192
-            self.__test_list__.append('test_color_temp')
193
-
194
-    def test_power_on_off(self, test=TEST_FULL):
195
-        self.heading("Power On/ Off test (%s)" % self.videv.topic)
196
-        #
197
-        sw_state = self.sw_device.get(self.sw_device.KEY_OUTPUT_0)
198
-        #
199
-        for i in range(0, 2):
200
-            self.sub_heading("State change of switching device")
201
-            #
202
-            self.sw_device.set(self.sw_device.KEY_OUTPUT_0, not self.sw_device.get(self.sw_device.KEY_OUTPUT_0))
203
-            time.sleep(DT_TOGGLE)
204
-            self.result("Virtual device state after Switch on by switching device", sw_state != self.videv.get(self.videv.KEY_OUTPUT_0))
205
-            self.result("Switching device state after Switch on by switching device",
206
-                        sw_state != self.sw_device.get(self.sw_device.KEY_OUTPUT_0))
207
-
208
-            self.sub_heading("State change of virtual device")
209
-            #
210
-            self.videv.set(self.videv.KEY_OUTPUT_0, not self.videv.get(self.videv.KEY_OUTPUT_0))
211
-            time.sleep(DT_TOGGLE)
212
-            self.result("Virtual device state after Switch off by virtual device", sw_state == self.videv.get(self.videv.KEY_OUTPUT_0))
213
-            self.result("Switching device state after Switch on by switching device",
214
-                        sw_state == self.sw_device.get(self.sw_device.KEY_OUTPUT_0))
215
-
216
-    def test_brightness(self, test=TEST_FULL):
217
-        self.heading("Brightness test (%s)" % self.videv.topic)
218
-        #
219
-        br_state = self.li_device.get(self.li_device.KEY_BRIGHTNESS)
220
-        delta = -15 if br_state > 50 else 15
221
-
222
-        self.sw_device.set(self.sw_device.KEY_OUTPUT_0, True)
223
-        time.sleep(DT_TOGGLE)
224
-
225
-        for i in range(0, 2):
226
-            self.sub_heading("Brightness change by light device")
227
-            #
228
-            self.li_device.set(self.li_device.KEY_BRIGHTNESS, br_state + delta)
229
-            time.sleep(DT_TOGGLE)
230
-            self.result("Virtual device state after setting brightness by light device",
231
-                        br_state + delta == self.videv.get(self.videv.KEY_BRIGHTNESS))
232
-            self.result("Light device state after setting brightness by light device", br_state +
233
-                        delta == self.li_device.get(self.li_device.KEY_BRIGHTNESS))
234
-
235
-            self.sub_heading("Brightness change by virtual device")
236
-            #
237
-            self.videv.set(self.videv.KEY_BRIGHTNESS, br_state)
238
-            time.sleep(DT_TOGGLE)
239
-            self.result("Virtual device state after setting brightness by light device", br_state == self.videv.get(self.videv.KEY_BRIGHTNESS))
240
-            self.result("Light device state after setting brightness by light device",
241
-                        br_state == self.li_device.get(self.li_device.KEY_BRIGHTNESS))
242
-
243
-        self.sw_device.set(self.sw_device.KEY_OUTPUT_0, False)
244
-        time.sleep(DT_TOGGLE)
245
-
246
-    def test_color_temp(self, test=TEST_FULL):
247
-        self.heading("Color temperature test (%s)" % self.videv.topic)
248
-        #
249
-        ct_state = self.li_device.get(self.li_device.KEY_COLOR_TEMP)
250
-        delta = -3 if ct_state > 5 else 3
251
-
252
-        self.sw_device.set(self.sw_device.KEY_OUTPUT_0, True)
253
-        time.sleep(DT_TOGGLE)
254
-
255
-        for i in range(0, 2):
256
-            self.sub_heading("Color temperature change by light device")
257
-            #
258
-            self.li_device.set(self.li_device.KEY_COLOR_TEMP, ct_state + delta)
259
-            time.sleep(DT_TOGGLE)
260
-            self.result("Virtual device state after setting color temperature by light device",
261
-                        ct_state + delta == self.videv.get(self.videv.KEY_COLOR_TEMP))
262
-            self.result("Light device state after setting color temperature by light device", ct_state +
263
-                        delta == self.li_device.get(self.li_device.KEY_COLOR_TEMP))
264
-
265
-            self.sub_heading("Color temperature change by virtual device")
266
-            #
267
-            self.videv.set(self.videv.KEY_COLOR_TEMP, ct_state)
268
-            time.sleep(DT_TOGGLE)
269
-            self.result("Virtual device state after setting color temperature by light device",
270
-                        ct_state == self.videv.get(self.videv.KEY_COLOR_TEMP))
271
-            self.result("Light device state after setting color temperature by light device",
272
-                        ct_state == self.li_device.get(self.li_device.KEY_COLOR_TEMP))
273
-
274
-        self.sw_device.set(self.sw_device.KEY_OUTPUT_0, False)
275
-        time.sleep(DT_TOGGLE)
276
-
277
-
278
-class testcase_synchronisation(testcase):
279
-    def __init__(self, sw_master, br_master, ct_master, *follower):
280
-        super().__init__()
281
-        self.sw_master = sw_master
282
-        self.br_master = br_master
283
-        self.ct_master = ct_master
284
-        self.follower = follower
285
-        self.__test_list__ = []
286
-        if sw_master is not None:
287
-            self.__test_list__.append('test_power_on_off_sync')
288
-        if br_master is not None:
289
-            self.__test_list__.append('test_brightness_sync')
290
-
291
-    def test_power_on_off_sync(self, test=TEST_FULL):
292
-        self.heading("Power On/ Off sychronisation test")
293
-        #
294
-        # set sw_master to slave state as precondition
295
-        f_state = self.follower[0].get(self.follower[0].KEY_OUTPUT_0)
296
-        self.sw_master.set(self.sw_master.KEY_OUTPUT_0, f_state)
297
-        time.sleep(DT_TOGGLE)
298
-        for i in range(0, 2):
299
-            self.sub_heading("State change of sw_master device")
300
-            #
301
-            self.sw_master.set(self.sw_master.KEY_OUTPUT_0, not f_state)
302
-            time.sleep(DT_TOGGLE)
303
-            f_state = not f_state
304
-            for fo in self.follower:
305
-                self.result("Follower device state after switching (%s)" % fo.topic,
306
-                            f_state == fo.get(fo.KEY_OUTPUT_0))
307
-
308
-    def test_brightness_sync(self, test=TEST_FULL):
309
-        self.heading("Power On/ Off sychronisation test")
310
-        #
311
-        # set precondition
312
-        sw_state = self.sw_master.get(self.sw_master.KEY_OUTPUT_0)
313
-        self.sw_master.set(self.sw_master.KEY_OUTPUT_0, True)
314
-        time.sleep(DT_TOGGLE)
315
-
316
-        target = self.follower[0].get(self.follower[0].KEY_BRIGHTNESS)
317
-        delta = 15 if target < 50 else -15
318
-        for i in range(0, 2):
319
-            target = target + delta
320
-            self.sub_heading("State change of br_master device")
321
-            #
322
-            self.br_master.set(self.br_master.KEY_BRIGHTNESS, target)
323
-            time.sleep(DT_TOGGLE)
324
-            for fo in self.follower:
325
-                self.result("Follower device brightness after change (%s)" % fo.topic,
326
-                            target == fo.get(fo.KEY_BRIGHTNESS))
327
-            delta = -delta
328
-
329
-        # reset changes of precondition
330
-        self.sw_master.set(self.sw_master.KEY_OUTPUT_0, sw_state)
331
-        time.sleep(DT_TOGGLE)
332
-
333
-
334
-class testcase_heating(testcase):
335
-    def __init__(self, videv, valve):
336
-        self.__videv__ = videv
337
-        self.__valve__ = valve
338
-        self.__default_temperature__ = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic)
339
-        self.__test_list__ = ["test_user_temperature_setpoint", "test_default_temperature", ]
340
-
341
-    def test_user_temperature_setpoint(self, test=TEST_FULL):
342
-        self.heading("User temperature setpoint test (%s)" % self.__videv__.topic)
343
-        #
344
-        mtemp = round(self.__valve__.TEMP_RANGE[0] + (self.__valve__.TEMP_RANGE[1] - self.__valve__.TEMP_RANGE[0]) / 2, 1)
345
-        setp = self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT)
346
-        delta = 5 if setp < mtemp else -5
347
-
348
-        for i in range(0, 2):
349
-            self.sub_heading("Setpoint change by valve device")
350
-            #
351
-            self.__valve__.set(self.__valve__.KEY_TEMPERATURE_SETPOINT, setp + delta)
352
-            time.sleep(DT_TOGGLE)
353
-            self.result("Virtual device valve temperature after setting temperature by valve device",
354
-                        setp + delta == self.__videv__.get(self.__videv__.KEY_VALVE_TEMPERATURE_SETPOINT))
355
-            self.result("Virtual device user temperature after setting temperature by valve device",
356
-                        setp + delta == self.__videv__.get(self.__videv__.KEY_USER_TEMPERATURE_SETPOINT))
357
-
358
-            self.sub_heading("Setpoint change by videv device")
359
-            #
360
-            self.__videv__.set(self.__videv__.KEY_USER_TEMPERATURE_SETPOINT, setp)
361
-            time.sleep(DT_TOGGLE)
362
-            self.result("Valve device temperature setpoint after setting temperature by videv device",
363
-                        setp == self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT))
364
-            self.result("Virtual device valve temperature after setting temperature by videv device",
365
-                        setp == self.__videv__.get(self.__videv__.KEY_VALVE_TEMPERATURE_SETPOINT))
366
-
367
-    def test_default_temperature(self, test=TEST_FULL):
368
-        self.heading("Default temperature setpoint test (%s)" % self.__videv__.topic)
369
-        #
370
-        dtemp = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic)
371
-        mtemp = round(self.__valve__.TEMP_RANGE[0] + (self.__valve__.TEMP_RANGE[1] - self.__valve__.TEMP_RANGE[0]) / 2, 1)
372
-        ptemp = dtemp + (5 if dtemp < mtemp else -5)
373
-
374
-        self.sub_heading("Setting setpoint to a value unequal default as precondition")
375
-        self.__valve__.set(self.__valve__.KEY_TEMPERATURE_SETPOINT, ptemp)
376
-        time.sleep(DT_TOGGLE)
377
-        self.result("Valve device temperature setpoint after setting precondition temperature",
378
-                    ptemp == self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT))
379
-
380
-        self.sub_heading("Triggering default temperature by videv device")
381
-        self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
382
-        time.sleep(DT_TOGGLE)
383
-        self.result("Valve device temperature setpoint after setting default temperature",
384
-                    dtemp == self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT))
385
-
386
-    def test_summer_mode(self, test=TEST_FULL):
387
-        pass
388
-
389
-    def test_away_mode(self, test=TEST_FULL):
390
-        pass
391
-
392
-    def test_boost_mode(self, test=TEST_FULL):
393
-        pass
394
-        if test == TEST_FULL:
395
-            # test boost timer
396
-            pass
42
+        tc(tcel)
43
+        simulation.devices.OUTPUT_ACTIVE = True

+ 139
- 0
tests/all.py Zobrazit soubor

@@ -0,0 +1,139 @@
1
+import distro
2
+import getpass
3
+import inspect
4
+import jinja2
5
+import json
6
+import os
7
+import platform
8
+import report
9
+from tests import test_collection
10
+from tests.heating import testcase_heating
11
+from tests.light import testcase_light
12
+from tests.synchronisation import testcase_synchronisation
13
+from unittest import jsonlog
14
+
15
+try:
16
+    from config import APP_NAME as ROOT_LOGGER_NAME
17
+except ImportError:
18
+    ROOT_LOGGER_NAME = 'root'
19
+
20
+
21
+class test_smarthome(object):
22
+    def __init__(self, rooms):
23
+        self.__init__tcl__()
24
+        # add testcases for switching devices
25
+        for name in rooms.getmembers():
26
+            obj = rooms.getobjbyname(name)
27
+            if obj.__class__.__name__ == "videv_light":
28
+                common_name = '.'.join(name.split('.')[:-1]) + '.' + name.split('.')[-1][6:]
29
+                try:
30
+                    li_device = rooms.getobjbyname(common_name + '_zigbee') if obj.enable_brightness or obj.enable_color_temp else None
31
+                except AttributeError:
32
+                    li_device = rooms.getobjbyname(common_name + '_zigbee_1') if obj.enable_brightness or obj.enable_color_temp else None
33
+                try:
34
+                    sw_device = rooms.getobjbyname(common_name) if obj.enable_state else None
35
+                except AttributeError:
36
+                    # must be a device without switching device
37
+                    sw_device = li_device
38
+                setattr(self, common_name.replace('.', '_'), testcase_light(self.tcl, obj, sw_device, li_device))
39
+        # add testcases for heating devices
40
+        for name in rooms.getmembers():
41
+            obj = rooms.getobjbyname(name)
42
+            if obj.__class__.__name__ == "videv_heating":
43
+                common_name = '.'.join(name.split('.')[:-1]) + '.' + name.split('.')[-1][6:]
44
+                heat_device = rooms.getobjbyname(common_name + '_valve')
45
+                setattr(self, common_name.replace('.', '_'), testcase_heating(self.tcl, obj, heat_device))
46
+        # synchronisation
47
+        # gfw.dirk.amplifier with cd_player
48
+        self.gfw_dirk_cd_player_amplifier_sync = testcase_synchronisation(
49
+            self.tcl,
50
+            rooms.gfw.dirk.cd_player, None, None,
51
+            rooms.gfw.dirk.amplifier)
52
+        # gfw.floor.main_light_2 with gfw.floor.main_light_1
53
+        self.gfw_floor_main_light_sync = testcase_synchronisation(
54
+            self.tcl,
55
+            rooms.gfw.floor.main_light, rooms.gfw.floor.videv_main_light, rooms.gfw.floor.videv_main_light,
56
+            rooms.gfw.floor.main_light_zigbee_1, rooms.gfw.floor.main_light_zigbee_2
57
+        )
58
+        # ffe.diningroom.floorlamp with ffe.dinigroom.main_light
59
+        self.ffe_diningroom_main_light_floor_lamp_sync = testcase_synchronisation(
60
+            self.tcl,
61
+            rooms.ffe.diningroom.main_light, None, None,
62
+            rooms.ffe.diningroom.floor_lamp)
63
+        # ffe.livingroom.floorlamp_[1-6] with ffe.livingroom.main_light
64
+        self.ffe_livingroom_main_light_floor_lamp_sync = testcase_synchronisation(
65
+            self.tcl,
66
+            rooms.ffe.livingroom.main_light, rooms.ffe.livingroom.videv_floor_lamp, rooms.ffe.livingroom.videv_floor_lamp,
67
+            *[getattr(rooms.ffe.livingroom, "floor_lamp_zigbee_%d" % i) for i in range(1, 7)]
68
+        )
69
+        # add test collection
70
+        self.all = test_collection(self)
71
+
72
+    def __init__tcl__(self):
73
+        system_info = {}
74
+        system_info[jsonlog.SYSI_ARCHITECTURE] = platform.architecture()[0]
75
+        system_info[jsonlog.SYSI_MACHINE] = platform.machine()
76
+        system_info[jsonlog.SYSI_HOSTNAME] = platform.node()
77
+        system_info[jsonlog.SYSI_DISTRIBUTION] = distro.name() + " " + distro.version() + " (" + distro.codename() + ")"
78
+        system_info[jsonlog.SYSI_SYSTEM] = platform.system()
79
+        system_info[jsonlog.SYSI_KERNEL] = platform.release() + ' (%s)' % platform.version()
80
+        system_info[jsonlog.SYSI_USERNAME] = getpass.getuser()
81
+        system_info[jsonlog.SYSI_PATH] = os.path.abspath(os.path.basename(__file__))
82
+
83
+        self.tcl = report.testSession(['__unittest__', 'unittest', ROOT_LOGGER_NAME])
84
+        self.tcl[jsonlog.MAIN_KEY_SYSTEM_INFO] = system_info
85
+
86
+    def __eval_tcl__(self):
87
+        path = os.path.abspath(os.path.join(os.path.basename(__file__), '..'))
88
+
89
+        with open(os.path.join(path, "testresults", "testrun.json"), "w") as fh:
90
+            fh.write(json.dumps(self.tcl, indent=4))
91
+
92
+        template_path = os.path.join(path, 'templates')
93
+        template_filename = 'unittest.tex'
94
+        jenv = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path))
95
+        template = jenv.get_template(template_filename)
96
+        with open(os.path.join(path, "testresults", "testrun.tex"), "w") as fh:
97
+            fh.write(template.render(data=self.tcl, details=False))
98
+        with open(os.path.join(path, "testresults", "testrun_full.tex"), "w") as fh:
99
+            fh.write(template.render(data=self.tcl, details=True))
100
+
101
+    def __del__(self):
102
+        try:
103
+            self.__eval_tcl__()
104
+        except:
105
+            pass
106
+
107
+    def getmembers(self, prefix=''):
108
+        rv = []
109
+        for name, obj in inspect.getmembers(self):
110
+            if prefix:
111
+                full_name = prefix + '.' + name
112
+            else:
113
+                full_name = name
114
+            if not name.startswith('_'):
115
+                try:
116
+                    if obj.__class__.__bases__[0].__name__ == "testcase" or obj.__class__.__name__ == "test_collection":
117
+                        rv.append(full_name)
118
+                    else:
119
+                        rv.extend(obj.getmembers(full_name))
120
+                except AttributeError:
121
+                    pass
122
+        return rv
123
+
124
+    def getobjbyname(self, name):
125
+        if name.startswith("test."):
126
+            name = name[5:]
127
+        obj = self
128
+        for subname in name.split('.'):
129
+            obj = getattr(obj, subname)
130
+        return obj
131
+
132
+    def command(self, full_command):
133
+        try:
134
+            parameter = " " + full_command.split(' ')[1]
135
+        except IndexError:
136
+            parameter = ""
137
+        command = full_command.split(' ')[0].split('.')[-1] + parameter
138
+        device_name = '.'.join(full_command.split(' ')[0].split('.')[:-1])
139
+        self.getobjbyname(device_name).command(command)

+ 129
- 0
tests/heating.py Zobrazit soubor

@@ -0,0 +1,129 @@
1
+import config
2
+import report
3
+from tests import testcase, DT_TOGGLE
4
+import time
5
+from unittest.test import equivalency_chk, greater_chk
6
+
7
+
8
+class testcase_heating(testcase):
9
+    def __init__(self, tcl, videv, valve):
10
+        self.tcl = tcl
11
+        self.__videv__ = videv
12
+        self.__valve__ = valve
13
+        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
+
16
+    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)
19
+
20
+    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)
22
+        setp = self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT)
23
+        delta = 5 if setp < mtemp else -5
24
+
25
+        for i in range(0, 2):
26
+            self.__valve__.set(self.__valve__.KEY_TEMPERATURE_SETPOINT, setp + delta)
27
+            time.sleep(DT_TOGGLE)
28
+            tLogger.debug("Changing valve temperature setpoint to '%.1f'", setp + delta)
29
+            equivalency_chk(self.__videv__.get(self.__videv__.KEY_VALVE_TEMPERATURE_SETPOINT),
30
+                            setp + delta, tLogger, "Virtual device valve temperature")
31
+            equivalency_chk(self.__videv__.get(self.__videv__.KEY_USER_TEMPERATURE_SETPOINT),
32
+                            setp + delta, tLogger, "Virtual device user temperature")
33
+            #
34
+            self.__videv__.set(self.__videv__.KEY_USER_TEMPERATURE_SETPOINT, setp)
35
+            time.sleep(DT_TOGGLE)
36
+            tLogger.debug("Changing videv user temperature setpoint to '%.1f'", setp)
37
+            equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), setp, tLogger, "Valve device temperature setpoint")
38
+            equivalency_chk(self.__videv__.get(self.__videv__.KEY_VALVE_TEMPERATURE_SETPOINT), setp, tLogger, "Virtual device valve temperature")
39
+
40
+    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)
43
+
44
+    def __test_default_temperature__(self, tLogger, tcel):
45
+        dtemp = config.DEFAULT_TEMPERATURE.get(self.__valve__.topic)
46
+        mtemp = round(self.__valve__.TEMP_RANGE[0] + (self.__valve__.TEMP_RANGE[1] - self.__valve__.TEMP_RANGE[0]) / 2, 1)
47
+        ptemp = dtemp + (5 if dtemp < mtemp else -5)
48
+
49
+        self.__valve__.set(self.__valve__.KEY_TEMPERATURE_SETPOINT, ptemp)
50
+        time.sleep(DT_TOGGLE)
51
+        tLogger.debug("Setting preconditions (Valve setpoint to %.1f)", ptemp)
52
+
53
+        equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT) != dtemp,
54
+                        True, tLogger, "Valve temperature setpoint (is not default temperature)")
55
+        self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
56
+        time.sleep(DT_TOGGLE)
57
+        tLogger.debug("Triggering set to default temperature (%.1f)", dtemp)
58
+        equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), dtemp, tLogger, "Valve temperature setpoint")
59
+
60
+    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)
62
+
63
+    def __test_summer_mode__(self, tLogger, tcel):
64
+        self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
65
+        time.sleep(DT_TOGGLE)
66
+        tLogger.debug("Setting preconditions (Default setpoint)")
67
+
68
+        vtemp = self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT)
69
+
70
+        equivalency_chk(self.__videv__.get(self.__videv__.KEY_SUMMER_MODE), False, tLogger, "Summer mode")
71
+        self.__videv__.set(self.__videv__.KEY_SUMMER_MODE, True)
72
+        time.sleep(DT_TOGGLE)
73
+        tLogger.debug("Activating summer mode")
74
+        equivalency_chk(self.__videv__.get(self.__videv__.KEY_SUMMER_MODE), True, tLogger, "Summer mode")
75
+        equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), 5, tLogger, "Temperature setpoint")
76
+
77
+        self.__videv__.set(self.__videv__.KEY_SUMMER_MODE, False)
78
+        time.sleep(DT_TOGGLE)
79
+        tLogger.debug("Deactivating summer mode")
80
+        equivalency_chk(self.__videv__.get(self.__videv__.KEY_SUMMER_MODE), False, tLogger, "Summer mode")
81
+        equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp, tLogger, "Temperature setpoint")
82
+
83
+    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)
85
+
86
+    def __test_away_mode__(self, tLogger, tcel):
87
+        self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
88
+        time.sleep(DT_TOGGLE)
89
+        tLogger.debug("Setting preconditions (Default setpoint)")
90
+
91
+        vtemp = self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT)
92
+
93
+        equivalency_chk(self.__videv__.get(self.__videv__.KEY_AWAY_MODE), False, tLogger, "Away mode")
94
+        self.__videv__.set(self.__videv__.KEY_AWAY_MODE, True)
95
+        time.sleep(DT_TOGGLE)
96
+        tLogger.debug("Activating away mode")
97
+        equivalency_chk(self.__videv__.get(self.__videv__.KEY_AWAY_MODE), True, tLogger, "Away mode")
98
+        equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp - 5, tLogger, "Temperature setpoint")
99
+
100
+        self.__videv__.set(self.__videv__.KEY_AWAY_MODE, False)
101
+        time.sleep(DT_TOGGLE)
102
+        tLogger.debug("Deactivating away mode")
103
+        equivalency_chk(self.__videv__.get(self.__videv__.KEY_AWAY_MODE), False, tLogger, "Away mode")
104
+        equivalency_chk(self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT), vtemp, tLogger, "Temperature setpoint")
105
+
106
+    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)
108
+
109
+    def __test_boost_mode__(self, tLogger, tcel):
110
+        self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
111
+        time.sleep(DT_TOGGLE)
112
+        tLogger.debug("Setting preconditions (Default setpoint)")
113
+
114
+        vtemp = self.__valve__.get(self.__valve__.KEY_TEMPERATURE_SETPOINT)
115
+
116
+        equivalency_chk(self.__videv__.get(self.__videv__.KEY_BOOST_TIMER), 0, tLogger, "Boost timer")
117
+        self.__videv__.set(self.__videv__.KEY_START_BOOST, None)
118
+        time.sleep(DT_TOGGLE)
119
+        tLogger.debug("Activating boost mode")
120
+        greater_chk(self.__videv__.get(self.__videv__.KEY_BOOST_TIMER), 0, tLogger, "Boost timer")
121
+
122
+        self.__videv__.set(self.__videv__.KEY_SET_DEFAULT_TEMPERATURE, None)
123
+        time.sleep(DT_TOGGLE)
124
+        tLogger.debug("Setting postconditions (Default setpoint)")
125
+        equivalency_chk(self.__videv__.get(self.__videv__.KEY_BOOST_TIMER), 0, tLogger, "Boost timer")
126
+
127
+        if tcel == report.TCEL_FULL:
128
+            # test boost timer
129
+            pass

+ 92
- 0
tests/light.py Zobrazit soubor

@@ -0,0 +1,92 @@
1
+import report
2
+from tests import testcase, DT_TOGGLE
3
+import time
4
+from unittest.test import equivalency_chk
5
+
6
+
7
+class testcase_light(testcase):
8
+    def __init__(self, tcl, videv, sw_device, li_device):
9
+        self.tcl = tcl
10
+        self.videv = videv
11
+        self.sw_device = sw_device
12
+        self.li_device = li_device
13
+        self.__test_list__ = []
14
+        if self.videv.enable_state:
15
+            self.__test_list__.append('test_power_on_off')
16
+        if self.videv.enable_brightness:
17
+            self.__test_list__.append('test_brightness')
18
+        if self.videv.enable_color_temp:
19
+            self.__test_list__.append('test_color_temp')
20
+
21
+    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
+
24
+    def __test_power_on_off__(self, tLogger, tcel):
25
+        sw_state = self.sw_device.get(self.sw_device.KEY_OUTPUT_0)
26
+
27
+        for i in range(0, 2):
28
+            equivalency_chk(self.videv.get(self.videv.KEY_OUTPUT_0), sw_state, tLogger, "Virtual device state")
29
+            self.sw_device.set(self.sw_device.KEY_OUTPUT_0, not sw_state)
30
+            time.sleep(DT_TOGGLE)
31
+            tLogger.debug("Changing switching device state to '%s'", not sw_state)
32
+            equivalency_chk(self.videv.get(self.videv.KEY_OUTPUT_0), not sw_state, tLogger, "Virtual device state")
33
+            #
34
+            equivalency_chk(self.sw_device.get(self.sw_device.KEY_OUTPUT_0), not sw_state, tLogger, "Switching device state")
35
+            self.videv.set(self.videv.KEY_OUTPUT_0, sw_state)
36
+            time.sleep(DT_TOGGLE)
37
+            tLogger.debug("Changing virtual device state to '%s'", sw_state)
38
+            equivalency_chk(self.sw_device.get(self.sw_device.KEY_OUTPUT_0), sw_state, tLogger, "Switching device state")
39
+
40
+    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)
42
+
43
+    def __test_brightness__(self, tLogger, tcel):
44
+        br_state = self.li_device.get(self.li_device.KEY_BRIGHTNESS)
45
+        delta = -15 if br_state > 50 else 15
46
+        self.sw_device.set(self.sw_device.KEY_OUTPUT_0, True)
47
+        time.sleep(DT_TOGGLE)
48
+        tLogger.debug("Setting preconditions (Power on)")
49
+
50
+        for i in range(0, 2):
51
+            equivalency_chk(self.videv.get(self.videv.KEY_BRIGHTNESS), br_state, tLogger, "Virtual device brightness")
52
+            self.li_device.set(self.li_device.KEY_BRIGHTNESS, br_state + delta)
53
+            time.sleep(DT_TOGGLE)
54
+            tLogger.debug("Changing light device brightness to '%d'", br_state + delta)
55
+            equivalency_chk(self.videv.get(self.videv.KEY_BRIGHTNESS), br_state + delta, tLogger, "Virtual device brightness")
56
+            #
57
+            equivalency_chk(self.li_device.get(self.li_device.KEY_BRIGHTNESS), br_state + delta, tLogger, "Light device brightness")
58
+            self.videv.set(self.videv.KEY_BRIGHTNESS, br_state)
59
+            time.sleep(DT_TOGGLE)
60
+            tLogger.debug("Changing virtual device brightness to '%d'", br_state)
61
+            equivalency_chk(self.li_device.get(self.li_device.KEY_BRIGHTNESS), br_state, tLogger, "Light device brightness")
62
+        #
63
+        self.sw_device.set(self.sw_device.KEY_OUTPUT_0, False)
64
+        time.sleep(DT_TOGGLE)
65
+        tLogger.debug("Resetting precondition (Power off)")
66
+
67
+    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)
69
+
70
+    def __test_color_temp__(self, tLogger, tcel):
71
+        ct_state = self.li_device.get(self.li_device.KEY_COLOR_TEMP)
72
+        delta = -3 if ct_state > 5 else 3
73
+        self.sw_device.set(self.sw_device.KEY_OUTPUT_0, True)
74
+        time.sleep(DT_TOGGLE)
75
+        tLogger.debug("Setting preconditions (Power on)")
76
+
77
+        for i in range(0, 2):
78
+            equivalency_chk(self.videv.get(self.videv.KEY_COLOR_TEMP), ct_state, tLogger, "Virtual device color temperature")
79
+            self.li_device.set(self.li_device.KEY_COLOR_TEMP, ct_state + delta)
80
+            time.sleep(DT_TOGGLE)
81
+            tLogger.debug("Changing light device color temperature to '%d'", ct_state)
82
+            equivalency_chk(self.videv.get(self.videv.KEY_COLOR_TEMP), ct_state + delta, tLogger, "Virtual device color temperature")
83
+            #
84
+            equivalency_chk(self.li_device.get(self.li_device.KEY_COLOR_TEMP), ct_state + delta, tLogger, "Light device brightness")
85
+            self.videv.set(self.videv.KEY_COLOR_TEMP, ct_state)
86
+            time.sleep(DT_TOGGLE)
87
+            tLogger.debug("Changing virtual device color temperature to '%d'", ct_state)
88
+            equivalency_chk(self.li_device.get(self.li_device.KEY_COLOR_TEMP), ct_state, tLogger, "Light device brightness")
89
+        #
90
+        self.sw_device.set(self.sw_device.KEY_OUTPUT_0, False)
91
+        time.sleep(DT_TOGGLE)
92
+        tLogger.debug("Resetting precondition (Power off)")

+ 90
- 0
tests/synchronisation.py Zobrazit soubor

@@ -0,0 +1,90 @@
1
+import report
2
+from tests import testcase, DT_TOGGLE
3
+import time
4
+from unittest.test import equivalency_chk
5
+
6
+
7
+class testcase_synchronisation(testcase):
8
+    def __init__(self, tcl, sw_master, br_master, ct_master, *follower):
9
+        super().__init__()
10
+        self.tcl = tcl
11
+        self.sw_master = sw_master
12
+        self.br_master = br_master
13
+        self.ct_master = ct_master
14
+        self.follower = follower
15
+        #
16
+        self.__test_list__ = []
17
+        if sw_master is not None:
18
+            self.__test_list__.append('test_power_on_off_sync')
19
+        if br_master is not None:
20
+            self.__test_list__.append('test_brightness_sync')
21
+        if ct_master is not None:
22
+            self.__test_list__.append('test_color_temp_sync')
23
+
24
+    def test_power_on_off_sync(self, tcel=report.TCEL_FULL):
25
+        self.tcl.testCase("Power On/ Off synchronisation test: %s" % self.sw_master.topic, tcel, self.__test_power_on_off_sync__, tcel)
26
+
27
+    def __test_power_on_off_sync__(self, tLogger, tcel):
28
+        f_state = self.follower[0].get(self.follower[0].KEY_OUTPUT_0)
29
+        self.sw_master.set(self.sw_master.KEY_OUTPUT_0, f_state)
30
+        time.sleep(DT_TOGGLE)
31
+        tLogger.debug("Setting preconditions for master device '%s'", f_state)
32
+
33
+        for i in range(0, 2):
34
+            f_state = not f_state
35
+            self.sw_master.set(self.sw_master.KEY_OUTPUT_0, f_state)
36
+            time.sleep(DT_TOGGLE)
37
+            tLogger.debug("Changing master device state to '%s'", f_state)
38
+
39
+            for fo in self.follower:
40
+                equivalency_chk(fo.get(fo.KEY_OUTPUT_0), f_state, tLogger, "Follower device (%s) state" % fo.topic)
41
+
42
+    def test_brightness_sync(self, tcel=report.TCEL_FULL):
43
+        self.tcl.testCase("Brightness synchronisation test: %s" % self.br_master.topic, tcel, self.__test_brightness_sync__, tcel)
44
+
45
+    def __test_brightness_sync__(self, tLogger, tcel):
46
+        sw_state = self.sw_master.get(self.sw_master.KEY_OUTPUT_0)
47
+        self.sw_master.set(self.sw_master.KEY_OUTPUT_0, True)
48
+        time.sleep(DT_TOGGLE)
49
+        tLogger.debug("Setting preconditions for master device '%s' (Power on)", True)
50
+
51
+        target = self.follower[0].get(self.follower[0].KEY_BRIGHTNESS)
52
+        delta = 15 if target < 50 else -15
53
+        for i in range(0, 2):
54
+            target = target + delta
55
+            self.br_master.set(self.br_master.KEY_BRIGHTNESS, target)
56
+            time.sleep(DT_TOGGLE)
57
+            tLogger.debug("Changing master device brightness to '%d'", target)
58
+            for fo in self.follower:
59
+                equivalency_chk(fo.get(fo.KEY_BRIGHTNESS), target, tLogger, "Follower device (%s) brightness" % fo.topic)
60
+            delta = -delta
61
+
62
+        # reset changes of precondition
63
+        self.sw_master.set(self.sw_master.KEY_OUTPUT_0, sw_state)
64
+        time.sleep(DT_TOGGLE)
65
+        tLogger.debug("Resetting preconditions for master device '%s' (Power off)", sw_state)
66
+
67
+    def test_color_temp_sync(self, tcel=report.TCEL_FULL):
68
+        self.tcl.testCase("Color temperature synchronisation test: %s" % self.ct_master.topic, tcel, self.__test_color_temp_sync__, tcel)
69
+
70
+    def __test_color_temp_sync__(self, tLogger, tcel):
71
+        sw_state = self.sw_master.get(self.sw_master.KEY_OUTPUT_0)
72
+        self.sw_master.set(self.sw_master.KEY_OUTPUT_0, True)
73
+        time.sleep(DT_TOGGLE)
74
+        tLogger.debug("Setting preconditions for master device '%s' (Power on)", True)
75
+
76
+        target = self.follower[0].get(self.follower[0].KEY_COLOR_TEMP)
77
+        delta = 3 if target < 5 else -3
78
+        for i in range(0, 2):
79
+            target = target + delta
80
+            self.ct_master.set(self.br_master.KEY_COLOR_TEMP, target)
81
+            time.sleep(DT_TOGGLE)
82
+            tLogger.debug("Changing master device color temperature to '%d'", target)
83
+            for fo in self.follower:
84
+                equivalency_chk(fo.get(fo.KEY_COLOR_TEMP), target, tLogger, "Follower device (%s) color temperature" % fo.topic)
85
+            delta = -delta
86
+
87
+        # reset changes of precondition
88
+        self.sw_master.set(self.sw_master.KEY_OUTPUT_0, sw_state)
89
+        time.sleep(DT_TOGGLE)
90
+        tLogger.debug("Resetting preconditions for master device '%s' (Power off)", sw_state)

+ 1
- 0
unittest

@@ -0,0 +1 @@
1
+Subproject commit a73c8f8c3523df17eeddad6297d1454c16fc4552

Načítá se…
Zrušit
Uložit