Module EDTestCaseParallelExecute
[hide private]
[frames] | no frames]

Source Code for Module EDTestCaseParallelExecute

 1  # coding: utf8 
 2  # 
 3  #    Project: The EDNA Kernel 
 4  #             http://www.edna-site.org 
 5  # 
 6  #    File: "$Id$" 
 7  # 
 8  #    Copyright (C) 2008-2009 European Synchrotron Radiation Facility 
 9  #                            Grenoble, France 
10  # 
11  #    Principal authors: Jérôme Kieffer (Jerome.Kieffer@esrf.eu) 
12  #                       Olof Svensson (svensson@esrf.fr)  
13  # 
14  #    This program is free software: you can redistribute it and/or modify 
15  #    it under the terms of the GNU Lesser General Public License as published 
16  #    by the Free Software Foundation, either version 3 of the License, or 
17  #    (at your option) any later version. 
18  # 
19  #    This program is distributed in the hope that it will be useful, 
20  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
21  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
22  #    GNU Lesser General Public License for more details. 
23  # 
24  #    You should have received a copy of the GNU General Public License 
25  #    and the GNU Lesser General Public License  along with this program.   
26  #    If not, see <http://www.gnu.org/licenses/>. 
27  # 
28   
29  __authors__ = ["Jérôme Kieffer", "Olof Svensson"] 
30  __contact__ = "Jerome.Kieffer@esrf.eu" 
31  __license__ = "LGPLv3+" 
32  __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" 
33   
34  """This is the parallel Execute testing program """ 
35   
36  import os, tempfile, types 
37   
38  from EDVerbose                           import EDVerbose 
39  from EDTestCase                          import EDTestCase 
40  from EDAssert                            import EDAssert 
41  from EDParallelExecute                   import EDParallelExecute 
42  from EDUtilsParallel                     import EDUtilsParallel 
43   
44 -def fakeXML(strInput):
45 """Just a fake function that returns an empty XML string""" 46 return "<xml></xml>"
47
48 -class EDTestCaseParallelExecute(EDTestCase):
49 """ 50 Unit & execution test for the EDParallelExecute class 51 """ 52
53 - def __init__(self, _strTestName=None):
54 EDTestCase.__init__(self, "EDTestCaseParallelExecute") 55 self.__edpluginPE = EDParallelExecute("EDPluginTestPluginFactory", fakeXML)
56 57
58 - def unitTestMoveToTempDir(self):
59 """ 60 test the execution of self.movetoTempDir 61 """ 62 initcwd = os.getcwd() 63 self.__edpluginPE.moveToTempDir() 64 EDAssert.equal(os.path.abspath(os.path.dirname(os.getcwd())), os.path.abspath(tempfile.gettempdir()), "Test Move to Temporary Directory...") 65 os.chdir(initcwd)
66 67
69 """ 70 test the execution of detectNumberOfCPUs 71 """ 72 iNbCPU = EDUtilsParallel.detectNumberOfCPUs() 73 EDVerbose.unitTest("Detection of the number of Cores: %s" % iNbCPU) 74 EDAssert.equal(types.IntType, type(iNbCPU), "Number of CPU is an integer") 75 iNbCPU = EDUtilsParallel.detectNumberOfCPUs(1) #limited to 1 76 EDAssert.equal(1, iNbCPU, "Limit number of CPU") 77 iNbCPU = EDUtilsParallel.detectNumberOfCPUs(100, True) #forced to 100 78 EDAssert.equal(100, iNbCPU, "Force number of CPU")
79
80 - def process(self):
81 self.addTestMethod(self.unitTestMoveToTempDir) 82 self.addTestMethod(self.unitTestDetectNumberOfCPUs) 83 EDUtilsParallel.uninitializeNbThread()
84 85 86 87 if __name__ == '__main__': 88 89 edTestCaseEDUtilsTable = EDTestCaseParallelExecute("EDTestCaseParallelExecute") 90 edTestCaseEDUtilsTable.execute() 91