[pitivi] dogtail: Fix test_timeline.py:TimelineTest.test_split



commit 0abc2864f4a31875224638c66da05e71643aef72
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Wed Mar 26 20:15:06 2014 +0100

    dogtail: Fix test_timeline.py:TimelineTest.test_split

 pitivi/utils/ui.py                        |   23 ++++++-----------------
 tests/dogtail_scripts/helper_functions.py |   23 +++++++++++++++++++++++
 tests/dogtail_scripts/test_timeline.py    |   15 +++++++--------
 3 files changed, 36 insertions(+), 25 deletions(-)
---
diff --git a/pitivi/utils/ui.py b/pitivi/utils/ui.py
index ff69bf6..ae55a4a 100644
--- a/pitivi/utils/ui.py
+++ b/pitivi/utils/ui.py
@@ -22,8 +22,7 @@
 # Boston, MA 02110-1301, USA.
 
 """
-UI utilities. This file contain the UI constants, and various functions and
-classes that help with UI drawing around the application
+UI constants and various functions and classes that help with UI drawing.
 """
 
 
@@ -47,18 +46,11 @@ from gi.repository import Gtk
 from gi.repository.GstPbutils import DiscovererVideoInfo, DiscovererAudioInfo,\
     DiscovererStreamInfo, DiscovererSubtitleInfo, DiscovererInfo
 
-from pitivi.utils.misc import path_from_uri
-
 from pitivi.utils.loggable import doLog, ERROR
+from pitivi.utils.misc import path_from_uri
 
-# ---------------------- Constants -------------------------------------------#
-
-##
-# UI pixels information constants
-##
 
-LAYER_HEIGHT_EXPANDED = 50
-LAYER_HEIGHT_COLLAPSED = 15
+# Dimensions in pixels
 TRACK_SPACING = 8
 EXPANDED_SIZE = 65
 CONTROL_WIDTH = 250
@@ -75,16 +67,14 @@ PLAYHEAD_COLOR = Clutter.Color.new(200, 0, 0, 255)
 # Layer creation blocking time in s
 LAYER_CREATION_BLOCK_TIME = 0.2
 
-##
-#   Drag'n drop constants
-##
+# Drag and drop
 TYPE_TEXT_PLAIN = 24
 TYPE_URI_LIST = 25
 
 # FileSourceFactory (or subclasses)
 TYPE_PITIVI_FILESOURCE = 26
 
-# What objects to these correspond to ???
+# What objects do these correspond to ???
 TYPE_PITIVI_EFFECT = 27
 TYPE_PITIVI_AUDIO_EFFECT = 28
 TYPE_PITIVI_VIDEO_EFFECT = 29
@@ -141,8 +131,7 @@ def pack_color_64(red, green, blue, alpha=0xFFFF):
 def unpack_color(value):
     """Unpacks the specified RGBA value into four 16bit color values.
 
-    Args:
-      value: A 32bit or 64bit RGBA value.
+    @param value: A 32bit or 64bit RGBA value.
     """
     if not (value >> 32):
         return unpack_color_32(value)
diff --git a/tests/dogtail_scripts/helper_functions.py b/tests/dogtail_scripts/helper_functions.py
index a2e763b..8848624 100644
--- a/tests/dogtail_scripts/helper_functions.py
+++ b/tests/dogtail_scripts/helper_functions.py
@@ -11,6 +11,8 @@ from time import sleep
 from pyatspi import Registry as registry
 from pyatspi import KEY_PRESS, KEY_RELEASE
 
+from pitivi.utils import ui
+
 
 class HelpFunc(BaseDogTail):
 
@@ -314,3 +316,24 @@ class HelpFunc(BaseDogTail):
             sleep(2)
             new_timestamp = os.path.getmtime(path)
         return new_timestamp != timestamp
+
+    def getTimelineX(self, percent):
+        assert percent >= 0
+        assert percent <= 1
+        perceived_width = self.timeline.size[0] - ui.CONTROL_WIDTH
+        return self.timeline.position[0] + ui.CONTROL_WIDTH + percent * perceived_width
+
+    def getTimelineY(self, layer, above=False):
+        """
+        Get the absolute y for the middle of the specified layer.
+
+        @param layer: 0-based layer index.
+        @param above: Whether instead middle of the space above.
+        """
+        assert layer >= 0
+        perceived_top = layer * (ui.EXPANDED_SIZE + ui.SPACING)
+        if above:
+            perceived_top += ui.SPACING / 2
+        else:
+            perceived_top += ui.SPACING + ui.EXPANDED_SIZE / 2
+        return self.timeline.position[1] + perceived_top
diff --git a/tests/dogtail_scripts/test_timeline.py b/tests/dogtail_scripts/test_timeline.py
index c070ec9..b122464 100644
--- a/tests/dogtail_scripts/test_timeline.py
+++ b/tests/dogtail_scripts/test_timeline.py
@@ -80,23 +80,22 @@ class TimelineTest(HelpFunc):
         self.insertTwoClipsAndSeekToEnd()
         timecode_widget = self.viewer.child(name="timecode_entry").child(roleName="text")
         self.assertEqual(timecode_widget.text, DURATION_OF_TWO_CLIPS)
-        timeline = self.timeline
-        #Adjust to different screen sizes
-        adj = (float)(timeline.size[0]) / 883
 
-        dogtail.rawinput.click(timeline.position[0] + 500 * adj, timeline.position[1] + 50)
+        dogtail.rawinput.click(self.getTimelineX(0.75), self.getTimelineY(0))
         self.timeline_toolbar.child(name="Split", roleName="push button").click()
-        dogtail.rawinput.click(timeline.position[0] + 450 * adj, timeline.position[1] + 50)
+        # Delete the first half of the split clip.
+        dogtail.rawinput.click(self.getTimelineX(0.75 - 0.125), self.getTimelineY(0))
         self.timeline_toolbar.child(name="Delete", roleName="push button").click()
-
         self.goToEnd_button.click()
         self.assertEqual(timecode_widget.text, DURATION_OF_TWO_CLIPS)
 
-        dogtail.rawinput.click(timeline.position[0] + 550 * adj, timeline.position[1] + 50)
+        # Delete also the second half of the split clip.
+        dogtail.rawinput.click(self.getTimelineX(0.75 + 0.125), self.getTimelineY(0))
         dogtail.rawinput.pressKey("Del")
-        #self.timeline_toolbar.child(name="Delete", roleName="push button").click()
 
         self.goToEnd_button.click()
+        # Allow the UI to update
+        sleep(0.1)
         self.assertEqual(timecode_widget.text, DURATION_OF_ONE_CLIP)
 
     def test_multiple_split(self):


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