[pitivi] elements: Fix selection of groups



commit 53b1100512bb3d0f2b80f8369f941dba458a4f1c
Author: Thibault Saunier <tsaunier gnome org>
Date:   Wed Jan 6 20:35:33 2016 +0100

    elements: Fix selection of groups
    
    And add a test where we were getting:
    
      AttributeError: 'NoneType' object has no attribute 'get_children'
    
    because of that.
    
    Reviewed-by: Alex Băluț <alexandru balut gmail com>
    Differential Revision: https://phabricator.freedesktop.org/D626

 pitivi/timeline/elements.py     |    7 ++--
 tests/common.py                 |    6 ++--
 tests/test_timeline_timeline.py |   75 +++++++++++++++++++++++++++------------
 3 files changed, 59 insertions(+), 29 deletions(-)
---
diff --git a/pitivi/timeline/elements.py b/pitivi/timeline/elements.py
index ab20bea..d79d77b 100644
--- a/pitivi/timeline/elements.py
+++ b/pitivi/timeline/elements.py
@@ -856,11 +856,12 @@ class Clip(Gtk.EventBox, timelineUtils.Zoomable, Loggable):
         if parent == self.timeline.current_group or parent is None:
             selection = [self.bClip]
         else:
-            while parent:
-                if parent.get_parent() == self.timeline.current_group:
+            while True:
+                grandparent = parent.get_parent()
+                if not grandparent or grandparent == self.timeline.current_group:
                     break
-                parent = parent.get_parent()
 
+                parent = grandparent
             children = parent.get_children(True)
             selection = [elem for elem in children if isinstance(elem, GES.SourceClip) or
                          isinstance(elem, GES.TransitionClip)]
diff --git a/tests/common.py b/tests/common.py
index 5e03ab4..f3ee7fa 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -110,7 +110,7 @@ class TestCase(unittest.TestCase, Loggable):
         self._result = result
         unittest.TestCase.run(self, result)
 
-    def toggleClipSelection(self, bClip):
+    def toggleClipSelection(self, bClip, expect_selected):
         '''
         Toggle selection state of @bClip.
         '''
@@ -123,8 +123,8 @@ class TestCase(unittest.TestCase, Loggable):
             Event(Gdk.EventType.BUTTON_RELEASE, button=1), bClip.ui)
 
         self.assertEqual(bool(bClip.ui.get_state_flags() & Gtk.StateFlags.SELECTED),
-                         not selected)
-        self.assertEqual(bClip.selected.selected, not selected)
+                         expect_selected)
+        self.assertEqual(bClip.selected.selected, expect_selected)
 
 
 def getSampleUri(sample):
diff --git a/tests/test_timeline_timeline.py b/tests/test_timeline_timeline.py
index f1cba54..8d1aebb 100644
--- a/tests/test_timeline_timeline.py
+++ b/tests/test_timeline_timeline.py
@@ -49,8 +49,19 @@ class BaseTestTimeline(common.TestCase):
         timeline = timeline_container.timeline
         timeline.get_parent = mock.MagicMock()
 
+        timeline.app.settings.leftClickAlsoSeeks = False
+
         return timeline
 
+    def addClipsSimple(self, timeline, num_clips):
+        layer = timeline.bTimeline.append_layer()
+
+        asset = GES.UriClipAsset.request_sync(
+            common.getSampleUri("tears_of_steel.webm"))
+
+        return [layer.add_asset(asset, i * 10, 0, 10, GES.TrackType.UNKNOWN)
+                for i in range(num_clips)]
+
 
 class TestLayers(BaseTestTimeline):
     def testDraggingLayer(self):
@@ -144,13 +155,7 @@ class TestGrouping(BaseTestTimeline):
     def groupClips(self, num_clips):
         timeline = self.createTimeline()
         timeline.app.settings.leftClickAlsoSeeks = False
-        layer = timeline.bTimeline.append_layer()
-
-        asset = GES.UriClipAsset.request_sync(
-            common.getSampleUri("tears_of_steel.webm"))
-
-        clips = [layer.add_asset(asset, i * 10, 0, 10, GES.TrackType.UNKNOWN)
-                 for i in range(num_clips)]
+        clips = self.addClipsSimple(timeline, num_clips)
 
         # Press <ctrl> so selecting in ADD mode
         timeline.sendFakeEvent(Event(event_type=Gdk.EventType.KEY_PRESS,
@@ -158,7 +163,7 @@ class TestGrouping(BaseTestTimeline):
 
         # Select the 2 clips
         for clip in clips:
-            self.toggleClipSelection(clip)
+            self.toggleClipSelection(clip, expect_selected=True)
 
         before_grouping_timeline_group = timeline.current_group
 
@@ -197,7 +202,7 @@ class TestGrouping(BaseTestTimeline):
         self.assertEqual(len(clips), num_clips)
 
         # Deselect one grouped clip clips
-        self.toggleClipSelection(clips[0])
+        self.toggleClipSelection(clips[0], expect_selected=False)
 
         # Make sure all the clips have been deselected
         for clip in clips:
@@ -218,18 +223,46 @@ class TestGrouping(BaseTestTimeline):
         for clip in clips:
             self.assertIsNone(clip.get_parent())
 
+    def testGroupSplittedClipAndSelectGroup(self):
+        position = 5
+
+        timeline = self.createTimeline()
+        clips = self.addClipsSimple(timeline, 1)
+        self.toggleClipSelection(clips[0], expect_selected=True)
+
+        timeline.bTimeline.get_asset().pipeline.getPosition = mock.Mock(return_value=position)
+        layer = timeline.bTimeline.get_layers()[0]
+
+        # Split
+        timeline.parent.split_action.emit("activate", None)
+        clips = layer.get_clips()
+        self.assertEqual(len(clips), 2)
+
+        # Only the first clip is selected so select the
+        # second one
+        self.assertTrue(clips[0].selected.selected)
+        self.assertFalse(clips[1].selected.selected)
+
+        timeline.sendFakeEvent(Event(event_type=Gdk.EventType.KEY_PRESS,
+                                     keyval=Gdk.KEY_Control_L))
+        self.toggleClipSelection(clips[1], expect_selected=True)
+        timeline.sendFakeEvent(Event(event_type=Gdk.EventType.KEY_RELEASE,
+                                     keyval=Gdk.KEY_Control_L))
+
+        for clip in clips:
+            self.assertTrue(clip.selected.selected)
+
+        # Group the two parts
+        timeline.parent.group_action.emit("activate", None)
+
+        self.toggleClipSelection(clips[1], expect_selected=True)
+
 
 class TestCopyPaste(BaseTestTimeline):
     def copyClips(self, num_clips):
         timeline = self.createTimeline()
-        timeline.app.settings.leftClickAlsoSeeks = False
-        layer = timeline.bTimeline.append_layer()
-
-        asset = GES.UriClipAsset.request_sync(
-            common.getSampleUri("tears_of_steel.webm"))
 
-        clips = [layer.add_asset(asset, i * 10, 0, 10, GES.TrackType.UNKNOWN)
-                 for i in range(num_clips)]
+        clips = self.addClipsSimple(timeline, num_clips)
 
         # Press <ctrl> so selecting in ADD mode
         timeline.sendFakeEvent(Event(event_type=Gdk.EventType.KEY_PRESS,
@@ -237,7 +270,7 @@ class TestCopyPaste(BaseTestTimeline):
 
         # Select the 2 clips
         for clip in clips:
-            self.toggleClipSelection(clip)
+            self.toggleClipSelection(clip, expect_selected=True)
 
         self.assertTrue(timeline.parent.copy_action.props.enabled)
         self.assertFalse(timeline.parent.paste_action.props.enabled)
@@ -249,16 +282,12 @@ class TestCopyPaste(BaseTestTimeline):
     def testCopyPaste(self):
         position = 20
 
-        def fakeGetPosition():
-            return position
-
         timeline = self.copyClips(2)
 
         layer = timeline.bTimeline.get_layers()[0]
-        project = timeline.bTimeline.get_asset()
-
         # Monkey patching the pipeline.getPosition method
-        project.pipeline.getPosition = fakeGetPosition
+        project = timeline.bTimeline.get_asset()
+        project.pipeline.getPosition = mock.Mock(return_value=position)
 
         clips = layer.get_clips()
         self.assertEqual(len(clips), 2)


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