source: proiecte/HadoopJUnit/hadoop-0.20.1/contrib/hod/testing/main.py @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#Licensed to the Apache Software Foundation (ASF) under one
2#or more contributor license agreements.  See the NOTICE file
3#distributed with this work for additional information
4#regarding copyright ownership.  The ASF licenses this file
5#to you under the Apache License, Version 2.0 (the
6#"License"); you may not use this file except in compliance
7#with the License.  You may obtain a copy of the License at
8
9#     http://www.apache.org/licenses/LICENSE-2.0
10
11#Unless required by applicable law or agreed to in writing, software
12#distributed under the License is distributed on an "AS IS" BASIS,
13#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#See the License for the specific language governing permissions and
15#limitations under the License.
16import unittest, os, sys, re
17
18myPath = os.path.realpath(sys.argv[0])
19rootDirectory   = re.sub("/testing/.*", "", myPath)
20testingDir = os.path.join(rootDirectory, "testing")
21
22sys.path.append(rootDirectory)
23
24from testing.lib import printSeparator, printLine
25
26moduleList = []
27allList = []
28excludes = [
29           ]
30
31# Build a module list by scanning through all files in testingDir
32for file in os.listdir(testingDir):
33  if(re.search(r".py$", file) and re.search(r"^test", file)):
34    # All .py files with names starting in 'test'
35    module = re.sub(r"^test","",file)
36    module = re.sub(r".py$","",module)
37    allList.append(module)
38    if module not in excludes:
39      moduleList.append(module)
40
41printLine("All testcases - %s" % allList)
42printLine("Excluding the testcases - %s" % excludes)
43printLine("Executing the testcases - %s" % moduleList)
44
45testsResult = 0
46# Now import each of these modules and start calling the corresponding
47#testSuite methods
48for moduleBaseName in moduleList:
49  try:
50    module = "testing.test" + moduleBaseName
51    suiteCaller = "Run" + moduleBaseName + "Tests"
52    printSeparator()
53    printLine("Running %s" % suiteCaller)
54
55    # Import the corresponding test cases module
56    imported_module = __import__(module , fromlist=[suiteCaller] )
57   
58    # Call the corresponding suite method now
59    testRes = getattr(imported_module, suiteCaller)()
60    testsResult = testsResult + testRes
61    printLine("Finished %s. TestSuite Result : %s\n" % \
62                                              (suiteCaller, testRes))
63  except ImportError, i:
64    # Failed to import a test module
65    printLine(i)
66    testsResult = testsResult + 1
67    pass
68  except AttributeError, n:
69    # Failed to get suiteCaller from a test module
70    printLine(n)
71    testsResult = testsResult + 1
72    pass
73  except Exception, e:
74    # Test module suiteCaller threw some exception
75    printLine("%s failed. \nReason : %s" % (suiteCaller, e))
76    printLine("Skipping %s" % suiteCaller)
77    testsResult = testsResult + 1
78    pass
79
80if testsResult != 0:
81  printSeparator()
82  printLine("Total testcases with failure or error : %s" % testsResult)
83sys.exit(testsResult)
Note: See TracBrowser for help on using the repository browser.