[pitivi] Concider asset loaded through proxy as OK when loading a project
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] Concider asset loaded through proxy as OK when loading a project
- Date: Thu, 11 Feb 2016 12:30:26 +0000 (UTC)
commit 39dfe33751aa6e27b8193eab1b6647c409c7c627
Author: Thibault Saunier <tsaunier gnome org>
Date: Wed Feb 10 18:22:43 2016 +0100
Concider asset loaded through proxy as OK when loading a project
Add a test to verify we properly react on definitely missing file
And fix a minor bug in tabsmanager when trying to instanciate several
MainWindow inside the same process.
And make things pylint compliant.
Reviewed-by: Alex Băluț <alexandru balut gmail com>
Differential Revision: https://phabricator.freedesktop.org/D759
pitivi/mainwindow.py | 2 +-
pitivi/tabsmanager.py | 28 +++++++---
tests/common.py | 52 +++++++++++++++++--
tests/test_mainwindow.py | 118 +++++++++++++++++++++++++++++++++++++++----
tests/test_media_library.py | 18 +------
5 files changed, 177 insertions(+), 41 deletions(-)
---
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index e294c35..c567d03 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -995,7 +995,7 @@ class PitiviMainWindow(Gtk.ApplicationWindow, Loggable):
else:
dialog.hide()
- if self.app.proxy_manager.checkProxyLoadingSucceeded(asset):
+ if not self.app.proxy_manager.checkProxyLoadingSucceeded(asset):
# Reset the project manager and disconnect all the signals.
self.app.project_manager.newBlankProject(
ignore_unsaved_changes=True)
diff --git a/pitivi/tabsmanager.py b/pitivi/tabsmanager.py
index cebe63f..e821e1d 100644
--- a/pitivi/tabsmanager.py
+++ b/pitivi/tabsmanager.py
@@ -18,14 +18,19 @@
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
+"""
+A helper object to work with Gtk.Notebook tabs
+"""
from gi.repository import Gtk
from gi.repository import Gdk
+
+from pitivi.utils.loggable import Loggable
from pitivi.utils.ui import SPACING
-from pitivi.settings import GlobalSettings
+from pitivi.settings import GlobalSettings, ConfigError
-class BaseTabs(Gtk.Notebook):
+class BaseTabs(Gtk.Notebook, Loggable):
"""
@type app: Pitivi
@@ -33,6 +38,7 @@ class BaseTabs(Gtk.Notebook):
def __init__(self, app):
Gtk.Notebook.__init__(self)
+ Loggable.__init__(self)
self.set_border_width(SPACING)
self.set_scrollable(True)
self.connect("create-window", self._createWindowCb)
@@ -40,6 +46,7 @@ class BaseTabs(Gtk.Notebook):
notebook_widget_settings = self.get_settings()
notebook_widget_settings.props.gtk_dnd_drag_threshold = 1
+ # pylint: disable=arguments-differ
def append_page(self, child, label):
child_name = label.get_text()
Gtk.Notebook.append_page(self, child, label)
@@ -60,8 +67,8 @@ class BaseTabs(Gtk.Notebook):
self.child_set_property(child, "tab-fill", True)
label.props.xalign = 0.0
- def _detachedComponentWindowDestroyCb(self, window, child,
- original_position, child_name):
+ def __detached_window_destroyed_cb(self, window, child,
+ original_position, child_name):
notebook = window.get_child()
position = notebook.page_num(child)
notebook.remove_page(position)
@@ -108,10 +115,10 @@ class BaseTabs(Gtk.Notebook):
window.show_all()
window.move(x, y)
window.connect(
- "configure-event", self._detachedComponentWindowConfiguredCb,
+ "configure-event", self._detached_window_configure_cb,
child_name)
window.connect(
- "destroy", self._detachedComponentWindowDestroyCb, child,
+ "destroy", self.__detached_window_destroyed_cb, child,
original_position, child_name)
if not created_by_signal:
@@ -122,7 +129,7 @@ class BaseTabs(Gtk.Notebook):
else:
return notebook
- def _detachedComponentWindowConfiguredCb(self, window, event, child_name):
+ def _detached_window_configure_cb(self, window, event, child_name):
"""
When the user configures the detached window
(changes its size, position, etc.), save the settings.
@@ -141,7 +148,12 @@ class BaseTabs(Gtk.Notebook):
If they do not exist already, create default settings
to save the state of a detachable widget.
"""
- GlobalSettings.addConfigSection(child_name)
+ try:
+ GlobalSettings.addConfigSection(child_name)
+ except ConfigError:
+ self.info("Section %s already exists", child_name)
+ return
+
GlobalSettings.addConfigOption(child_name + "docked",
section=child_name,
key="docked",
diff --git a/tests/common.py b/tests/common.py
index 442e9dd..549bcac 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -4,8 +4,9 @@ A collection of objects to use for testing
import os
import gc
-import unittest
+import sys
import tempfile
+import unittest
from gi.repository import Gdk
from gi.repository import Gst
@@ -31,16 +32,27 @@ def cleanPitiviMock(app):
def getPitiviMock(settings=None, proxyingStrategy=ProxyingStrategy.NOTHING,
numTranscodingJobs=4):
+ def __create_settings():
+ settings = mock.MagicMock()
+
+ settings.proxyingStrategy = proxyingStrategy
+ settings.numTranscodingJobs = numTranscodingJobs
+
+ return settings
+
app = mock.MagicMock()
app.write_action = mock.MagicMock(spec=Pitivi.write_action)
check.check_requirements()
if not settings:
- settings = mock.MagicMock()
+ settings = __create_settings()
+ elif isinstance(settings, dict):
+ nsettings = __create_settings()
- settings.proxyingStrategy = proxyingStrategy
- settings.numTranscodingJobs = numTranscodingJobs
+ for key, value in settings.items():
+ setattr(nsettings, key, value)
+ settings = nsettings
app.settings = settings
app.proxy_manager = ProxyManager(app)
@@ -133,6 +145,38 @@ class TestCase(unittest.TestCase, Loggable):
expect_selected)
self.assertEqual(bClip.selected.selected, expect_selected)
+ def createTempProject(self):
+ """
+ Created a temporary project
+
+ Always generate projects with missing assets for now
+
+ Returns:
+ str: The path of the new project
+ str: The URI of the new project
+ """
+ unused_fd, xges_path = tempfile.mkstemp()
+ with open(xges_path, "w") as xges:
+ xges.write("""
+<ges version='0.1'>
+ <project>
+ <ressources>
+ <asset id='file:///icantpossiblyexist.png'
+ extractable-type-name='GESUriClip' />
+ </ressources>
+ <timeline>
+ <track caps='video/x-raw' track-type='4' track-id='0' />
+ <layer priority='0'>
+ <clip id='0' asset-id='file:///icantpossiblyexist.png'
+ type-name='GESUriClip' layer-priority='0' track-types='4'
+ start='0' duration='2590000000' inpoint='0' rate='0' />
+ </layer>
+ </timeline>
+</project>
+</ges>""")
+
+ return xges_path, Gst.filename_to_uri(xges_path)
+
def getSampleUri(sample):
assets_dir = os.path.dirname(os.path.abspath(__file__))
diff --git a/tests/test_mainwindow.py b/tests/test_mainwindow.py
index 8f54599..a5bd286 100644
--- a/tests/test_mainwindow.py
+++ b/tests/test_mainwindow.py
@@ -17,28 +17,124 @@
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
-from unittest import TestCase, mock
+"""
+Test for pitivi/mainwindow.py
+"""
+
+import os
+
+from unittest import mock
from gi.repository import GES
+from gi.repository import GLib
+from gi.repository import Gtk
from pitivi.mainwindow import PitiviMainWindow
+from pitivi.project import ProjectManager
+from pitivi.utils.misc import disconnectAllByFunc
+from tests import common
-class TestMainWindow(TestCase):
- def setUp(self):
- app = mock.MagicMock()
- self.mainwindow = PitiviMainWindow(app)
+class TestMainWindow(common.TestCase):
+ """
+ Test PitiviMainWindow
+ """
def testSwitchContextTab(self):
- for expected_tab, bElement in [
+ """
+ Test tab switches
+ """
+ app = common.getPitiviMock()
+ mainwindow = PitiviMainWindow(app)
+ for expected_tab, b_element in [
(2, GES.TitleClip()),
(0, GES.SourceClip()),
(1, GES.TransitionClip())]:
- self.mainwindow.switchContextTab(bElement)
- self.assertEqual(
- expected_tab, self.mainwindow.context_tabs.get_current_page(), bElement)
+ mainwindow.switchContextTab(b_element)
+ self.assertEqual(expected_tab,
+ mainwindow.context_tabs.get_current_page(),
+ b_element)
# Make sure the tab does not change when using an invalid argument.
- self.mainwindow.switchContextTab("invalid")
+ mainwindow.switchContextTab("invalid")
self.assertEqual(
- expected_tab, self.mainwindow.context_tabs.get_current_page())
+ expected_tab, mainwindow.context_tabs.get_current_page())
+
+ mainwindow.destroy()
+
+ def __loading_failure(self, has_proxy):
+ mainloop = GLib.MainLoop.new(None, False)
+
+ app = common.getPitiviMock(
+ settings={"lastProjectFolder": "/tmp",
+ "edgeSnapDeadband": 32})
+ app.project_manager = ProjectManager(app)
+ mainwindow = PitiviMainWindow(app)
+ mainwindow.viewer = mock.MagicMock()
+
+ def __pm_missing_uri_cb(project_manager, project,
+ error, asset):
+ nonlocal mainloop
+ nonlocal mainwindow
+ nonlocal self
+ nonlocal app
+ nonlocal has_proxy
+
+ with mock.patch('gi.repository.Gtk.Dialog') as dialog:
+ failed_cb = mock.MagicMock()
+ app.project_manager.connect("new-project-failed", failed_cb)
+
+ dialog.return_value = mock.MagicMock()
+ dialog.return_value.run = mock.MagicMock(
+ return_value=Gtk.ResponseType.CLOSE)
+
+ # Call the actual callback
+ # pylint: disable=protected-access
+ app.proxy_manager.checkProxyLoadingSucceeded = \
+ mock.MagicMock(return_value=has_proxy)
+
+ mainwindow._projectManagerMissingUriCb(
+ project_manager, project, error, asset)
+
+ self.assertTrue(dialog.called)
+ self.assertTrue(dialog.return_value.run.called)
+ self.assertEqual(failed_cb.called, not has_proxy)
+
+ # pylint: disable=protected-access
+ app.project_manager.connect("missing-uri",
+ mainwindow._projectManagerMissingUriCb)
+ # pylint: disable=protected-access
+ app.project_manager.connect("new-project-failed",
+ mainwindow._projectManagerNewProjectFailedCb)
+
+ mainwindow.destroy()
+ mainloop.quit()
+
+ # pylint: disable=protected-access
+ disconnectAllByFunc(app.project_manager,
+ mainwindow._projectManagerMissingUriCb)
+ disconnectAllByFunc(app.project_manager,
+ mainwindow._projectManagerNewProjectFailedCb)
+
+ app.project_manager.connect("missing-uri",
+ __pm_missing_uri_cb)
+
+ xges_path, uri = self.createTempProject()
+ try:
+ app.project_manager.loadProject(uri)
+ finally:
+ os.remove(xges_path)
+
+ mainloop.run()
+
+ def test_loading_project_no_proxy(self):
+ """
+ Test loading failure without proxies
+ """
+ self.__loading_failure(has_proxy=False)
+
+ def test_loading_project_wth_proxy(self):
+ """
+ Test loading failure with proxies
+ """
+ self.__loading_failure(has_proxy=True)
diff --git a/tests/test_media_library.py b/tests/test_media_library.py
index 1d8209e..0be7e2e 100644
--- a/tests/test_media_library.py
+++ b/tests/test_media_library.py
@@ -195,23 +195,7 @@ class TestMediaLibrary(common.TestCase):
self.assertEqual(asset.get_proxy(), proxy)
def testMissingUriDisplayed(self):
- # Load a project with a missing asset.
- unused, xges_path = tempfile.mkstemp()
- with open(xges_path, "w") as xges:
- xges.write("""<ges version='0.1'>
- <project>
- <ressources>
- <asset id='file:///icantpossiblyexist.png' extractable-type-name='GESUriClip' />
- </ressources>
- <timeline>
- <track caps='video/x-raw' track-type='4' track-id='0' />
- <layer priority='0'>
- <clip id='0' asset-id='file:///icantpossiblyexist.png' type-name='GESUriClip' layer-priority='0'
track-types='4' start='0' duration='2590000000' inpoint='0' rate='0' />
- </layer>
- </timeline>
-</project>
-</ges>""")
- uri = "file://%s" % xges_path
+ xges_path, uri = self.createTempProject()
try:
self._customSetUp(None, project_uri=uri)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]