[pitivi] ui: Handle no duration in beautify_length
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] ui: Handle no duration in beautify_length
- Date: Thu, 6 Oct 2016 12:25:41 +0000 (UTC)
commit 53ab510d3dc57551f6a53b716bbed7969c42e792
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Wed Oct 5 13:39:57 2016 +0200
ui: Handle no duration in beautify_length
Reviewed-by: Thibault Saunier <tsaunier gnome org>
Differential Revision: https://phabricator.freedesktop.org/D1351
pitivi/medialibrary.py | 5 +----
pitivi/utils/ui.py | 4 ++++
tests/test_utils.py | 18 ++++++++++++------
3 files changed, 17 insertions(+), 10 deletions(-)
---
diff --git a/pitivi/medialibrary.py b/pitivi/medialibrary.py
index 7137d51..b13d4c1 100644
--- a/pitivi/medialibrary.py
+++ b/pitivi/medialibrary.py
@@ -808,10 +808,7 @@ class MediaLibraryWidget(Gtk.Box, Loggable):
thumbs_decorator = ThumbnailsDecorator([thumb_64, thumb_128], asset,
self.app.proxy_manager)
- if info.get_duration() == Gst.CLOCK_TIME_NONE:
- duration = ''
- else:
- duration = beautify_length(info.get_duration())
+ duration = beautify_length(info.get_duration())
name = info_name(asset)
self.pending_rows.append((thumbs_decorator.thumb_64,
thumbs_decorator.thumb_128,
diff --git a/pitivi/utils/ui.py b/pitivi/utils/ui.py
index d2e61e9..84ab335 100644
--- a/pitivi/utils/ui.py
+++ b/pitivi/utils/ui.py
@@ -353,6 +353,7 @@ def time_to_string(value):
"""
if value == Gst.CLOCK_TIME_NONE:
return "--:--:--.---"
+
ms = value / Gst.MSECOND
sec = ms / 1000
ms = ms % 1000
@@ -369,6 +370,9 @@ def beautify_length(length):
Args:
length (int): The duration in nanoseconds.
"""
+ if length == Gst.CLOCK_TIME_NONE:
+ return ""
+
sec = length / Gst.SECOND
mins = int(sec / 60)
sec = int(sec % 60)
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 4e638c7..bf966ab 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -21,7 +21,10 @@ from unittest import TestCase
from gi.repository import Gst
-from pitivi.check import * # noqa
+from pitivi.check import CairoDependency
+from pitivi.check import ClassicDependency
+from pitivi.check import GstDependency
+from pitivi.check import GtkDependency
from pitivi.utils.ui import beautify_length
second = Gst.SECOND
@@ -31,26 +34,29 @@ hour = minute * 60
class TestBeautifyLength(TestCase):
- def testBeautifySeconds(self):
+ def test_beautify_seconds(self):
self.assertEqual(beautify_length(second), "1 second")
self.assertEqual(beautify_length(second * 2), "2 seconds")
- def testBeautifyMinutes(self):
+ def test_beautify_minutes(self):
self.assertEqual(beautify_length(minute), "1 minute")
self.assertEqual(beautify_length(minute * 2), "2 minutes")
- def testBeautifyHours(self):
+ def test_beautify_hours(self):
self.assertEqual(beautify_length(hour), "1 hour")
self.assertEqual(beautify_length(hour * 2), "2 hours")
- def testBeautifyMinutesAndSeconds(self):
+ def test_beautify_minutes_and_seconds(self):
self.assertEqual(beautify_length(minute + second),
"1 minute, 1 second")
- def testBeautifyHoursAndMinutes(self):
+ def test_beautify_hours_and_minutes(self):
self.assertEqual(beautify_length(hour + minute + second),
"1 hour, 1 minute")
+ def test_beautify_nothing(self):
+ self.assertEqual(beautify_length(Gst.CLOCK_TIME_NONE), "")
+
class TestDependencyChecks(TestCase):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]