[pitivi] tests: Resurrect timeline undo tests
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] tests: Resurrect timeline undo tests
- Date: Tue, 6 May 2014 13:02:22 +0000 (UTC)
commit f104426d752949c0b3f9235f6358dfd0fb7afa86
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Thu Apr 10 13:08:39 2014 +0200
tests: Resurrect timeline undo tests
pitivi/undo/timeline.py | 6 +-
tests/Makefile.am | 2 +-
tests/common.py | 5 +
tests/test_timeline_undo.py | 298 -------------------------------------------
tests/test_undo_timeline.py | 261 +++++++++++++++++++++++++++++++++++++
5 files changed, 269 insertions(+), 303 deletions(-)
---
diff --git a/pitivi/undo/timeline.py b/pitivi/undo/timeline.py
index 5651417..5385404 100644
--- a/pitivi/undo/timeline.py
+++ b/pitivi/undo/timeline.py
@@ -235,8 +235,6 @@ class TimelineLogObserver(object):
for layer in timeline.get_layers():
for clip in layer.get_clips():
self._connectToClip(clip)
- for track_element in clip.get_children(True):
- self._connectToTrackElement(track_element)
def stopObserving(self, timeline):
self._disconnectFromTimeline(timeline)
@@ -274,8 +272,8 @@ class TimelineLogObserver(object):
clip.connect("child-added", self._clipTrackElementAddedCb)
clip.connect("child-removed", self._clipTrackElementRemovedCb)
- for element in clip.get_children(False):
- self._connectToTrackElement(element)
+ for track_element in clip.get_children(True):
+ self._connectToTrackElement(track_element)
def _disconnectFromClip(self, clip):
tracker = self.clip_property_trackers.pop(clip)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 84281be..22265c6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,8 +15,8 @@ tests = \
test_projectsettings.py \
test_signallable.py \
test_system.py \
- test_timeline_undo.py \
test_undo.py \
+ test_undo_timeline.py \
test_utils.py \
test_utils_timeline.py \
test_widgets.py
diff --git a/tests/common.py b/tests/common.py
index 6eced92..5b7930b 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -75,6 +75,11 @@ class TestCase(unittest.TestCase):
self._result = result
unittest.TestCase.run(self, result)
+ @staticmethod
+ def getSampleUri(sample):
+ dir = os.path.dirname(os.path.abspath(__file__))
+ return "file://%s/samples/%s" % (dir, sample)
+
class SignalMonitor(object):
def __init__(self, obj, *signals):
diff --git a/tests/test_undo_timeline.py b/tests/test_undo_timeline.py
new file mode 100644
index 0000000..11893c2
--- /dev/null
+++ b/tests/test_undo_timeline.py
@@ -0,0 +1,261 @@
+# -*- coding: utf-8 -*-
+#
+# tests/test_undo_timeline.py
+#
+# Copyright (c) 2009, Alessandro Decina <alessandro d gmail com>
+# Copyright (c) 2014, Alex Băluț <alexandru balut gmail com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+from unittest import TestCase
+
+from gi.repository import GES
+from gi.repository import Gst
+
+from tests import common
+
+from pitivi.undo.timeline import TimelineLogObserver, \
+ ClipAdded, ClipRemoved, \
+ ClipPropertyChanged, EffectAdded
+from pitivi.undo.undo import UndoableActionLog
+
+
+class TimelineLogObserverSpy(TimelineLogObserver):
+ def _connectToTimeline(self, timeline):
+ TimelineLogObserver._connectToTimeline(self, timeline)
+ timeline.connected = True
+
+ def _disconnectFromTimeline(self, timeline):
+ TimelineLogObserver._disconnectFromTimeline(self, timeline)
+ timeline.connected = False
+
+ def _connectToClip(self, clip):
+ TimelineLogObserver._connectToClip(self, clip)
+ clip.connected = True
+
+ def _disconnectFromClip(self, clip):
+ TimelineLogObserver._disconnectFromClip(self, clip)
+ clip.connected = False
+
+ def _connectToTrackElement(self, track_element):
+ TimelineLogObserver._connectToTrackElement(self, track_element)
+ track_element.connected = True
+
+ def _disconnectFromTrackElement(self, track_element):
+ TimelineLogObserver._disconnectFromTrackElement(self, track_element)
+ track_element.connected = False
+
+
+class TestTimelineLogObserver(TestCase):
+
+ def setUp(self):
+ self.action_log = UndoableActionLog()
+ self.observer = TimelineLogObserverSpy(self.action_log)
+
+ def testConnectionAndDisconnection(self):
+ timeline = GES.Timeline.new_audio_video()
+ layer = GES.Layer()
+ timeline.add_layer(layer)
+ self.observer.startObserving(timeline)
+ self.assertTrue(timeline.connected)
+
+ clip1 = GES.TitleClip()
+
+ layer.add_clip(clip1)
+ track_element1 = clip1.get_children(False)[0]
+ self.assertTrue(timeline.connected)
+ self.assertTrue(clip1.connected)
+ self.assertTrue(track_element1.connected)
+
+ layer.remove_clip(clip1)
+ self.assertTrue(timeline.connected)
+ self.assertFalse(clip1.connected)
+ self.assertFalse(track_element1.connected)
+
+ layer.add_clip(clip1)
+ track_element2 = clip1.get_children(False)[0]
+ self.assertTrue(timeline.connected)
+ self.assertTrue(clip1.connected)
+ self.assertFalse(track_element1.connected)
+ self.assertTrue(track_element2.connected)
+
+ self.observer.stopObserving(timeline)
+ self.assertFalse(timeline.connected)
+ self.assertFalse(clip1.connected)
+ self.assertFalse(track_element1.connected)
+ self.assertFalse(track_element2.connected)
+
+
+class TestTimelineUndo(TestCase):
+
+ def setUp(self):
+ self.timeline = GES.Timeline.new_audio_video()
+ self.layer = GES.Layer()
+ self.timeline.add_layer(self.layer)
+ self.action_log = UndoableActionLog()
+ self.observer = TimelineLogObserverSpy(self.action_log)
+ self.observer.startObserving(self.timeline)
+
+ def getTimelineClips(self):
+ for layer in self.timeline.layers:
+ for clip in layer.get_clips():
+ yield clip
+
+ @staticmethod
+ def commitCb(action_log, stack, nested, stacks):
+ stacks.append(stack)
+
+ def testAddClip(self):
+ stacks = []
+ self.action_log.connect("commit", TestTimelineUndo.commitCb, stacks)
+
+ clip1 = GES.TitleClip()
+ self.action_log.begin("add clip")
+ self.layer.add_clip(clip1)
+ self.action_log.commit()
+
+ self.assertEqual(1, len(stacks))
+ stack = stacks[0]
+ self.assertEqual(1, len(stack.done_actions))
+ action = stack.done_actions[0]
+ self.assertTrue(isinstance(action, ClipAdded))
+ self.assertTrue(clip1 in self.getTimelineClips())
+
+ self.action_log.undo()
+ self.assertFalse(clip1 in self.getTimelineClips())
+
+ self.action_log.redo()
+ self.assertTrue(clip1 in self.getTimelineClips())
+
+ def testRemoveClip(self):
+ stacks = []
+ self.action_log.connect("commit", TestTimelineUndo.commitCb, stacks)
+
+ clip1 = GES.TitleClip()
+ self.layer.add_clip(clip1)
+ self.action_log.begin("remove clip")
+ self.layer.remove_clip(clip1)
+ self.action_log.commit()
+
+ self.assertEqual(1, len(stacks))
+ stack = stacks[0]
+ self.assertEqual(1, len(stack.done_actions))
+ action = stack.done_actions[0]
+ self.assertTrue(isinstance(action, ClipRemoved))
+ self.assertFalse(clip1 in self.getTimelineClips())
+
+ self.action_log.undo()
+ self.assertTrue(clip1 in self.getTimelineClips())
+
+ self.action_log.redo()
+ self.assertFalse(clip1 in self.getTimelineClips())
+
+ def testAddEffectToClip(self):
+ stacks = []
+ self.action_log.connect("commit", TestTimelineUndo.commitCb, stacks)
+
+ clip1 = GES.TitleClip()
+ self.layer.add_clip(clip1)
+
+ effect1 = GES.Effect.new("videoconvert ! agingtv ! videoconvert")
+ self.action_log.begin("add effect")
+ clip1.add(effect1)
+ self.action_log.commit()
+
+ self.assertEqual(1, len(stacks))
+ stack = stacks[0]
+ self.assertEqual(1, len(stack.done_actions), stack.done_actions)
+ action = stack.done_actions[0]
+ self.assertTrue(isinstance(action, EffectAdded))
+
+ self.assertTrue(effect1 in clip1.get_children(True))
+ self.assertEqual(1, len([effect for effect in
+ clip1.get_children(True)
+ if isinstance(effect, GES.Effect)]))
+
+ self.action_log.undo()
+ self.assertFalse(effect1 in clip1.get_children(True))
+
+ self.action_log.redo()
+ self.assertEqual(1, len([effect for effect in
+ clip1.get_children(True)
+ if isinstance(effect, GES.Effect)]))
+
+ def testClipPropertyChange(self):
+ stacks = []
+ self.action_log.connect("commit", TestTimelineUndo.commitCb, stacks)
+
+ clip1 = GES.TitleClip()
+ self.layer.add_clip(clip1)
+ clip1.set_start(5 * Gst.SECOND)
+ clip1.set_duration(20 * Gst.SECOND)
+ self.layer.add_clip(clip1)
+ self.action_log.begin("modify clip")
+ clip1.set_start(10 * Gst.SECOND)
+ self.action_log.commit()
+
+ self.assertEqual(1, len(stacks))
+ stack = stacks[0]
+ self.assertEqual(1, len(stack.done_actions))
+ action = stack.done_actions[0]
+ self.assertTrue(isinstance(action, ClipPropertyChanged))
+ self.assertEqual(10 * Gst.SECOND, clip1.get_start())
+
+ self.action_log.undo()
+ self.assertEqual(5 * Gst.SECOND, clip1.get_start())
+ self.action_log.redo()
+ self.assertEqual(10 * Gst.SECOND, clip1.get_start())
+
+ clip1.set_priority(10)
+ self.action_log.begin("priority change")
+ clip1.set_priority(20)
+ self.action_log.commit()
+
+ self.assertEqual(20, clip1.get_priority())
+ self.action_log.undo()
+ self.assertEqual(10, clip1.get_priority())
+ self.action_log.redo()
+ self.assertEqual(20, clip1.get_priority())
+
+ def testUngroup(self):
+ uri = common.TestCase.getSampleUri("tears_of_steel.webm")
+ asset = GES.UriClipAsset.request_sync(uri)
+ clip1 = asset.extract()
+ self.layer.add_clip(clip1)
+
+ clip1.set_start(5 * Gst.SECOND)
+ clip1.set_duration(0.5 * Gst.SECOND)
+ timeline_clips = list(self.getTimelineClips())
+ self.assertEqual(1, len(timeline_clips), timeline_clips)
+ self.assertEqual(5 * Gst.SECOND, timeline_clips[0].get_start())
+ self.assertEqual(0.5 * Gst.SECOND, timeline_clips[0].get_duration())
+
+ self.action_log.begin("ungroup")
+ ungrouped = GES.Container.ungroup(clip1, False)
+ self.assertEqual(2, len(ungrouped), ungrouped)
+ self.action_log.commit()
+ timeline_clips = list(self.getTimelineClips())
+ self.assertEqual(2, len(timeline_clips), timeline_clips)
+ self.assertEqual(5 * Gst.SECOND, timeline_clips[0].get_start())
+ self.assertEqual(0.5 * Gst.SECOND, timeline_clips[0].get_duration())
+ self.assertEqual(5 * Gst.SECOND, timeline_clips[1].get_start())
+ self.assertEqual(0.5 * Gst.SECOND, timeline_clips[1].get_duration())
+
+ self.action_log.undo()
+ timeline_clips = list(self.getTimelineClips())
+ self.assertEqual(1, len(timeline_clips))
+ self.assertEqual(5 * Gst.SECOND, timeline_clips[0].get_start())
+ self.assertEqual(0.5 * Gst.SECOND, timeline_clips[0].get_duration())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]