[pitivi] tests: Fix the tests to initialize the modules properly



commit 3cdad622f6716359b8e9603155cd9ef35dee89c4
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Sun Jan 26 17:57:50 2014 +0100

    tests: Fix the tests to initialize the modules properly

 bin/pitivi.in     |   50 ++++++++++++++++----------------------------------
 pitivi/check.py   |   30 ++++++++++++++++++++++++++++++
 tests/runtests.py |   23 ++++++-----------------
 3 files changed, 52 insertions(+), 51 deletions(-)
---
diff --git a/bin/pitivi.in b/bin/pitivi.in
index 5bb7c48..b14f4c7 100644
--- a/bin/pitivi.in
+++ b/bin/pitivi.in
@@ -99,27 +99,11 @@ def _add_pitivi_path():
 
 
 def _initialize_modules():
-    from gi.repository import Gdk
-    Gdk.init([])
-    from gi.repository import GtkClutter
-    GtkClutter.init([])
-    from gi.repository import ClutterGst
-    ClutterGst.init([])
-
-    import gi
-    if not gi.version_info >= (3, 11):
-        from gi.repository import GObject
-        GObject.threads_init()
-
-    from gi.repository import Gst
-    Gst.init(None)
-    from gi.repository import GES
-    GES.init()
-
-    # This is required because of:
-    # https://bugzilla.gnome.org/show_bug.cgi?id=656314
-    from gi.repository import GdkX11
-    GdkX11  # noop
+    from pitivi.check import initialize_modules
+    try:
+        initialize_modules()
+    except Exception, e:
+        print "Failed to initialize modules: ", e
 
 
 def _check_dependencies():
@@ -152,18 +136,16 @@ def _run_pitivi():
     sys.exit(ptv.main(sys.argv))
 
 
-try:
-    _add_pitivi_path()
+if __name__ == "__main__":
     try:
+        _add_pitivi_path()
         _initialize_modules()
-    except Exception, e:
-        print "Failed to initialize modules: ", e
-    # Dep checks really have to happen here, not in application.py. Otherwise,
-    # as soon as application.py starts, it will try importing all the code and
-    # the classes in application.py will not even have the opportunity to run.
-    # We do these checks on every startup (even outside the dev environment, for
-    # soft deps); doing imports and gst registry checks has near-zero cost.
-    _check_dependencies()
-    _run_pitivi()
-except KeyboardInterrupt:
-    print "\tPitivi stopped by user with KeyboardInterrupt!"
+        # Dep checks really have to happen here, not in application.py. Otherwise,
+        # as soon as application.py starts, it will try importing all the code and
+        # the classes in application.py will not even have the opportunity to run.
+        # We do these checks on every startup (even outside the dev environment, for
+        # soft deps); doing imports and gst registry checks has near-zero cost.
+        _check_dependencies()
+        _run_pitivi()
+    except KeyboardInterrupt:
+        print "\tPitivi stopped by user with KeyboardInterrupt!"
diff --git a/pitivi/check.py b/pitivi/check.py
index c9dedf3..6012221 100644
--- a/pitivi/check.py
+++ b/pitivi/check.py
@@ -253,3 +253,33 @@ def check_soft_dependencies():
     # see fit. We can do a registry.find_plugin for specific encoders, but we
     # don't really have something generic to rely on; ideas/patches welcome.
     return missing_soft_deps
+
+
+def initialize_modules():
+    """
+    Initialize the modules.
+
+    This has to be done in a specific order otherwise the app
+    crashes on some systems.
+    """
+    from gi.repository import Gdk
+    Gdk.init([])
+    from gi.repository import GtkClutter
+    GtkClutter.init([])
+    from gi.repository import ClutterGst
+    ClutterGst.init([])
+
+    import gi
+    if not gi.version_info >= (3, 11):
+        from gi.repository import GObject
+        GObject.threads_init()
+
+    from gi.repository import Gst
+    Gst.init(None)
+    from gi.repository import GES
+    GES.init()
+
+    # This is required because of:
+    # https://bugzilla.gnome.org/show_bug.cgi?id=656314
+    from gi.repository import GdkX11
+    GdkX11  # noop
diff --git a/tests/runtests.py b/tests/runtests.py
index 7fe9e22..bef0815 100644
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -1,28 +1,17 @@
+#!/usr/bin/env python2
+
+"""Pitivi tests runner."""
+
 import os
 import sys
 import unittest
 
-from gi.repository import GObject
-# This call has to be made before any "import Gst" call!
-# We have to do this call here, even though it already is in __init__.py,
-# because this tool is run directly, as an executable.
-GObject.threads_init()
-
-from pitivi.check import check_hard_dependencies
 
 parent = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
-
 sys.path.append(os.path.join(parent, "pitivi/coptimizations/.libs"))
 
-missing_hard_deps = check_hard_dependencies()
-# This differs slightly from bin/pitivi.in as we don't check soft deps here:
-if missing_hard_deps:
-    print "\nERROR - The following hard dependencies are unmet:"
-    print "=================================================="
-    for dep in missing_hard_deps:
-        print "-", dep + ":", missing_hard_deps[dep]
-    print ""
-    sys.exit(2)
+from pitivi.check import initialize_modules
+initialize_modules()
 
 
 def gettestnames(file_names):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]