1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#!/usr/bin/env python3
"""
Pitivi unit tests
"""
import glob
import os
import sys
import unittest
from tempfile import mkdtemp
import gi.overrides
def get_pitivi_dir():
"""Gets the pitivi root directory."""
tests_dir = os.path.dirname(os.path.abspath(__file__))
pitivi_dir = os.path.join(tests_dir, os.path.pardir)
return os.path.abspath(pitivi_dir)
def _prepend_env_paths(**args):
"""Prepends one or more paths to an environment variable."""
for name, value in args.items():
if not isinstance(value, list):
value = [value]
os.environ[name] = os.pathsep.join(
value + os.environ.get(name, "").split(
os.pathsep))
def setup():
"""Sets paths and initializes modules, to be able to run the tests."""
# Make sure xdg_*_home return temp dirs, to avoid touching
# the config files of the developer.
os.environ['XDG_DATA_HOME'] = mkdtemp()
os.environ['XDG_CONFIG_HOME'] = mkdtemp()
os.environ['XDG_CACHE_HOME'] = mkdtemp()
# Make available to configure.py the top level dir.
pitivi_dir = get_pitivi_dir()
sys.path.insert(0, pitivi_dir)
from pitivi import configure
# Let Gst overrides from our prefix take precedence over any
# other, making sure they are used.
local_overrides = os.path.join(configure.LIBDIR,
"python" + sys.version[:3],
"site-packages", "gi", "overrides")
gi.overrides.__path__.insert(0, local_overrides)
# Make sure that flatpak gst-python overrides are always used first.
flatpak_gst_python_path = os.path.join("/app/lib/", "python" + sys.version[:3],
"site-packages", "gi", "overrides")
if os.path.exists(flatpak_gst_python_path):
gi.overrides.__path__.insert(0, flatpak_gst_python_path)
# Make available the compiled C code.
sys.path.append(configure.BUILDDIR)
subproject_paths = os.path.join(configure.BUILDDIR, "subprojects", "gst-transcoder")
_prepend_env_paths(LD_LIBRARY_PATH=subproject_paths,
GST_PLUGIN_PATH=subproject_paths,
GI_TYPELIB_PATH=subproject_paths,
GST_PRESET_PATH=[os.path.join(pitivi_dir, "data", "videopresets"),
os.path.join(pitivi_dir, "data", "audiopresets")],
GST_ENCODING_TARGET_PATH=[os.path.join(pitivi_dir, "tests", "test-encoding-targets"),
os.path.join(pitivi_dir, "data", "encoding-profiles")])
os.environ.setdefault('PITIVI_TOP_LEVEL_DIR', pitivi_dir)
# Make sure the modules are initialized correctly.
from pitivi import check
check.initialize_modules()
res = check.check_requirements()
from pitivi.utils import loggable as log
log.init('PITIVI_DEBUG')
return res
if not setup():
raise ImportError("Could not setup testsuite")
|