• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python2.4
2#
3# Copyright 2010, The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# 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.
16
17"""Test runner to run all the tests in this package."""
18
19import os
20import re
21import sys
22import unittest
23
24
25TESTCASE_RE = re.compile('_test\.py$')
26
27
28def AllTestFilesInDir(path):
29  """Finds all the unit test files in the given path."""
30  return filter(TESTCASE_RE.search, os.listdir(path))
31
32
33def suite(loader=unittest.defaultTestLoader):
34  """Creates the all_tests TestSuite."""
35  script_parent_path = os.path.abspath(os.path.dirname(sys.argv[0]))
36  # Find all the _test.py files in the same directory we are in
37  test_files = AllTestFilesInDir(script_parent_path)
38  # Convert them into module names
39  module_names = [os.path.splitext(f)[0] for f in test_files]
40  # And import them
41  modules = map(__import__, module_names)
42  # And create the test suite for all these modules
43  return unittest.TestSuite([loader.loadTestsFromModule(m) for m in modules])
44
45if __name__ == '__main__':
46  result = unittest.TextTestRunner().run(suite())
47  if not result.wasSuccessful():
48    # On failure return an error code
49    sys.exit(1)
50