[pitivi] Fix undo tests



commit a8dfc8d59243edfc108a3d68ac8cecf58051f249
Author: Thibault Saunier <tsaunier gnome org>
Date:   Tue Dec 9 20:06:25 2014 +0100

    Fix undo tests
    
    That implies:
        * Use the pitivi Project  subclass of GESProject in the tests, that
          is needed for the undo subsystem to work properly (we need access
          to the pipeline to flush it)
    
        * Make sure that audio and video tracks are added to newly created
          Blank projects
    
        * We properly disconnect from TrackElements when removing a clip
          from a layer
    
        * Adding a clip leads to 3 Actions as GES will set the height and
          width of clips now

 pitivi/project.py           |    1 +
 pitivi/undo/timeline.py     |   21 ++++++++++++++++-----
 tests/runtests.py           |    2 +-
 tests/test_undo_timeline.py |   11 +++++++++--
 4 files changed, 27 insertions(+), 8 deletions(-)
---
diff --git a/pitivi/project.py b/pitivi/project.py
index c2687b7..f0213e1 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -596,6 +596,7 @@ class ProjectManager(GObject.Object, Loggable):
         project.author = getpwuid(os.getuid()).pw_gecos.split(",")[0]
 
         project.createTimeline()
+        project._ensureTracks()
         self.current_project = project
         self.emit("new-project-created", project)
 
diff --git a/pitivi/undo/timeline.py b/pitivi/undo/timeline.py
index 742576e..6efb029 100644
--- a/pitivi/undo/timeline.py
+++ b/pitivi/undo/timeline.py
@@ -565,6 +565,9 @@ class TimelineLogObserver(Loggable):
         if isinstance(clip, GES.TransitionClip):
             return
 
+        for child in clip.get_children(True):
+            self._disconnectFromTrackElement(child)
+
         clip.disconnect_by_func(self._clipTrackElementAddedCb)
         clip.disconnect_by_func(self._clipTrackElementRemovedCb)
         tracker = self.clip_property_trackers.pop(clip)
@@ -617,12 +620,20 @@ class TimelineLogObserver(Loggable):
 
     def _disconnectFromControlSource(self, binding):
         control_source = binding.props.control_source
-        control_source.disconnect_by_func(self._controlSourceKeyFrameAddedCb)
-        control_source.disconnect_by_func(self._controlSourceKeyFrameRemovedCb)
 
-        tracker = self.control_source_keyframe_trackers.pop(control_source)
-        tracker.disconnectFromObject(control_source)
-        tracker.disconnect_by_func(self._controlSourceKeyFrameMovedCb)
+        try:
+            control_source.disconnect_by_func(self._controlSourceKeyFrameAddedCb)
+            control_source.disconnect_by_func(self._controlSourceKeyFrameRemovedCb)
+        except TypeError:
+            pass
+
+        try:
+            tracker = self.control_source_keyframe_trackers.pop(control_source)
+            tracker.disconnectFromObject(control_source)
+            tracker.disconnect_by_func(self._controlSourceKeyFrameMovedCb)
+        except KeyError:
+            self.debug("Control source already disconnected: %s" % control_source)
+            pass
 
     def _clipAddedCb(self, layer, clip):
         if isinstance(clip, GES.TransitionClip):
diff --git a/tests/runtests.py b/tests/runtests.py
index 3877084..10830b6 100644
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 
 """Pitivi tests runner."""
 
diff --git a/tests/test_undo_timeline.py b/tests/test_undo_timeline.py
index 9118c45..9558a98 100644
--- a/tests/test_undo_timeline.py
+++ b/tests/test_undo_timeline.py
@@ -31,6 +31,9 @@ from pitivi.undo.timeline import TimelineLogObserver, \
     ClipAdded, ClipRemoved, \
     ClipPropertyChanged, TrackElementAdded
 from pitivi.undo.undo import UndoableActionLog
+from pitivi.project import Project
+from pitivi.application import Pitivi
+from pitivi.utils.loggable import Loggable
 
 
 class TimelineLogObserverSpy(TimelineLogObserver):
@@ -103,7 +106,11 @@ class TestTimelineLogObserver(TestCase):
 class TestTimelineUndo(TestCase):
 
     def setUp(self):
-        self.timeline = GES.Timeline.new_audio_video()
+        app = Pitivi()
+        app._startupCb(app)
+        app.project_manager.newBlankProject()
+
+        self.timeline = app.project_manager.current_project.timeline
         self.layer = GES.Layer()
         self.timeline.add_layer(self.layer)
         self.action_log = UndoableActionLog()
@@ -130,7 +137,7 @@ class TestTimelineUndo(TestCase):
 
         self.assertEqual(1, len(stacks))
         stack = stacks[0]
-        self.assertEqual(1, len(stack.done_actions))
+        self.assertEqual(3, len(stack.done_actions))
         action = stack.done_actions[0]
         self.assertTrue(isinstance(action, ClipAdded))
         self.assertTrue(clip1 in self.getTimelineClips())


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