~timo-jyrinki/ubuntu/trusty/pitivi/backport_utopic_fixes

« back to all changes in this revision

Viewing changes to tests/runtests.py

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2014-03-29 15:22:50 UTC
  • mto: (3.1.23 experimental)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20140329152250-flg9onx416bqf3e3
Tags: upstream-0.93
Import upstream version 0.93

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python2
 
2
 
 
3
"""Pitivi tests runner."""
 
4
 
1
5
import os
2
6
import sys
3
7
import unittest
4
8
 
5
 
from gi.repository import GObject
6
 
# This call has to be made before any "import Gst" call!
7
 
# We have to do this call here, even though it already is in __init__.py,
8
 
# because this tool is run directly, as an executable.
9
 
GObject.threads_init()
10
 
 
11
 
from pitivi.check import check_hard_dependencies
12
 
 
13
 
parent = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
14
 
 
15
 
sys.path.append(os.path.join(parent, "pitivi/coptimizations/.libs"))
16
 
 
17
 
missing_hard_deps = check_hard_dependencies()
18
 
# This differs slightly from bin/pitivi.in as we don't check soft deps here:
19
 
if missing_hard_deps:
20
 
    print "\nERROR - The following hard dependencies are unmet:"
21
 
    print "=================================================="
22
 
    for dep in missing_hard_deps:
23
 
        print "-", dep + ":", missing_hard_deps[dep]
24
 
    print ""
25
 
    sys.exit(2)
26
 
 
27
 
 
28
 
def gettestnames(file_names):
29
 
    test_names = [file_name[:-3] for file_name in file_names]
30
 
    return test_names
31
 
 
32
 
loader = unittest.TestLoader()
33
 
 
34
 
# Set verbosity.
35
 
descriptions = 1
36
 
verbosity = 1
37
 
if 'VERBOSE' in os.environ:
38
 
    descriptions = 2
39
 
    verbosity = 2
40
 
from pitivi.utils import loggable as log
41
 
log.init('PITIVI_DEBUG', 1)
42
 
 
43
 
# Make available to configure.py the top level dir.
44
 
dir = os.path.dirname(os.path.abspath(__file__))
45
 
top_srcdir = os.path.split(dir)[0]
46
 
os.environ.setdefault('PITIVI_TOP_LEVEL_DIR', top_srcdir)
47
 
 
48
 
# Pick which tests to run.
49
 
TEST_CASE = os.getenv("TESTCASE")
50
 
if TEST_CASE:
51
 
    test_names = [TEST_CASE]
52
 
else:
53
 
    test_names = gettestnames(sys.argv[1:])
54
 
suite = loader.loadTestsFromNames(test_names)
55
 
if not list(suite):
56
 
    raise Exception("No tests found")
57
 
 
58
 
# Run the tests.
59
 
testRunner = unittest.TextTestRunner(descriptions=descriptions,
60
 
    verbosity=verbosity)
61
 
result = testRunner.run(suite)
62
 
if result.failures or result.errors:
63
 
    sys.exit(1)
 
9
 
 
10
def _testcases(filenames):
 
11
    """Yield testcases out of filenames."""
 
12
    for filename in filenames:
 
13
        if filename.endswith(".py"):
 
14
            yield filename[:-3]
 
15
 
 
16
 
 
17
def _tests_suite():
 
18
    """Pick which tests to run."""
 
19
    testcase = os.getenv("TESTCASE")
 
20
    if testcase:
 
21
        testcases = [testcase]
 
22
    else:
 
23
        testcases = _testcases(sys.argv[1:])
 
24
    loader = unittest.TestLoader()
 
25
    return loader.loadTestsFromNames(testcases)
 
26
 
 
27
 
 
28
def get_pitivi_dir():
 
29
    tests_dir = os.path.dirname(os.path.abspath(__file__))
 
30
    pitivi_dir = os.path.join(tests_dir, os.path.pardir)
 
31
    return os.path.abspath(pitivi_dir)
 
32
 
 
33
 
 
34
def get_build_dir():
 
35
    from pitivi.configure import in_devel
 
36
    if in_devel():
 
37
        # It's the same.
 
38
        build_dir = get_pitivi_dir()
 
39
    else:
 
40
        # Probably running make distcheck. The path to the test files
 
41
        # is different than the build path, so we must use the current
 
42
        # dir which is build_path/tests.
 
43
        build_dir = os.path.join(os.path.abspath(os.path.curdir), os.path.pardir)
 
44
    return os.path.abspath(build_dir)
 
45
 
 
46
 
 
47
def setup():
 
48
    # Make available to configure.py the top level dir.
 
49
    pitivi_dir = get_pitivi_dir()
 
50
    os.environ.setdefault('PITIVI_TOP_LEVEL_DIR', pitivi_dir)
 
51
 
 
52
    # Make available the compiled C code.
 
53
    build_dir = get_build_dir()
 
54
    libs_dir = os.path.join(build_dir, "pitivi/coptimizations/.libs")
 
55
    sys.path.append(libs_dir)
 
56
 
 
57
    # Make sure the modules are initialized correctly.
 
58
    from pitivi.check import initialize_modules
 
59
    initialize_modules()
 
60
 
 
61
    try:
 
62
        import mock
 
63
    except ImportError, e:
 
64
        raise Exception("Python mock library missing! www.voidspace.org.uk/python/mock", e)
 
65
 
 
66
 
 
67
if __name__ == "__main__":
 
68
    setup()
 
69
 
 
70
    # Set verbosity.
 
71
    descriptions = 1
 
72
    verbosity = 1
 
73
    if 'VERBOSE' in os.environ:
 
74
        descriptions = 2
 
75
        verbosity = 2
 
76
    from pitivi.utils import loggable as log
 
77
    log.init('PITIVI_DEBUG')
 
78
 
 
79
    suite = _tests_suite()
 
80
    if not list(suite):
 
81
        raise Exception("No tests found")
 
82
 
 
83
    # Run the tests.
 
84
    testRunner = unittest.TextTestRunner(descriptions=descriptions,
 
85
        verbosity=verbosity)
 
86
    result = testRunner.run(suite)
 
87
    if result.failures or result.errors:
 
88
        sys.exit(1)