author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Fri, 16 Feb 2018 02:29:10 +0100 | |
changeset 1937 | 986dbad48ab7 |
parent 1881 | 091005ec69c4 |
child 1961 | b4a1ba9dbaf3 |
permissions | -rw-r--r-- |
1808
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
1 |
#!/usr/bin/env python |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
3 |
|
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
6 |
# |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
7 |
# Copyright (C) 2017: Andrey Skvortsov |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
8 |
# |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
10 |
# |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
15 |
# |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
19 |
# GNU General Public License for more details. |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
20 |
# |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
24 |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1822
diff
changeset
|
25 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
26 |
from __future__ import absolute_import |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1822
diff
changeset
|
27 |
from __future__ import print_function |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
28 |
import os |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
29 |
import sys |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
30 |
import unittest |
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1826
diff
changeset
|
31 |
import time |
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1826
diff
changeset
|
32 |
|
1809
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
33 |
import pytest |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
34 |
import wx |
1809
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
35 |
import ddt |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
36 |
|
1808
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
37 |
import conftest |
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
38 |
import Beremiz |
1819
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
39 |
import PLCOpenEditor |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
40 |
|
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
41 |
|
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
42 |
class UserApplicationTest(unittest.TestCase): |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
43 |
def InstallExceptionHandler(self): |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
44 |
def handle_exception(e_type, e_value, e_traceback): |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
45 |
# traceback.print_exception(e_type, e_value, e_traceback) |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
46 |
self.exc_info = [e_type, e_value, e_traceback] |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
47 |
self.exc_info = None |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
48 |
self.old_excepthook = sys.excepthook |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
49 |
sys.excepthook = handle_exception |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
50 |
|
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
51 |
def StartApp(self): |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
52 |
self.app = None |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
53 |
|
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
54 |
def FinishApp(self): |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
55 |
wx.CallAfter(self.app.frame.Close) |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
56 |
self.app.MainLoop() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
57 |
self.app = None |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
58 |
|
1809
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
59 |
def setUp(self): |
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
60 |
self.app = None |
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
61 |
|
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
62 |
def tearDown(self): |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
63 |
if self.app is not None and self.app.frame is not None: |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
64 |
self.FinishApp() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
65 |
|
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
66 |
def RunUIActions(self, actions): |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
67 |
for act in actions: |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
68 |
wx.CallAfter(*act) |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
69 |
self.ProcessEvents() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
70 |
|
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
71 |
def CheckForErrors(self): |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
72 |
if self.exc_info is not None: |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
73 |
# reraise catched previously exception |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
74 |
raise self.exc_info[0], self.exc_info[1], self.exc_info[2] |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
75 |
|
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
76 |
def ProcessEvents(self): |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
77 |
for dummy in range(0, 30): |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
78 |
self.CheckForErrors() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
79 |
wx.Yield() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
80 |
time.sleep(0.01) |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
81 |
|
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
82 |
|
1809
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
83 |
@ddt.ddt |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
84 |
class BeremizApplicationTest(UserApplicationTest): |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
85 |
"""Test Beremiz as whole application""" |
1816
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
86 |
|
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
87 |
def StartApp(self): |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
88 |
self.app = Beremiz.BeremizIDELauncher() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
89 |
# disable default exception handler in Beremiz |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
90 |
self.app.InstallExceptionHandler = lambda: None |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
91 |
self.InstallExceptionHandler() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
92 |
self.app.PreStart() |
1818
925ea35edc2c
run application tests in full screen mode
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1817
diff
changeset
|
93 |
self.app.frame.Show() |
925ea35edc2c
run application tests in full screen mode
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1817
diff
changeset
|
94 |
self.ProcessEvents() |
925ea35edc2c
run application tests in full screen mode
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1817
diff
changeset
|
95 |
self.app.frame.ShowFullScreen(True) |
925ea35edc2c
run application tests in full screen mode
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1817
diff
changeset
|
96 |
self.ProcessEvents() |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
97 |
|
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
98 |
def FinishApp(self): |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
99 |
wx.CallAfter(self.app.frame.Close) |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
100 |
self.app.MainLoop() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
101 |
time.sleep(1) |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
102 |
self.app = None |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
103 |
|
1816
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
104 |
def GetSkippedProjectTreeItems(self): |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
105 |
""" |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
106 |
Returns the list of skipped items in the project tree. |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
107 |
|
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
108 |
Beremiz test don't need to skip any elemnts in the project tree. |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
109 |
""" |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
110 |
return [] |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
111 |
|
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
112 |
def OpenAllProjectElements(self): |
1808
b4764ebb352d
move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1796
diff
changeset
|
113 |
"""Open editor for every object in the project tree""" |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
114 |
self.app.frame.ProjectTree.ExpandAll() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
115 |
self.ProcessEvents() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
116 |
item = self.app.frame.ProjectTree.GetRootItem() |
1819
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
117 |
skip = self.GetSkippedProjectTreeItems() |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
118 |
tree_id = self.app.frame.ProjectTree.GetId() |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
119 |
while item is not None: |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
120 |
self.app.frame.ProjectTree.SelectItem(item, True) |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
121 |
self.ProcessEvents() |
1819
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
122 |
if item not in skip: |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
123 |
event = wx.lib.agw.customtreectrl.TreeEvent( |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
124 |
wx.lib.agw.customtreectrl.wxEVT_TREE_ITEM_ACTIVATED, |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
125 |
tree_id, item) |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
126 |
self.app.frame.OnProjectTreeItemActivated(event) |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
127 |
self.ProcessEvents() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
128 |
item = self.app.frame.ProjectTree.GetNextVisible(item) |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
129 |
|
1816
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
130 |
def CheckTestProject(self, project): |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
131 |
sys.argv = ["", project] |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
132 |
self.StartApp() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
133 |
self.OpenAllProjectElements() |
1816
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
134 |
user_actions = self.GetUserActions() |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
135 |
self.RunUIActions(user_actions) |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
136 |
self.FinishApp() |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
137 |
|
1816
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
138 |
def GetProjectPath(self, project): |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
139 |
return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", project)) |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
140 |
|
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
141 |
def GetUserActions(self): |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
142 |
""" |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
143 |
Returns list of user actions that will be executed |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
144 |
on every test project by testCheckProject test. |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
145 |
""" |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
146 |
user_actions = [ |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
147 |
[self.app.frame.SwitchFullScrMode, None], |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
148 |
[self.app.frame.SwitchFullScrMode, None], |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
149 |
[self.app.frame.CTR._Clean], |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
150 |
[self.app.frame.CTR._Build], |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
151 |
[self.app.frame.CTR._Connect], |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
152 |
[self.app.frame.CTR._Transfer], |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
153 |
[self.app.frame.CTR._Run], |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
154 |
[self.app.frame.CTR._Stop], |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
155 |
[self.app.frame.CTR._Disconnect], |
1822
1d7bf584eb7f
clean build example project after running test
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1819
diff
changeset
|
156 |
[self.app.frame.CTR._Clean], |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
157 |
] |
1816
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
158 |
return user_actions |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
159 |
|
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
160 |
def testStartUp(self): |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
161 |
"""Checks whether the app starts and finishes correctly""" |
1817
ff0c18be4a8b
clean sys.argv, because if test is running from pytest
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1816
diff
changeset
|
162 |
sys.argv = [""] |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
163 |
self.StartApp() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
164 |
self.FinishApp() |
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
165 |
|
1809
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
166 |
@ddt.data( |
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
167 |
"first_steps", |
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
168 |
"logging", |
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
169 |
"svgui", |
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
170 |
"traffic_lights", |
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
171 |
"wxGlade", |
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
172 |
"python", |
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
173 |
"wiimote", |
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
174 |
"wxHMI", |
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
175 |
) |
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
176 |
@pytest.mark.timeout(30) |
3f0a552549d1
run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1808
diff
changeset
|
177 |
def testCheckProject(self, name): |
1816
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
178 |
""" |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
179 |
Checks that test PLC project can be open, |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
180 |
compiled and run on SoftPLC. |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
181 |
""" |
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
182 |
project = self.GetProjectPath(name) |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1822
diff
changeset
|
183 |
print("Testing example " + name) |
1816
724722c03db4
rework Beremiz application "testCheckProject" test to allow easier reuse later
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1809
diff
changeset
|
184 |
self.CheckTestProject(project) |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
185 |
|
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
186 |
|
1819
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
187 |
class PLCOpenEditorApplicationTest(BeremizApplicationTest): |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
188 |
"""Test PLCOpenEditor as whole application""" |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
189 |
|
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
190 |
def StartApp(self): |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
191 |
self.app = PLCOpenEditor.PLCOpenEditorApp() |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
192 |
# disable default exception handler in application |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
193 |
self.app.InstallExceptionHandler = lambda: None |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
194 |
self.InstallExceptionHandler() |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
195 |
self.app.Show() |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
196 |
self.ProcessEvents() |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
197 |
self.app.frame.ShowFullScreen(True) |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
198 |
self.ProcessEvents() |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
199 |
|
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
200 |
def FinishApp(self): |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
201 |
wx.CallAfter(self.app.frame.Close) |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
202 |
self.app.MainLoop() |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
203 |
time.sleep(1) |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
204 |
self.app = None |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
205 |
|
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
206 |
def GetSkippedProjectTreeItems(self): |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
207 |
""" |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
208 |
Returns the list of skipped items in the project tree. |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
209 |
|
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
210 |
Root item opens dialog window for project settings. |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
211 |
To avoid code that handles closing dialog windows just skip this item. |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
212 |
""" |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
213 |
return [self.app.frame.ProjectTree.GetRootItem()] |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
214 |
|
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
215 |
def GetUserActions(self): |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
216 |
return [] |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
217 |
|
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
218 |
def GetProjectPath(self, project): |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
219 |
"""Open PLC program in every Beremiz test project""" |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
220 |
project_dir = BeremizApplicationTest.GetProjectPath(self, project) |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
221 |
return os.path.join(project_dir, "plc.xml") |
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
222 |
|
27976d1606a4
add PLCOpenEditor tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1818
diff
changeset
|
223 |
|
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
224 |
if __name__ == '__main__': |
1850
614396cbffbf
fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
225 |
conftest.init_environment() |
1796
4f7a0c40a7c3
add couple Beremiz application tests
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
226 |
unittest.main() |