]> SALOME platform Git repositories - modules/kernel.git/blob - src/KERNEL_PY/kernel/unittester.py
Salome HOME
Add functions to know that SALOME module version is development one
[modules/kernel.git] / src / KERNEL_PY / kernel / unittester.py
1 # -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2010  EDF R&D
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 __author__="gboulant"
20 __date__ ="$1 avr. 2010 09:45:21$"
21
22 import sys
23
24 def run(modulePath, functionName):
25     """
26     This function should be used for very basic unit tests and only for a
27     rapid development. A better way should be the pyunit framework.
28     The function functionName is supposed here to return a boolean value
29     indicating if the test is OK (True) or NOT OK (False)
30     """
31     moduleName = modulePath.replace('/','.') 
32     __import__ (moduleName)
33     module=sys.modules[moduleName]
34     func = getattr(module,functionName)
35     tabsize = 70-len(moduleName)-len(functionName)
36     print "[TEST] %s.%s %s test in progress" % (moduleName, functionName,"."*tabsize) 
37     ok = func()
38     if ( ok ):
39         print "[TEST] %s.%s %s OK" % (moduleName, functionName,"."*tabsize)
40     else:
41         print "[TEST] %s.%s %s NOT OK" % (moduleName, functionName,"."*tabsize)
42
43 def tryfunction(function,*argv):
44     """
45     This function is for debug only. It executes the specified function with the
46     specified arguments in a try/except bloc so that to display the exception in
47     the case where an exception is raised (usefull to debug server side of a CORBA
48     process).
49     """
50     print "[TEST] trying the function %s" % function
51     try:
52         return function(*argv)
53     except Exception, e:
54         print e
55         raise e
56
57
58 #
59 # ==============================================================================
60 # Simple use cases
61 # ==============================================================================
62 #
63 def TEST_myTestIsOk():
64     return True
65
66 def TEST_myTestIsNotOk():
67     return False
68
69 if __name__ == "__main__":
70     run("salome/kernel/unittester","TEST_myTestIsOk")
71     run("salome/kernel/unittester","TEST_myTestIsNotOk")