[pitivi] test_transitions.py: unit test for add/remove transition



commit 1db82ebcde252541173271a9b1ef075715477ece
Author: Brandon Lewis <brandon_lewis alum berkeley edu>
Date:   Thu Mar 4 17:28:51 2010 -0800

    test_transitions.py: unit test for add/remove transition

 tests/test_transitions.py |   96 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 96 insertions(+), 0 deletions(-)
---
diff --git a/tests/test_transitions.py b/tests/test_transitions.py
index 341c1d9..27d6e13 100644
--- a/tests/test_transitions.py
+++ b/tests/test_transitions.py
@@ -19,6 +19,102 @@
 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
+from common import TestCase
+import gst
+
+from pitivi.timeline.track import Track, SourceTrackObject, TrackError
+from pitivi.stream import AudioStream, VideoStream
+from common import SignalMonitor, StubFactory
+from pitivi.factories.test import AudioTestSourceFactory
+from pitivi.timeline.track import Transition, TrackError
+
+class TestTransitions(TestCase):
+    def setUp(self):
+        TestCase.setUp(self)
+        self.factory = StubFactory()
+        self.stream = VideoStream(gst.Caps('video/x-raw-rgb'))
+        self.factory.addOutputStream(self.stream)
+        self.track1 = Track(self.stream)
+
+    def tearDown(self):
+        self.factory = None
+        self.stream = None
+        self.track1 = None
+        TestCase.tearDown(self)
+
+    def testAddRemoveTransitions(self):
+        factory = self.factory
+        track1 = self.track1
+        track1._update_transitions = False
+        stream = self.stream
+
+        test_data = [
+            ("a", 0, 10),
+            ("b", 5, 15),
+            ("c", 15, 20),
+            ("d", 30, 35),
+            ("e", 30, 35),
+        ]
+
+        transitions = [
+            ("a", "b"),
+            ("d", "e"),
+        ]
+
+        objs = {}
+        names = {}
+
+        for name, start, end in test_data:
+            obj = SourceTrackObject(factory, stream)
+            obj.start = start * gst.SECOND
+            obj.in_point = 0
+            obj.duration = end * gst.SECOND - obj.start
+            obj.media_duration = obj.duration
+            track1.addTrackObject(obj)
+            names[obj] = name
+            objs[name] = obj
+
+        result = []
+        transition_objects = {}
+
+        def addTransition(b, c):
+            tr = Transition(objs[b], objs[c])
+            track1.addTransition(tr)
+
+        def transitionAddedCb(track, transition):
+            values =(names[transition.a], names[transition.b])
+            result.append(values)
+            transition_objects[values] = transition
+
+        def transitionRemovedCb(track, transition):
+            values =(names[transition.a], names[transition.b])
+            result.remove(values)
+
+        track1.connect("transition-added", transitionAddedCb)
+        track1.connect("transition-removed", transitionRemovedCb)
+
+        # add transitions and check that initial properties are properly
+        # evaluated
+        for a, b in transitions:
+            addTransition(a, b)
+
+        self.failUnlessEqual(result, transitions)
+
+        # check that adding a transition with a bogus track object raises an
+        # error
+        track1.removeTrackObject(objs["c"])
+        self.failUnlessRaises(TrackError, addTransition, "b", "c")
+
+        # check that adding a transition that already exists raises an error
+        self.failUnlessRaises(TrackError, addTransition, "d", "e")
+
+        # check that removing a transition directly works
+        track1.removeTransition(transition_objects["d", "e"])
+        self.failUnlessEqual(result, [("a", "b")])
+
+        # check tht we can restore a transition after deleting it
+        addTransition("d", "e")
+        self.failUnlessEqual(result, [("a", "b"), ("d", "e")])
 
     def testTransitionProperties(self):
         factory = self.factory



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