tests/tools/test_application.py
changeset 1816 724722c03db4
parent 1809 3f0a552549d1
child 1817 ff0c18be4a8b
equal deleted inserted replaced
1815:f0600fe03a89 1816:724722c03db4
    77 
    77 
    78 
    78 
    79 @ddt.ddt
    79 @ddt.ddt
    80 class BeremizApplicationTest(UserApplicationTest):
    80 class BeremizApplicationTest(UserApplicationTest):
    81     """Test Beremiz as whole application"""
    81     """Test Beremiz as whole application"""
       
    82 
    82     def StartApp(self):
    83     def StartApp(self):
    83         self.app = Beremiz.BeremizIDELauncher()
    84         self.app = Beremiz.BeremizIDELauncher()
    84         # disable default exception handler in Beremiz
    85         # disable default exception handler in Beremiz
    85         self.app.InstallExceptionHandler = lambda: None
    86         self.app.InstallExceptionHandler = lambda: None
    86         self.InstallExceptionHandler()
    87         self.InstallExceptionHandler()
    89     def FinishApp(self):
    90     def FinishApp(self):
    90         wx.CallAfter(self.app.frame.Close)
    91         wx.CallAfter(self.app.frame.Close)
    91         self.app.MainLoop()
    92         self.app.MainLoop()
    92         time.sleep(1)
    93         time.sleep(1)
    93         self.app = None
    94         self.app = None
       
    95 
       
    96     def GetSkippedProjectTreeItems(self):
       
    97         """
       
    98         Returns the list of skipped items in the project tree.
       
    99 
       
   100         Beremiz test don't need to skip any elemnts in the project tree.
       
   101         """
       
   102         return []
    94 
   103 
    95     def OpenAllProjectElements(self):
   104     def OpenAllProjectElements(self):
    96         """Open editor for every object in the project tree"""
   105         """Open editor for every object in the project tree"""
    97         self.app.frame.ProjectTree.ExpandAll()
   106         self.app.frame.ProjectTree.ExpandAll()
    98         self.ProcessEvents()
   107         self.ProcessEvents()
   106                 id, item)
   115                 id, item)
   107             self.app.frame.OnProjectTreeItemActivated(event)
   116             self.app.frame.OnProjectTreeItemActivated(event)
   108             self.ProcessEvents()
   117             self.ProcessEvents()
   109             item = self.app.frame.ProjectTree.GetNextVisible(item)
   118             item = self.app.frame.ProjectTree.GetNextVisible(item)
   110 
   119 
   111     def CheckTestProject(self, name):
   120     def CheckTestProject(self, project):
   112         project = self.GetProjectPath(name)
       
   113         print "Testing example " + name
       
   114         sys.argv = ["", project]
   121         sys.argv = ["", project]
   115         self.StartApp()
   122         self.StartApp()
   116         self.OpenAllProjectElements()
   123         self.OpenAllProjectElements()
       
   124         user_actions = self.GetUserActions()
       
   125         self.RunUIActions(user_actions)
       
   126         self.FinishApp()
   117 
   127 
       
   128     def GetProjectPath(self, project):
       
   129         return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", project))
       
   130 
       
   131     def GetUserActions(self):
       
   132         """
       
   133         Returns list of user actions that will be executed
       
   134         on every test project by testCheckProject test.
       
   135         """
   118         user_actions = [
   136         user_actions = [
   119             [self.app.frame.SwitchFullScrMode, None],
   137             [self.app.frame.SwitchFullScrMode, None],
   120             [self.app.frame.SwitchFullScrMode, None],
   138             [self.app.frame.SwitchFullScrMode, None],
   121             [self.app.frame.CTR._Clean],
   139             [self.app.frame.CTR._Clean],
   122             [self.app.frame.CTR._Build],
   140             [self.app.frame.CTR._Build],
   124             [self.app.frame.CTR._Transfer],
   142             [self.app.frame.CTR._Transfer],
   125             [self.app.frame.CTR._Run],
   143             [self.app.frame.CTR._Run],
   126             [self.app.frame.CTR._Stop],
   144             [self.app.frame.CTR._Stop],
   127             [self.app.frame.CTR._Disconnect],
   145             [self.app.frame.CTR._Disconnect],
   128         ]
   146         ]
   129 
   147         return user_actions
   130         self.RunUIActions(user_actions)
       
   131         self.FinishApp()
       
   132 
       
   133     def GetProjectPath(self, project):
       
   134         return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", project))
       
   135 
   148 
   136     def testStartUp(self):
   149     def testStartUp(self):
   137         """Checks whether the app starts and finishes correctly"""
   150         """Checks whether the app starts and finishes correctly"""
   138         self.StartApp()
   151         self.StartApp()
   139         self.FinishApp()
   152         self.FinishApp()
   148         "wiimote",
   161         "wiimote",
   149         "wxHMI",
   162         "wxHMI",
   150     )
   163     )
   151     @pytest.mark.timeout(30)
   164     @pytest.mark.timeout(30)
   152     def testCheckProject(self, name):
   165     def testCheckProject(self, name):
   153         self.CheckTestProject(name)
   166         """
       
   167         Checks that test PLC project can be open,
       
   168         compiled and run on SoftPLC.
       
   169         """
       
   170         project = self.GetProjectPath(name)
       
   171         print "Testing example " + name
       
   172         self.CheckTestProject(project)
   154 
   173 
   155 
   174 
   156 if __name__ == '__main__':
   175 if __name__ == '__main__':
   157     unittest.main()
   176     unittest.main()