Back to index

salome-kernel  6.5.0
unittester.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2010-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # This library is free software; you can redistribute it and/or
00005 # modify it under the terms of the GNU Lesser General Public
00006 # License as published by the Free Software Foundation; either
00007 # version 2.1 of the License.
00008 #
00009 # This library is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 # Lesser General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU Lesser General Public
00015 # License along with this library; if not, write to the Free Software
00016 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 #
00018 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 #
00020 __author__="gboulant"
00021 __date__ ="$1 avr. 2010 09:45:21$"
00022 
00023 import sys
00024 
00025 def run(modulePath, functionName):
00026     """
00027     This function should be used for very basic unit tests and only for a
00028     rapid development. A better way should be the pyunit framework.
00029     The function functionName is supposed here to return a boolean value
00030     indicating if the test is OK (True) or NOT OK (False)
00031     """
00032     moduleName = modulePath.replace('/','.') 
00033     __import__ (moduleName)
00034     module=sys.modules[moduleName]
00035     func = getattr(module,functionName)
00036     tabsize = 70-len(moduleName)-len(functionName)
00037     print "[TEST] %s.%s %s test in progress" % (moduleName, functionName,"."*tabsize) 
00038     ok = func()
00039     if ( ok ):
00040         print "[TEST] %s.%s %s OK" % (moduleName, functionName,"."*tabsize)
00041     else:
00042         print "[TEST] %s.%s %s NOT OK" % (moduleName, functionName,"."*tabsize)
00043 
00044 def tryfunction(function,*argv):
00045     """
00046     This function is for debug only. It executes the specified function with the
00047     specified arguments in a try/except bloc so that to display the exception in
00048     the case where an exception is raised (usefull to debug server side of a CORBA
00049     process).
00050     """
00051     print "[TEST] trying the function %s" % function
00052     try:
00053         return function(*argv)
00054     except Exception, e:
00055         print e
00056         raise e
00057 
00058 
00059 #
00060 # ==============================================================================
00061 # Simple use cases
00062 # ==============================================================================
00063 #
00064 def TEST_myTestIsOk():
00065     return True
00066 
00067 def TEST_myTestIsNotOk():
00068     return False
00069 
00070 if __name__ == "__main__":
00071     run("salome/kernel/unittester","TEST_myTestIsOk")
00072     run("salome/kernel/unittester","TEST_myTestIsNotOk")