Adding gst-python package
[platform/upstream/gst-python.git] / testsuite / runtests.py
1 #!/usr/bin/env python
2 # -*- Mode: Python -*-
3 # vi:si:et:sw=4:sts=4:ts=4
4 #
5 # gst-python - Python bindings for GStreamer
6 # Copyright (C) 2002 David I. Lehn
7 # Copyright (C) 2004 Johan Dahlin
8 # Copyright (C) 2005 Edward Hervey
9 #
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public
12 # License as published by the Free Software Foundation; either
13 # version 2.1 of the License, or (at your option) any later version.
14 #
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
23
24 import os
25 import sys
26 import unittest
27
28
29 def _testcases(filenames):
30     """Yield testcases out of filenames."""
31     for filename in filenames:
32         if filename.endswith(".py"):
33             yield filename[:-3]
34
35
36 def _tests_suite():
37     """Pick which tests to run."""
38     testcase = os.getenv("TESTCASE")
39     if testcase:
40         testcases = [testcase]
41     else:
42         testcases = _testcases(sys.argv[1:])
43     loader = unittest.TestLoader()
44     return loader.loadTestsFromNames(testcases)
45
46
47 def setup():
48     return
49
50
51 if __name__ == "__main__":
52     setup()
53
54     # Set verbosity.
55     descriptions = 1
56     verbosity = 1
57     if 'VERBOSE' in os.environ:
58         descriptions = 2
59         verbosity = 2
60
61     suite = _tests_suite()
62     if not list(suite):
63         raise Exception("No tests found")
64
65     # Run the tests.
66     testRunner = unittest.TextTestRunner(descriptions=descriptions,
67                                          verbosity=verbosity)
68     result = testRunner.run(suite)
69     if result.failures or result.errors:
70         sys.exit(1)