tests/tools/test_application.py
changeset 1808 b4764ebb352d
parent 1796 4f7a0c40a7c3
child 1809 3f0a552549d1
equal deleted inserted replaced
1807:5562f34f2fc2 1808:b4764ebb352d
       
     1 #!/usr/bin/env python
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 # This file is part of Beremiz, a Integrated Development Environment for
       
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
       
     6 #
       
     7 # Copyright (C) 2017: Andrey Skvortsov
       
     8 #
       
     9 # See COPYING file for copyrights details.
       
    10 #
       
    11 # This program is free software; you can redistribute it and/or
       
    12 # modify it under the terms of the GNU General Public License
       
    13 # as published by the Free Software Foundation; either version 2
       
    14 # of the License, or (at your option) any later version.
       
    15 #
       
    16 # This program is distributed in the hope that it will be useful,
       
    17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    19 # GNU General Public License for more details.
       
    20 #
       
    21 # You should have received a copy of the GNU General Public License
       
    22 # along with this program; if not, write to the Free Software
       
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       
    24 
     1 import os
    25 import os
     2 import sys
    26 import sys
     3 import unittest
    27 import unittest
     4 import wx
    28 import wx
     5 import time
    29 import time
     6 import traceback
    30 import traceback
     7 from xvfbwrapper import Xvfb
       
     8 
    31 
     9 vdisplay = None
    32 import conftest
    10 
    33 import Beremiz
    11 
       
    12 def setUpModule():
       
    13     vdisplay = Xvfb(width=1280, height=720)
       
    14     vdisplay.start()
       
    15 
       
    16 
       
    17 def tearDownModule():
       
    18     if vdisplay is not None:
       
    19         vdisplay.stop()
       
    20 
    34 
    21 
    35 
    22 class UserApplicationTest(unittest.TestCase):
    36 class UserApplicationTest(unittest.TestCase):
    23     def InstallExceptionHandler(self):
    37     def InstallExceptionHandler(self):
    24         def handle_exception(e_type, e_value, e_traceback):
    38         def handle_exception(e_type, e_value, e_traceback):
    32         self.app = None
    46         self.app = None
    33 
    47 
    34     def FinishApp(self):
    48     def FinishApp(self):
    35         wx.CallAfter(self.app.frame.Close)
    49         wx.CallAfter(self.app.frame.Close)
    36         self.app.MainLoop()
    50         self.app.MainLoop()
    37         # time.sleep(0.2)
       
    38         self.app = None
    51         self.app = None
    39 
    52 
    40     def tearDown(self):
    53     def tearDown(self):
    41         if self.app is not None and self.app.frame is not None:
    54         if self.app is not None and self.app.frame is not None:
    42             self.FinishApp()
    55             self.FinishApp()
    72         self.app.MainLoop()
    85         self.app.MainLoop()
    73         time.sleep(1)
    86         time.sleep(1)
    74         self.app = None
    87         self.app = None
    75 
    88 
    76     def OpenAllProjectElements(self):
    89     def OpenAllProjectElements(self):
    77         # open every object in the project tree
    90         """Open editor for every object in the project tree"""
    78         self.app.frame.ProjectTree.ExpandAll()
    91         self.app.frame.ProjectTree.ExpandAll()
    79         self.ProcessEvents()
    92         self.ProcessEvents()
    80         item = self.app.frame.ProjectTree.GetRootItem()
    93         item = self.app.frame.ProjectTree.GetRootItem()
    81         while item is not None:
    94         while item is not None:
    82             self.app.frame.ProjectTree.SelectItem(item, True)
    95             self.app.frame.ProjectTree.SelectItem(item, True)
   104             [self.app.frame.CTR._Run],
   117             [self.app.frame.CTR._Run],
   105             [self.app.frame.CTR._Stop],
   118             [self.app.frame.CTR._Stop],
   106             [self.app.frame.CTR._Disconnect],
   119             [self.app.frame.CTR._Disconnect],
   107         ]
   120         ]
   108 
   121 
   109         # user_actions.append([self.app.frame.OnCloseProjectMenu, None])
       
   110         self.RunUIActions(user_actions)
   122         self.RunUIActions(user_actions)
   111         self.FinishApp()
   123         self.FinishApp()
   112 
   124 
   113     def GetProjectPath(self, project):
   125     def GetProjectPath(self, project):
   114         return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", project))
   126         return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", project))
   115 
   127 
   116     # @unittest.skip("")
       
   117     def testStartUp(self):
   128     def testStartUp(self):
   118         """Checks whether the app starts and finishes correctly"""
   129         """Checks whether the app starts and finishes correctly"""
   119         self.StartApp()
   130         self.StartApp()
   120         self.FinishApp()
   131         self.FinishApp()
   121 
   132 
   137             print "Testing example " + name
   148             print "Testing example " + name
   138             self.CheckTestProject(project)
   149             self.CheckTestProject(project)
   139 
   150 
   140 
   151 
   141 if __name__ == '__main__':
   152 if __name__ == '__main__':
   142     if __package__ is None:
       
   143         sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
       
   144         global Beremiz
       
   145         import Beremiz
       
   146     unittest.main()
   153     unittest.main()